2-APL UPC project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added more 2apl examples

fdesan dc4cede3 6428efbe

+299
+27
code/2apl_platform/examples/carriage/agent.2apl
··· 1 + 2 + Plans: 3 + { 4 + @carriageexample( getAllEntities(), AE ); 5 + print(allEntities(AE)); 6 + @carriageexample( associateWith(robot1), AW ); 7 + print(associationResult(AW)); 8 + @carriageexample( getFreeEntities(), FE ); 9 + print(freeEntities(FE)); 10 + @carriageexample( getAllPercepts(), AP ); 11 + print(allPercepts(AP)); 12 + 13 + 14 + while B( false ) do { 15 + 16 + @carriageexample( wait(), _ ) 17 + 18 + }; 19 + 20 + @carriageexample( push(), X ); 21 + @carriageexample( push(), X ); 22 + @carriageexample( push(), X ); 23 + @carriageexample( push(), X ); 24 + @carriageexample( push(), X ); 25 + 26 + print("ALARM") 27 + }
+1
code/2apl_platform/examples/carriage/carriage.mas
··· 1 + agent : agent.2apl @carriageexample
code/2apl_platform/examples/carriage/carriageexample.jar

This is a binary file and will not be displayed.

code/2apl_platform/examples/elevator/ElevatorEnvironment.pdf

This is a binary file and will not be displayed.

+12
code/2apl_platform/examples/elevator/agent.2apl
··· 1 + Plans: 2 + { 3 + @elevatorenv( getAllEntities(), AE ); 4 + print(allEntities(AE)); 5 + @elevatorenv( getFreeEntities(), AE ); 6 + print(freeEntities(AE)); 7 + @elevatorenv( associateWith(car1), AW ); 8 + print(associationResult(AW)); 9 + @elevatorenv( goto(3,up) , GR); 10 + print(gotoResult(GR)); 11 + skip 12 + }
+1
code/2apl_platform/examples/elevator/elevator.mas
··· 1 + agent : agent.2apl @elevatorenv
code/2apl_platform/examples/elevator/elevatorenv.jar

This is a binary file and will not be displayed.

+61
code/2apl_platform/examples/explorer and carrier/carrier.2apl
··· 1 + Include: 2 + moving.2apl 3 + 4 + BeliefUpdates: 5 + { true } RemoveBomb(POS) { not bomb(POS) } 6 + { not carrying_bomb } SetCarryingBomb() { carrying_bomb } 7 + { carrying_bomb } SetNotCarryingBomb() { not carrying_bomb } 8 + { } SetError() { error } 9 + 10 + Beliefs: 11 + trap([0,0]). 12 + bombStored :- not bomb(_), not carrying_bomb. 13 + done :- bombStored. 14 + 15 + Goals: 16 + bombStored 17 + 18 + PG-rules: 19 + bombStored <- bomb(POS) and not carrying_bomb and not at(POS)| 20 + { 21 + [ 22 + updatePosition(); 23 + if B(bomb(POS) and not at(POS)) then adopta(at(POS)) 24 + ] 25 + } 26 + 27 + bombStored <- bomb(POS) and not carrying_bomb and at(POS)| 28 + { 29 + [ 30 + updatePosition(); 31 + if B(at(POS)) then 32 + { 33 + @blockworld( pickup(), _ ); 34 + SetCarryingBomb(); 35 + RemoveBomb(POS) 36 + } 37 + ] 38 + } 39 + 40 + bombStored <- carrying_bomb and trap(TRAPPOS) and not at(TRAPPOS) | 41 + { 42 + adopta(at(TRAPPOS)) 43 + } 44 + 45 + bombStored <- carrying_bomb and trap(TRAPPOS) and at(TRAPPOS) | 46 + { 47 + @blockworld( drop(), _ ); 48 + SetNotCarryingBomb() 49 + } 50 + 51 + PR-rules: 52 + @blockworld(pickup(), _); REST <- true | 53 + { 54 + SetError() 55 + } 56 + 57 + @blockworld(drop(), _); REST <- true | 58 + { 59 + SetError() 60 + } 61 +
+33
code/2apl_platform/examples/explorer and carrier/explorer.2apl
··· 1 + Include: 2 + moving.2apl 3 + 4 + BeliefUpdates: 5 + { true } RememberBomb(POS) { bomb(POS) } 6 + { at(OLDPOS) } UpdatePosition(POS) { not at(OLDPOS), at(POS) } 7 + { true } UpdatePosition(POS) { at(POS) } 8 + 9 + Beliefs: 10 + foundBomb :- bomb(_). 11 + 12 + /* Succeeds with probability P */ 13 + prob(P) :- is(X, rand), X < P. 14 + 15 + Goals: 16 + foundBomb 17 + 18 + PG-rules: 19 + /* Wander around */ 20 + foundBomb <- prob(0.05) | 21 + { 22 + gotoRandomPos(15,15) 23 + } 24 + 25 + foundBomb <- true | 26 + { 27 + @blockworld( senseBombs(), BOMBS ); 28 + if B( BOMBS = [actionresult([ [default,X1,Y1] | REST ])]) then 29 + { 30 + RememberBomb([X1,Y1]) 31 + } 32 + } 33 +
+19
code/2apl_platform/examples/explorer and carrier/explorerandcarrier.mas
··· 1 + /* 2 + * This example illustrates the use of modules to implement roles in 2APL. 3 + * 4 + * The aim of this multi-agent system in this example is to collect all bombs in 5 + * the environment and drop them to the the waste bin, which is assumed to be 6 + * at location 0,0. 7 + * 8 + * Multi-agent system consist of one manager and three worker agents. The 9 + * manager agent is authoritatively ordering workers to enact either explorer 10 + * role or carrier role. 11 + * 12 + * The roles of worker agents are implemented as modules and therefore can be 13 + * instantiated and executed during runtime as illustrated in this example. 14 + */ 15 + 16 + m : manager 17 + w : worker 3 @blockworld 18 + 19 +
+52
code/2apl_platform/examples/explorer and carrier/manager.2apl
··· 1 + BeliefUpdates: 2 + { true } SetAssigned(POS, A) { assigned(POS, A) } 3 + { true } SetBomb(POS) { bomb(POS) } 4 + { true } RemoveAssigned(POS, A) { not assigned(POS, A) } 5 + { true } RemoveBomb(POS) { not bomb(POS) } 6 + 7 + Beliefs: 8 + worker(w1). 9 + worker(w2). 10 + worker(w3). 11 + 12 + Goals: 13 + haveBomb 14 + 15 + PG-rules: 16 + haveBomb <- bomb(POS) and not assigned(carrier(POS), _) and worker(W) and not assigned(_, W) | 17 + { 18 + send(W, request, play(carrier, POS)); 19 + SetAssigned(carrier(POS), W) 20 + } 21 + 22 + haveBomb <- not bomb(_) and worker(W) and not assigned( _, W) | 23 + { 24 + send(W, request, play(explorer)); 25 + SetAssigned(explorer, W) 26 + } 27 + 28 + PC-rules: 29 + message(A, inform, _, _, bomb(POS)) <- true | 30 + { 31 + [ 32 + SetBomb(POS); 33 + RemoveAssigned(explorer, A) 34 + ] 35 + } 36 + 37 + message(A, inform, _, _, done(POS)) <- true | 38 + { 39 + [ 40 + RemoveAssigned(carrier(POS), A); 41 + RemoveBomb(POS) 42 + ] 43 + } 44 + 45 + message(A, inform, _, _, failed(POS)) <- true | 46 + { 47 + [ 48 + RemoveAssigned(carrier(POS), A) 49 + ] 50 + } 51 + 52 +
+47
code/2apl_platform/examples/explorer and carrier/moving.2apl
··· 1 + BeliefUpdates: 2 + { at(OLDPOS) } UpdatePosition(POS) { not at(OLDPOS), at(POS) } 3 + { true } UpdatePosition(POS) { at(POS) } 4 + 5 + Beliefs: 6 + prob(P) :- is(X, rand), X < P. 7 + 8 + PG-rules: 9 + at( [X, Y] ) <- true | 10 + { 11 + updatePosition(); 12 + B(at(POS) and POS = [A,B]); 13 + if B(A > X) then { @blockworld( west(), _ ) } 14 + else if B(A < X) then { @blockworld( east(), _ ) } 15 + else if B(B > Y) then { @blockworld( north(), _ )} 16 + else if B(B < Y) then { @blockworld( south(), _ )}; 17 + updatePosition() 18 + } 19 + 20 + PC-rules: 21 + 22 + gotoRandomPos(MaxX, MaxY) <- true | 23 + { 24 + B(is( X, int( random( MaxX ) ) )); 25 + B(is( Y, int( random( MaxY ) ) )); 26 + if G(at(OLDPOS)) then { dropgoal(at(OLDPOS))}; 27 + [ if B(not at([X, Y])) then adopta(at([X, Y])) ] 28 + } 29 + 30 + updatePosition() <- true | 31 + { 32 + @blockworld( sensePosition(), RES ); 33 + if B(RES = [actionresult(POS)]) then UpdatePosition(POS) 34 + } 35 + 36 + randomMove() <- prob(0.25) | { @blockworld( south(), _) } 37 + randomMove() <- prob(0.5) | { @blockworld( north(), _) } 38 + randomMove() <- prob(0.75) | { @blockworld( west(), _) } 39 + randomMove() <- true | { @blockworld( east(), _) } 40 + 41 + PR-rules: 42 + @blockworld( south(), _); REST <- true | { randomMove(); REST } 43 + @blockworld( north(), _); REST <- true | { randomMove(); REST } 44 + @blockworld( west(), _); REST <- true | { randomMove(); REST } 45 + @blockworld( east(), _); REST <- true | { randomMove(); REST } 46 + 47 +
+46
code/2apl_platform/examples/explorer and carrier/worker.2apl
··· 1 + Include: 2 + moving.2apl 3 + 4 + Beliefs: 5 + manager(m). 6 + 7 + Plans: 8 + B(is( X, int( random( 15 ) ) )); 9 + B(is( Y, int( random( 15 ) ) )); 10 + @blockworld( enter( X, Y, blue ), _ ) 11 + 12 + PG-rules: 13 + 14 + /* Wander around */ 15 + <- true | 16 + { 17 + if B(prob(0.05)) then 18 + gotoRandomPos(15,15) 19 + } 20 + 21 + PC-rules: 22 + message(A, request, _, _, play(explorer)) <- manager(A) | 23 + { 24 + create(explorer, myexp); 25 + myexp.execute(B(bomb(POS))); 26 + send(A, inform, bomb(POS)); 27 + release(myexp) 28 + } 29 + 30 + message(A, request, _, _, play(carrier, POS)) <- manager(A) | 31 + { 32 + create(carrier, mycar); 33 + mycar.updateBB(bomb(POS)); 34 + mycar.execute(B(done or error)); 35 + if mycar.B( done ) then 36 + { 37 + send(A, inform, done(POS)) 38 + } 39 + else 40 + { 41 + send(A, inform, failed(POS)) 42 + }; 43 + release(mycar) 44 + } 45 + 46 +