What you’ll build

The aim is to program an agent able to sense and control the temperature of a room. You will program this agent, situated in a simple environment that it is able to perceive and to act on.

What you’ll need

1. Problem description

The objective of this use case is to control the temperature of a room so that it reaches some desired value.

  • The control and decision-making activities, needed for the system to autonomously achieve its objectives are encapsulated in a room_controller agent. This agent has the initial simple goal of bringing the temperature of the room to some specific value;

  • The tools or resources that are necessary to realise these activities, are modeled and programmed in:

    • an hvac artifact, with the basic actions and observable properties, providing to the agent the means to control the HVAC device, encapsulating and hiding related machinery. The hvac artifact triggers an activity of heating or cooling, that, at some point, will need to be stopped or started;

    • a room workspace, representing the room location where the agent and the artifact are (logically) situated.

This artifact has the following usage interface:

  • startCooling operation to start cooling, that is, switching on the cooling process available in the HVAC device;

  • startHeating operation to start heating;

  • stopAirConditioner operation to stop cooling or heating.

The operations have no parameters.

The usage interface includes also the observable properties that make it possible for the agent to perceive the state of the world (of interest in this example):

  • the temperature observable property, representing the current temperature of the room, which is meant to be measured by a thermometer component of the HVAC device;

  • the state observable property, representing the current state of the HVAC, which could be idle, cooling, or heating.

The artifact includes a GUI that allows the user to dynamically change the temperature by means of a slider component, to simulate a real environment.

2. Simple version of the multi-agent system

Given the set of actions in the usage interface of the hvac artifact, a first simple strategy for the plan to set the temperature at a target value amounts to:

  • Start cooling if the current temperature is higher than the target one,and go on cooling until the target temperature is reached;

  • Analogously, start heating if the current temperature is lower;

  • Stop working when the target temperature is reached.

Create a MAOP program implementing this first application:
  • Implement this strategy in the room_controller agent program

  • Download here the code of the artifact implementing the HVAC and make it available in the env/devices folder:

  • Write the main application file that specifies the initial set of agents and artifacts that must be created, their location in workspaces, and other configuration details, as follows:

mas smart_room {
    agent rc : room_controller.asl {
        goals: temperature(21)
        focus: room.hvac
    }

    workspace room {
        artifact hvac: devices.HVAC(15,20)
    }
}

In this case we have a single room workspace (line 8), hosting an agent called rc of type room_controller (line 5, by focusing on the hvac artifact situated in the room workspace the agent joins this workspace) and an artifact called hvac (line 9), whose structure and behaviour is defined by the Java class whose full name is devices.HVAC — i.e., the class HVAC is stored in a package called devices. The application file allows us to instantiate artifacts by specifying parameters (e.g., 15 and 20 in the example) which are passed to the artifact constructor init.

  • Execute the program

3. Refined version of the multi-agent system

Refine the previous solution by taking into account a threshold to avoid a hysteresis phenomenon.

To that purpose, we add a belief tolerance(Th) to the agent program to keep track of the threshold

Refine the previous MAOP program:
  • Change the room_controller agent program to include this new belief.

  • Change and adapt the set of plans accordingly by using also the prolog-like rules to factorize some part of the code

  • Execute the new program

4. Refactoring the agent to make it reactive

A main feature of agents is the ability to promptly react to events perceived from the environment while also proactively carrying out behaviour to achieve goals by executing appropriate actions.

We extend the capability of the room_controller agent so that not only it is capable of bringing the environment temperature to the specified level, but we also want the agent to maintain the desired temperature.

That is, after a particular temperature is reached, the room temperature might change (by means of the GUI), in which case the agent should react to such environment changes so as to bring back the temperature to the desired level.

To make agent able to react to the evolution of the environment, we exploit a main feature in agent programming which is programming reactive behaviour using the agent plans. These plans are triggered and executed in reaction to changes perceived from the environment, or to be more precise changes in the beliefs about the state of the environment.

Extend the set of plans of the room_controller agent with a plan that might be triggered each time the belief about the current room temperature changes (i.e., +temperature(C )).

In case the new perceived temperature is out of range with respect to some preferred temperature and the agent does not already have an intention about achieving the target temperature (use of the internal operation .desire), a new goal !temperature(T) is created.

To keep track of the preferred desired temperature, you can introduce the new belief preferred_temperature/1 that can be changed (i.e., created beliefs or updated) in plans handling !temperature(T) goals.