What you’ll build

  • The aim is to program an agent able to act in a dynamic environment in accordance with a plan achieving its goal.

  • To program this agent, you will use the Jason Agent Oriented Programming Language, part of the JaCaMo platform. The agent is situated in a simple environment where it can execute some actions. The agent can also perceive some properties of this environment and can interact with other agents.

What you’ll need

Code

Collapsible sections introduced by present details or questions and exercises to realise. Click on the icon to access to the content.

Planning domain and problem

The planning domain that we are considering concerns the (strongly simplified) domain of house building. A set of predicates are used to describe states and goals of this domain. A set of operations that the agent can use are also defined.

Predicates for describing goals and beliefs (click on to access the detail)
  • field_bought/1: the field where the house has to be built has been bought by the owner (1 corresponds to the arity of the predicate, i.e. number of parameters).

  • site_prepared/1: the site where the house has to be build is ready. The building of the house can start.

  • floors_laid/1: the floors of the house have been laid.

  • roofs_built/1: the roofs of the house have been built.

  • walls_built/1: the walls of the house have been built.

  • windows_fitted/1: the windows have been fitted in the walls.

  • doors_fitted/1: the doors have been fitted in the walls.

  • electrical_system_installed/1: the electrical system has been installed.

  • plumbing_installed/1: the plumbing has been done.

  • exterior_painted/1: the painting outside of the house has been done.

  • interior_painted/1: the painting inside the house has been done.

  • house_built/1: the house has been built and is ready to be inhabited.

Operations (click on to access the detail)
  • prepare_site/1 is possible when the field has been bought. It achieves the state site_prepared

  • lay_floors/1 is possible when the site is prepared and achieves floors_laid

  • build_walls/1 is possible when the floors have ben laid and achieves the state walls_built

  • build_roofs/1 is possible when the walls have been built and achieves the state roofs_built

  • fit_windows/1 is possible when the walls have been built and achieves the state windows_fitted

  • fit_doors/1 is possible when the walls have been built and achieves the state doors_fitted

  • install_electrical_system/1 is possible when the roofs have been built, the windows and doors have been fitted. It achieves the state electrical_system_installed

  • install_plumbing/1 is possible when the roofs have been built, the windows and doors have been fitted. It achieves the state plumbing_installed

  • paint_exterior/1 is possible when the roofs have been built, the windows and doors have been fitted. It achieves the state exterior_painted

  • paint_interior/1 is possible when the plumbing has been done, the electrical system has been installed and the exterior has been painted. It achieves the state house_built

QUESTION 1: Modeling the Planning domain and problem (click on to access the detail)

Given the predicates and operations given above, your tasks are:

  • to write the Planning domain representation in pddl in the file house_building_domain.pddl

Note: even if each of the predicate and operation that are considered in the problem don’t need any parameter, we considered that each of them has one to be able to use javagp, program that we will use to compute the plan from this representation.

  • to write the Problem domain representation in pddl in the file pb1.pddl for the following situations:

    • initial state: the field has been bought

    • final state: the house is built

  • You can use the online pddl editor

Document to return

The house_building_domain.pddl and pb1.pddl have to be added to the archive submitted on e-campus by the end of the practical work.

QUESTION 2: Computing the plan (click on to access the detail)

From the modeling done in the previous section, your task is to compute the plan using javagp, implemented version of GraphPlan. It uses different heuristics and you can use it on domains and problems written in PDDL compliant form.

  • Download code for javagp

  • Test and validate your domain and problems representation by launching the javagp graphplan planner on them.

Note: to use JavaGP on a domain and problem written in PDDL Language, execute the following command line in the javagp directory:

java -jar javagp.jar -d house_building_domain.pddl -p pb1.pddl

Document to return

In the accompanying document submitted on e-campus, provide your answer to the following questions:

* computed plan from the javagp call * Why do you have only 6 steps? * What does it mean for your plan?

Programming the agent

Now that we have the plan computed from the initial state, goal and operations, let’s turn to its programming in an agent with the Jason agent programming language. In order to introduce a level of adaptation in the acting part, the operations that are considered in the plan are programmed as Jason subgoals in a Jason Plan. In order to simplify the modeling and the management, we let aside the parameters introduced in the modeling of the operators and predicates in the previous section.

QUESTION 3: Agent definition (click on to access the detail)
  • If not already done, download and extract the following code, open the folder.

  • Open the build_house.jcm

mas build_house {


  agent wood_concrete_seller
  agent company : companyv1.asl  {
        focus: building_area.houseA
  }

   workspace building_area {
        artifact houseA: simulator.House
   }
}
  • In the code of the agent, look at the plan corresponding to the one you computed (what are the triggering event, the context, the body of this jason plan?).

  • For each of the subgoals created in the body of this plan, there is a jason plan for achieving each of them. Achieving each of these subgoals in our case corresponds to execute the following external actions (each of this external action corresponds to the call of an operation executed on the artifact of type House created in the environment. House is an /artifact/, java class defined in the src/env folder):

    • prepareSite

    • layFloors

    • buildWalls

    • buildRoof

    • fitWindows

    • fitDoors

    • installElectricalSystem

    • installPlumbing

    • paintExterior

    • paintInterior

  • Execute and test your agent. You should see the house built on the GUI.

Document to return

The companyv1.asl has to be added to the archive submitted by the end of the practical work.

QUESTION 4: Living in the best of the possible worlds (click on to access the detail)
  • Make a new version of companyv1.asl to companyv2.asl.

  • Adapt the build_house.jcm file so that you can execute this new version of the agent, as follows:

mas build_house {


  agent wood_concrete_seller
  agent company : companyv2.asl  {
        focus: building_area.houseA
  }

   workspace building_area {
        artifact houseA: simulator.House
   }
}
  • Execute some of the goals in parallel as the modeling of the operations permits it.

  • Add some comments in the code to explain and justify your choices

  • Execute the agent in the environment

Document to return

The companyv2.asl has to be added to the archive submitted by the end of the practical work.

QUESTION 5: Living in a more realistic worlds (click on to access the detail)

In the previous execution of the agent, every operation executed as if it was in an "ideal world" where all the resources are available and all the actions can execute. However this is not exactly the case in real world situations.

For instance, let’s consider that the site cannot be prepared if the weather is not fine (belief weather(fine)). How could we change the definition of the plan aiming at realizing the operation prepare_site.

Using the definition of contingency plans, add plans to handle such a situation by blocking the execution of the plan till the belief weather(fine) becomes true (to that aim, you can use the Jason internal action .wait(aPredicate)).

  • Make a new version of companyv2.asl to companyv3.asl.

  • Adapt the build_house.jcm file so that you can execute this new version of the agent as follows:

mas build_house {


  agent wood_concrete_seller
  agent company : companyv3.asl  {
        focus: building_area.houseA
  }

   workspace building_area {
        artifact houseA: simulator.House
   }
}
  • Modify the agent code to handle the weather not fine for site preparation

  • Test this new version of the agent

  • Note: In order to make the agent believe that the weather is fine, you can create an agent alice sending it a message telling it that the weather is fine. You can dynamically create this new agent by using the kbd:[New REPL agent] in the console (e.g. agent alice) that sends the following message to company agent:

.send(company, tell, weather(fine)).

With this example, we clearly see how the agent executing a predefined plan is able to adapt its execution according to the current context of execution.

Document to return

The companyv3.asl has to be added to the archive submitted by the end of the practical work.

QUESTION 6: Living in a world where resources are distributed (click on to access the detail)

Using the same method, modify and adapt the corresponding plans conditioning the achievement of build_roofs and build_walls to the availability of woods and concrete in the stock (beliefs stock(wood), stock(concrete)).

Checking of availability of woods or concrete in your company may be done using a question goal (i.e. goals introduced by ?).

In order to renew its stock the agent will send a message to the agent wood_concrete_seller. To make it simple (you can make it more complex if you wish so), the wood_concrete_seller agent just sends a message telling that stock(concrete) and stock(woods) have been renewed, and this each time an agent requests for it.

Let’s remind that sending a message can be realized with the Jason internal action .send (see the slides for the different types of messages that can be sent). Use the verbs corresponding to the type of behaviour that the wood_concrete_seller executes when receiving the message.

  • Make a new version of companyv3.asl to companyv4.asl.

  • Adapt the build_house.jcm file so that you can execute this new version of the agent as follows:

mas build_house {


  agent wood_concrete_seller
  agent company : companyv4.asl  {
        focus: building_area.houseA
  }

   workspace building_area {
        artifact houseA: simulator.House
   }
}
  • Make a generic behaviour (Jason plan) so that when the company receives a message from the seller, it updates the stock with the corresponding product.

  • Test and execute it.

Document to return

The companyv4.asl has to be added to the archive submitted by the end of the practical work.