Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
Communication radius as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueDi committed Dec 15, 2017
1 parent 508b309 commit 0ee4328
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
15 changes: 10 additions & 5 deletions src/unknownexplorer/Captain.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ public void setOtherCaptains(List<AID> otherCaptains) {
* @param grid
* @param BOARD_DIM
*/
public Captain(ContinuousSpace<Object> space, Grid<Object> grid, int BOARD_DIM) {
public Captain(ContinuousSpace<Object> space, Grid<Object> grid, int BOARD_DIM, int COMMUNICATION_RADIUS) {
this.space = space;
this.grid = grid;
this.ready = false;
searchMatrix = new int[BOARD_DIM][BOARD_DIM];
this.communicationRadius = COMMUNICATION_RADIUS;
whoNeedHelp = new ArrayList<AID>();
pointsThatNeedHelp = new ArrayList<GridPoint>();
}
Expand All @@ -85,8 +86,6 @@ public Captain(ContinuousSpace<Object> space, Grid<Object> grid, int BOARD_DIM)
* Initialize the Captain.
*/
protected void setup() {
communicationRadius = 5;

DFAgentDescription dfd = new DFAgentDescription();
dfd.setName(getAID());
ServiceDescription sd = new ServiceDescription();
Expand Down Expand Up @@ -137,7 +136,8 @@ public void action() {
if (foundGoal) {
reply.setPerformative(ACLMessage.PROPAGATE);
reply.setContent(goal.getX() + "_" + goal.getY());
} else if (ready && !whoNeedHelp.isEmpty() && !pointsThatNeedHelp.isEmpty() && whoNeedHelp.get(0) != message.getSender()) {
} else if (ready && !whoNeedHelp.isEmpty() && !pointsThatNeedHelp.isEmpty()
&& whoNeedHelp.get(0) != message.getSender()) {
reply.setPerformative(ACLMessage.PROXY);
GridPoint gp = pointsThatNeedHelp.remove(0);
reply.setContent(gp.getX() + "_" + gp.getY());
Expand Down Expand Up @@ -172,7 +172,9 @@ public void action() {
point[0] = Integer.parseInt(parts[0]);
point[1] = Integer.parseInt(parts[1]);
point[2] = Integer.parseInt(parts[2]);
if (searchMatrix[point[1]][point[0]] == 0) {
if (point[0] >= searchMatrix.length || point[1] >= searchMatrix.length) {
reply.setPerformative(ACLMessage.CANCEL);
} else if (searchMatrix[point[1]][point[0]] == 0) {
reply.setPerformative(ACLMessage.CONFIRM);
updateSearchMatrixCaptain(point[0], point[1], point[2]);
} else {
Expand Down Expand Up @@ -265,6 +267,9 @@ public void action() {
}

nPositions = (xCounter >= yCounter) ? yCounter : xCounter;
if (nPositions == 1) {
nPositions = 2;
}
newZoneMessage
.setContent((xFirst0 + nPositions / 2) + "_" + (yFirst0 + nPositions / 2) + "_" + (nPositions / 2));

Expand Down
1 change: 1 addition & 0 deletions src/unknownexplorer/Soldier.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public boolean done() {
message.setConversationId("solved");
message.addReceiver(whoAskedForHelp);
myAgent.send(message);
myInfo = null;
addBehaviour(new SoldierBehaviour());
return true;
}
Expand Down
12 changes: 10 additions & 2 deletions src/unknownexplorer/UnknownExplorerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class UnknownExplorerLauncher extends RepastSLauncher {
private static int BOARD_DIM;
private static int N_SOLDIERS;
private static int N_CAPTAINS;
private static int COMMUNICATION_RADIUS;
private static double VISION_RADIUS = 0.1 * BOARD_DIM;

private ContinuousSpace<Object> space;
Expand Down Expand Up @@ -82,13 +83,14 @@ private void launchAgents() {
N_CAPTAINS = params.getInteger("N_CAPTAINS") + 1;
BOARD_DIM = params.getInteger("BOARD_DIM");
N_SOLDIERS = params.getInteger("N_SOLDIERS");
COMMUNICATION_RADIUS = params.getInteger("COMMUNICATION_RADIUS");
VISION_RADIUS = params.getDouble("VISION_RADIUS");

List<jade.core.AID> allCaptains = new ArrayList<jade.core.AID>();
try {
Captain[] caps = new Captain[N_CAPTAINS];
for (int i = 0; i < N_CAPTAINS; i++) {
Captain c = new Captain(space, grid, BOARD_DIM);
Captain c = new Captain(space, grid, BOARD_DIM, COMMUNICATION_RADIUS);
mainContainer.acceptNewAgent("Captain" + i, c).start();
caps[i] = c;
if (i != 0)
Expand Down Expand Up @@ -154,12 +156,18 @@ private void launchEnvironment(Context<Object> context) {
grid.moveTo(w, 9, i);
space.moveTo(w, 9, i);
}
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 6; i++) {
Wall w = new Wall(39, i);
context.add(w);
grid.moveTo(w, 39, i);
space.moveTo(w, 39, i);
}
for (int i = 0; i < 6; i++) {
Wall w = new Wall(38, i);
context.add(w);
grid.moveTo(w, 38, i);
space.moveTo(w, 38, i);
}

// OBJ POINT
Objective o = new Objective();
Expand Down
13 changes: 8 additions & 5 deletions unknownexplorer.rs/parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<parameter name="randomSeed" displayName="Default Random Seed"
type="int" defaultValue="__NULL__" />

<parameter name="BOARD_DIM" displayName="BOARD_DIM" type="int"
defaultValue="50" isReadOnly="false"
converter="repast.simphony.parameter.StringConverterFactory$IntConverter" />
Expand All @@ -15,10 +15,13 @@
<parameter name="N_SOLDIERS" displayName="N_SOLDIERS" type="int"
defaultValue="10" isReadOnly="false"
converter="repast.simphony.parameter.StringConverterFactory$IntConverter" />


<parameter name="VISION_RADIUS" displayName="VISION_RADIUS" type="double"
defaultValue="5" isReadOnly="false"

<parameter name="COMMUNICATION_RADIUS" displayName="COMMUNICATION_RADIUS" type="int"
defaultValue="6" isReadOnly="false"
converter="repast.simphony.parameter.StringConverterFactory$IntConverter" />

<parameter name="VISION_RADIUS" displayName="VISION_RADIUS"
type="double" defaultValue="5" isReadOnly="false"
converter="repast.simphony.parameter.StringConverterFactory$IntConverter" />

</parameters>

0 comments on commit 0ee4328

Please sign in to comment.