code/2apl_platform/examples/explorer and carrier/explorerandcarrier.mas
···11+/*
22+ * This example illustrates the use of modules to implement roles in 2APL.
33+ *
44+ * The aim of this multi-agent system in this example is to collect all bombs in
55+ * the environment and drop them to the the waste bin, which is assumed to be
66+ * at location 0,0.
77+ *
88+ * Multi-agent system consist of one manager and three worker agents. The
99+ * manager agent is authoritatively ordering workers to enact either explorer
1010+ * role or carrier role.
1111+ *
1212+ * The roles of worker agents are implemented as modules and therefore can be
1313+ * instantiated and executed during runtime as illustrated in this example.
1414+ */
1515+1616+m : manager
1717+w : worker 3 @blockworld
1818+1919+
+52
code/2apl_platform/examples/explorer and carrier/manager.2apl
···11+BeliefUpdates:
22+ { true } SetAssigned(POS, A) { assigned(POS, A) }
33+ { true } SetBomb(POS) { bomb(POS) }
44+ { true } RemoveAssigned(POS, A) { not assigned(POS, A) }
55+ { true } RemoveBomb(POS) { not bomb(POS) }
66+77+Beliefs:
88+ worker(w1).
99+ worker(w2).
1010+ worker(w3).
1111+1212+Goals:
1313+ haveBomb
1414+1515+PG-rules:
1616+ haveBomb <- bomb(POS) and not assigned(carrier(POS), _) and worker(W) and not assigned(_, W) |
1717+ {
1818+ send(W, request, play(carrier, POS));
1919+ SetAssigned(carrier(POS), W)
2020+ }
2121+2222+ haveBomb <- not bomb(_) and worker(W) and not assigned( _, W) |
2323+ {
2424+ send(W, request, play(explorer));
2525+ SetAssigned(explorer, W)
2626+ }
2727+2828+PC-rules:
2929+ message(A, inform, _, _, bomb(POS)) <- true |
3030+ {
3131+ [
3232+ SetBomb(POS);
3333+ RemoveAssigned(explorer, A)
3434+ ]
3535+ }
3636+3737+ message(A, inform, _, _, done(POS)) <- true |
3838+ {
3939+ [
4040+ RemoveAssigned(carrier(POS), A);
4141+ RemoveBomb(POS)
4242+ ]
4343+ }
4444+4545+ message(A, inform, _, _, failed(POS)) <- true |
4646+ {
4747+ [
4848+ RemoveAssigned(carrier(POS), A)
4949+ ]
5050+ }
5151+5252+
+47
code/2apl_platform/examples/explorer and carrier/moving.2apl