This repository contains a partial implementation of a JaCaMo application where a reinforcement learning agent operates in an unknown environment.
- Project structure
- How to set up the simulated environment
- Task 2
- How to run the project
- Bonus: Learning and acting on the real environment
├── simulator
│ └── simulator_flow.json # a simulator for the lab (smart factory) environment
├── src
│ ├── agt
│ │ └── illuminance_controller_agent.asl # agent program of the illuminance controller agent that is responsible for managing the indoor illuminance level based on task requirements
│ └── env
│ ├── tools
│ │ ├── Action.java
│ │ ├── Lab.java # Lab instances manage the state space and action space of a lab environment (simulated or real) - extends LearningEnvironment
│ │ ├── LearningEnvironment.java # an abstract class whose concrete classes help in learning environments
│ │ └── QLearner.java # artifact that can be used for performing Q learning in lab environments
│ └── wot
│ └── ThingArtifact.java # artifact that can be used for interacting with W3C Web of Things (WoT) Things
└── task.jcm # the configuration file of the JaCaMo application
See instructions in /simulator.
Extend the operation calculateQ
in QLearner.java
that calculates a Q matrix against a goal description.
- HINTS:
- The method
initializeQTable
of the classQLearner
can be used to initialize a Q-Table with Q values of 0.0. - A
QLearner
artifact is always initialized against an instance of the classLab
. The classLab
(and its superclassLearningEnvironment
) offers methods that may be useful to you (you can also ignore or modify the methods). For example:- the method
readCurrentState
can be used to read the current state of the environment during training; - the method
performAction
can be used to perform an action on the environment during training; - the method
getApplicableActions
can be used to retrieve a list of actions that are applicable on a state of the environment; - the method
getCompatibleStates
can be used to retrieve a list of states that are compatible with a given substate.
- the method
- It is advised that, in the beginning of each episode, the
QLearner
randomizes the state of the environment (e.g. using the methodperformAction
of the classLab
), so that training is performed against different initial states.
- The method
Modify the implementation in illuminance_controller_agent.asl
so that the agent calculates Q tables for its desired environment states.
- HINTS:
- Enable the agent to use the operation
calculateQ
that you implemented inQLearner.java
for Task 2.1. - The agent holds an initial belief of the form
task_requirements([Z1Level, Z2Level])
(e.g.task_requirements([3,3]
) that represents the required illuminance conditions for the tasks that take place in the environment. You can pass the list[Z1Level, Z2Level]
as a parameter to the operationcalculateQ
. You can modify the values stored in the initial belief to train for different goal descriptions.
- Enable the agent to use the operation
- Modify the operation
getActionFromState
inQLearner.java
that returns information about the next best action based on a given current state, and a given desired state. Use the QTable that has been computed for the given desired state to extract the next best action from the current state. - Modify the implementation in
illuminance_controller_agent.asl
so that the agent uses aThingArtifact
and aQLearner
artifact to take actions towards its goal.- HINTS:
- For example, the agent could:
- Perceive the state of the environment using a
ThingArtifact
. - If the perceived state does not match the desired state of the agent, the agent should get the next best action for its goal and perceived state using a
QLearner
artifact. - Act by using the information about the next best action, and using a
ThingArtifact
. - Repeat until the perceived state matches the desired state of the agent.
- Perceive the state of the environment using a
- For example, the agent could:
- HINTS:
You can run the project directly in Visual Studio Code or from the command line with Gradle 7.4.
- In VSCode: Click on the Gradle Side Bar elephant icon, and navigate through
GRADLE PROJECTS
>exercise-11
>Tasks
>jacamo
>task
. - On MacOS and Linux run the following command:
./gradlew task
- On Windows run the following command:
gradle.bat task
Simply update the implementation in illuminance_controller_agent.asl
so that the agent uses the W3C Web of Things Thing Description (WoT TD) of the real lab environment.