In previous lessons the rules where light weight regarding the coordination.

Indeed, if you carefully look at these scripts you will notice that only the first token returns several resources. The other tokens only return a single resource. This is exemplified in the following sample of the previous script :

 {*,!}["People","Customer"].rd(name,departure) &
 {*,!}["People","Destination"].rd(name,arrival) &

This sample can be read as :

  • The first token reads all the values of the name field of the Customer bag of the People object, associated with the departure field value of the returned resource.
  • The for each name value, we read the corresponding arrival field value (only 1 value, as specified in the {1,!} expression) of the Destination bag of the People object.
  • Finally, for each obtained couple of departure and arrival, we read the line value (only 1 value, as specified in the {1,!} expression) of the Connection bag of the Metro object.

However, sometimes, we have to deal with wider combinatorial expansion in order to solve less straight-forward problems and let the system finding the best combination (the "best" notion being expressed within the rules). Here, we implement a "combinatorial scenario" by evaluating direct, 2-hop, 3-hop and 4-hop journeys.

LINC objects may execute rules involving any bags. For performance or redundancy reasons, you can a dedicated object that only execute rules.

Like any other object of the application (Metro,People, Supervision), the Coordinator object is defined within the file :

 # Coordinator
 CoordinatorObject = data.ObjectDescription() = "Coordinator"
 CoordinatorObject.type = "Coordinator" = H1
 CoordinatorObject.application = A1
 CoordinatorObject.nameserver = NameServer
 CoordinatorObject.params = {param.OBJECT_TRACE_LEVEL : TRACE_LEVEL}

There is no difference in the script definition. We simply change the list_of_objects executing the script to CoordinatorObject.

 script2 = data.ScriptDescription()       <--- script definition
 script2.application = A1 = "trom"
 script2.list_of_objects = [CoordinatorObject]
 script2.policy = "Manual"

The trom.rules file contains 4 rules: one for direct journeys, one for the 2-hop journeys, one for 3-hop journeys and one for 4-hop journeys. The last two are built following the same principles as the ones used previously to manage 2-hop travel (see source files).

The initialization file ( remains the same, as well as its definition within the file.

Launch the application with the same magic command :

python --go

If you use the monitor to inspect the content of the Travel bag of the Supervision object, you may get something like this:

As the rules do not express any priority or constraints on the rules contained within the trom.rules file, the coordinator selected here a 2-hop journey for bob, a 3-hop journey for alice, and 2 direct journeys for the other two. As this is only one combination over several others, you may not get the same results by yourself, and you may not get the same result if you launch your application again.