Skip to content
Snippets Groups Projects
Commit 84d70fd6 authored by AxelCarayon's avatar AxelCarayon
Browse files

minor refactoring

parent 86e8f010
No related branches found
No related tags found
No related merge requests found
SUCEPTIBLE,EXPOSED,RECOVERED,INFECTED
9994,5,0,1
9982,14,0,4
9954,34,0,12
9878,93,0,29
9764,166,0,70
9603,226,6,165
9393,326,17,264
9147,404,32,417
8871,465,61,603
8536,562,101,801
8186,604,144,1066
7837,636,201,1326
7398,755,280,1567
6979,799,365,1857
6505,870,477,2148
6038,891,613,2458
5594,877,771,2758
5175,854,957,3014
4751,818,1146,3285
4319,875,1348,3458
3890,874,1574,3662
3450,866,1829,3855
3032,861,2053,4054
2680,791,2299,4230
2286,787,2582,4345
1899,781,2874,4446
1571,718,3112,4599
1262,680,3396,4662
987,609,3675,4729
780,529,3984,4707
559,488,4217,4736
412,399,4513,4676
298,316,4799,4587
216,253,5070,4461
144,192,5315,4349
84,141,5574,4201
38,105,5846,4011
15,73,6097,3815
2,49,6332,3617
1,24,6570,3405
0,14,6776,3210
0,6,6967,3027
0,1,7155,2844
0,0,7325,2675
0,0,7505,2495
0,0,7644,2356
0,0,7782,2218
0,0,7901,2099
0,0,8035,1965
0,0,8161,1839
0,0,8266,1734
0,0,8366,1634
0,0,8460,1540
0,0,8559,1441
0,0,8648,1352
0,0,8727,1273
0,0,8800,1200
0,0,8869,1131
0,0,8950,1050
0,0,8994,1006
0,0,9058,942
0,0,9117,883
0,0,9171,829
0,0,9214,786
0,0,9279,721
0,0,9310,690
0,0,9350,650
0,0,9396,604
0,0,9428,572
9995,4,0,1
9983,13,0,4
9953,36,0,11
9882,88,1,29
9789,140,2,69
9654,208,6,132
9470,302,20,208
9251,358,30,361
9002,436,51,511
8658,561,87,694
8284,641,128,947
7899,706,193,1202
7478,788,265,1469
6985,873,355,1787
6527,883,462,2128
6054,937,596,2413
5579,957,742,2722
5179,873,901,3047
4767,824,1080,3329
4326,887,1280,3507
3860,882,1524,3734
3421,873,1768,3938
3023,815,2010,4152
2624,819,2264,4293
2293,735,2548,4424
1897,744,2826,4533
1582,688,3089,4641
1259,666,3346,4729
1004,587,3638,4771
780,523,3935,4762
582,461,4248,4709
402,403,4525,4670
269,346,4803,4582
177,265,5067,4491
104,219,5364,4313
35,175,5628,4162
14,110,5886,3990
4,63,6151,3782
1,33,6360,3606
0,21,6570,3409
0,7,6778,3215
0,3,6979,3018
0,1,7126,2873
0,1,7290,2709
0,1,7451,2548
0,0,7603,2397
0,0,7755,2245
0,0,7870,2130
......@@ -5,8 +5,8 @@ import sma.agents.states.State;
public interface Agent {
void changeState(State state);
boolean contact();
boolean incubate();
boolean recover();
boolean isExposed();
boolean isInfected();
boolean isRecovered();
void move();
}
......@@ -15,11 +15,7 @@ public class RandomWalkingAgent implements Agent {
private Point position;
private Random r;
private GraphicEnvironment environment;
private State state;
private Boolean exposedThisCycle;
private Boolean infectedThisCycle;
public RandomWalkingAgent(Point position, int seed, GraphicEnvironment environment) {
this.position = position;
......@@ -29,8 +25,9 @@ public class RandomWalkingAgent implements Agent {
}
public void move() {
state.onMovement();
int move = r.nextInt(4);
Point newPosition = switch (move) {
case Environment.LEFT -> new Point(position.x-environment.RADIUS,position.y);
case Environment.RIGHT -> new Point(position.x+environment.RADIUS,position.y);
......@@ -45,12 +42,10 @@ public class RandomWalkingAgent implements Agent {
}
@Override
public void changeState(State state) {
this.state = state;
}
public void changeState(State state) { this.state = state; }
@Override
public boolean contact() {
public boolean isExposed() {
boolean isExposed = false;
for (RandomWalkingAgent neighbor: environment.getNeighbors(position)) {
if (neighbor.getState() instanceof InfectedState) {
......@@ -64,7 +59,7 @@ public class RandomWalkingAgent implements Agent {
}
@Override
public boolean incubate() {
public boolean isInfected() {
boolean isSick = false;
int roll = r.nextInt(100);
if (roll <= YamlReader.getParams().getIncubationRate()*100) {
......@@ -74,7 +69,7 @@ public class RandomWalkingAgent implements Agent {
}
@Override
public boolean recover() {
public boolean isRecovered() {
boolean isHealed = false;
int roll = r.nextInt(100);
if (roll <= YamlReader.getParams().getRecoveryRate()*100) {
......@@ -83,18 +78,8 @@ public class RandomWalkingAgent implements Agent {
return isHealed;
}
public State getState() {
return this.state;
}
public State getState() { return this.state; }
public void wakeUp() {
exposedThisCycle = false;
infectedThisCycle = false;
state.onMovement();
}
public Point getPosition() {
return position;
}
public Point getPosition() { return position; }
}
......@@ -10,8 +10,7 @@ public class ExposedState extends State{
@Override
public void onMovement() {
agent.move();
if (agent.incubate()) {
if (agent.isInfected()) {
agent.changeState(new InfectedState(agent));
}
}
......
......@@ -10,8 +10,7 @@ public class InfectedState extends State{
@Override
public void onMovement() {
agent.move();
if (agent.recover()) {
if (agent.isRecovered()) {
agent.changeState(new RecoveredState(agent));
}
}
......
......@@ -10,7 +10,7 @@ public class RecoveredState extends State{
@Override
public void onMovement() {
agent.move();
}
@Override
......
......@@ -10,8 +10,7 @@ public class SuceptibleState extends State{
@Override
public void onMovement() {
agent.move();
if (agent.contact()) {
if (agent.isExposed()) {
agent.changeState(new ExposedState(agent));
}
}
......
......@@ -20,7 +20,7 @@ public class FairAsynchronousScheduler implements Scheduler{
public void nextCycle() {
List<Future<RandomWalkingAgent>> results = queue.parallelStream().map(agent -> executor.submit(() -> {agent.wakeUp(); return agent;})).collect(Collectors.toList());
List<Future<RandomWalkingAgent>> results = queue.parallelStream().map(agent -> executor.submit(() -> {agent.move(); return agent;})).collect(Collectors.toList());
Function<Future<RandomWalkingAgent>, RandomWalkingAgent> futureTreatment = futureAgent -> {
try {
return futureAgent.get();
......
......@@ -25,7 +25,7 @@ public class FairSynchronousScheduler implements Scheduler {
private void wakeAgents() {
while (!executionOrder.isEmpty()) {
agents[(executionOrder.pop())].wakeUp();
agents[(executionOrder.pop())].move();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment