jacamo-lang / mapc2020

Team for MAPC 2020
GNU General Public License v3.0
3 stars 1 forks source link

JaCaMo team for MAPC 2020

Running a team

Requirements:

Running local server and client together

  1. Edit the script /clientconf/createFile.sh, setting on both teams the host parameter to localhost, password to 1, and set the parameter username to agentA%d and agentB%d on team A and B respectivelly.
  2. Execute the script to create the client configuration files.
  3. Make sure the server is being launched by setting the instruction Server.main(...) at the file src/java/runMAPC2020/Control.java.
  4. Execute the default strategy running ./gradlew run, press enter to start the simulation, and see the execution on a browser. You can set another strategy giving arguments, for instance: ./gradlew run --args="src/jcm/individualist.jcm

Running for the competition (just client side)

  1. Edit the script /clientconf/createFile.sh, setting on both teams configuration the host, password, and username that will be used for the competition (e.g.: agentcontest1.in.tu-clausthal.de, some-password, agentJaCaMo_Builders%d). In this case, you can set teamA to play on a server (e.g. agentcontest1.in.tu-clausthal.de) and team B to play on a second server (e.g. agentcontest2.in.tu-clausthal.de).
  2. Execute the script to create the client configuration files.
  3. Make sure the server is NOT being launched removing/commenting the instruction Server.main(...) at the file src/java/runMAPC2020/Control.java.
  4. Execute ./gradlew run --args="src/jcm/teamA.jcm or ./gradlew run --args="src/jcm/teamB.jcm according to the server.

Configuring an Eclipse Project

Requirements:

To add the project in your workspace, use the Eclipse menu File|Import|Existing Gradle Project and select the project directory.

Then

  1. use gradle tasks to run the team, or
  2. select and run class runMAPC2020.Run

Running a team using Docker

Requirements:

Run once (sudo - root privileges can be necessary):

docker volume create --name gradle-cache

Run the team (sudo - root privileges can be necessary):

docker run -ti --rm -u gradle -v gradle-cache:/home/gradle/.gradle -v "$PWD":/home/gradle/project -w /home/gradle/project -p 8000:8000 gradle:6.3.0-jdk13 ./gradlew run

Additional running configurations

Troubleshoot when using docker

Project structure

mapc2020/
        src/
            agt/ -- Jason Agents
                buildblock/ -- mid-level plans for assembling complex structures
                environment/ -- low-level bridges to artifacts
                exploration/ -- low-level helpers for gps facilities
                simulation/ -- low-level bridges for interacting with massim
                strategies/ -- top-level strategies
                tasks/ -- mid-level helpers for task accomplishment
                walking/ -- low-level helpers for walking
                agentBase.asl -- the base for top-level strategies
            env/ -- CArtAgO Artifacts
                connection/ -- artifacts to connect agents and the simulator
                coordination/ -- artifacts to coordinate agents
                localPositionSystem/ -- artifacts to provide gps facilities
            java/ -- Java supportive classes
                bb/ -- can be used to store beliefs of agents for tests
                jason/stdlib/ -- internal actions for mapc
                mabOptimizer/ -- libs for Multi Armed Bandit stochastic algorithm
                runMAPPC2020/ -- classes for launching the simulator and JaCaMo
                scenario/ -- classes for scenario interpretations
            jcm/ -- initialization scripts
            test/
                jacamo/ -- tests for jacamo systems
                    agt/ -- mapc tester agents folder
                    inc/ -- test helpers for mapc tester agents

Understanding the dynamics behind this project

Developing new strategies

Using artifacts

Server and clients setup

Using jason unit tests

  1. Create an agent for testing your agent(s). You can use the default src/test/jason/asl folder (all agents in this folder are automatically launched in the test task).
  2. Provide to your tester agent the testing facilities
    { include("$jasonJar/test/jason/inc/tester_agent.asl") }
  3. Add to your test agent (eg.: src/test/jason/asl/test_meeting.asl) support to the agent it is going to test:
    { include("exploration/meeting.asl") }
  4. The plans in which the label has the annotation [test] are automatically launched (e.g.: @test_coord_same_position[test])
  5. Run ./gradlew test to check results. You can run ./gradlew test -i to see more detailed messages or event ./gradlew test --debug for a full debug

For instance, let us say tat @test_coord_same_position is as below:

@test_coord_same_position[test]
+!test_coord_same_position
    <-
    ?coord(0,0,0,0,[],L1);

    !assert_equals(61,.length(L1));

    .findall(p(X,Y),proof(X,Y),L0);

    .difference(L0,L1,DIFF);
    !assert_equals([],DIFF);
.

In the file src/test/jason/asl/test_meeting.asl we add some known facts. When running ./gradlew test, it will launch this [test] plan and get from a rule coord/6 which is provided by exploration/meeting.asl a list L1. From the known facts, we know that two perspectives from the same origin (0,0) have same view, so, they are sharing 61 elements, so we can assert it as done in !assert_equals(61,.length(L1));. Then since we previously know each coordinate they are sharing (which regards to vision(5), i.e., 5 squares in radius) we have also created proof facts that are being confronted with the result provided by coord/6. The difference from the proof and the result from coord/6 must be an empty set! In this sense, we are testing in this plan the rule coord/6 in the hypothetical case of two agents sharing the same position (0,0).

Why it is important to create unit tests?

Tests are run every git push and can also be performed locally using ./gradlew test or gradle test.

Using a jacamo-web playgroung

We have a JCM using jacamo-web which may be helpful for faster the development of new features and tests. Actually, since MAPC uses a simulator which can produce changes very fast, jacamo-web is not being shown a good development environment. For this reason, the playground proposes the use jacamo-web out of the simulation. It is useful since it allows to quickly make changes (even while running) and after it has some maturity we can move from player's code to a final agent code or a tester agent. The script src/jcm/playground.jcm just launches a jacamo-web environment with the agent src/agt/player.asl. For instance, if we want to test the rule get_rotation provided by walking/rotate_jA_star.asl.

{ include("test_walking_helpers.asl") }
{ include("walking/rotate_jA_star.asl") }

+!start
    <-
    -+myposition(0,0);
    -+origin(mymap);

    ?get_rotation(b(1,0,b0),b(0,1,b0),D0);
    .log(warning,"Rotate a block from 3 o'clock to 6 o'clock got ",D0);
.

WARNING: