Skip to content
Snippets Groups Projects
Commit 5d7de619 authored by AxelCarayon's avatar AxelCarayon
Browse files

added three phased agents*

parent 38002536
Branches
No related tags found
1 merge request!10added three phased agents
Showing
with 304 additions and 64 deletions
......@@ -11,15 +11,10 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
<component name="SwUserDefinedSpecifications">
<option name="specTypeByUrl">
<map />
</option>
</component>
</project>
\ No newline at end of file
......@@ -7,6 +7,19 @@
<groupId>org.IRIT</groupId>
<artifactId>SMA-SEIR</artifactId>
<version>0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>18</source>
<target>18</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>17</maven.compiler.source>
......
package agents;
import behaviors.Wakeable;
import behaviors.Cyclic;
public interface Agent extends Wakeable {
public sealed interface Agent
permits CyclicAgent, ThreePhasedAgent{
String getId();
}
package agents;
import behaviors.Cyclic;
public non-sealed interface CyclicAgent extends Agent, Cyclic {
}
package agents;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.*;
public class FairInfectionRWAgent extends RandomWalkingAgent implements SEIRSAgent {
public FairInfectionRWAgent(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
}
@Override
public boolean isExposed() {
boolean isExposed = false;
int roll = r.nextInt(10000)+1;
if (this.environment.getInfectedNeighbors(position).size() != 0) {
if (roll <= YamlReader.getParams().infectionRate()*10000) {
isExposed = true;
}
}
return isExposed;
}
}
package agents;
import agents.seirs.RandomWakingAgent;
import agents.seirs.ThreePhasedSEIRSAgent;
import environment.SEIRSEnvironment;
import java.awt.*;
public class RandomWalkingAgent3P extends RandomWakingAgent implements ThreePhasedSEIRSAgent {
private String id;
public RandomWalkingAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
this.id = String.valueOf(seed);
}
@Override
public String getId() {
return id;
}
@Override
public void perceive() {
perceiveAuthorizedPositions();
}
@Override
public void decide() {
decideNextMove();
}
@Override
public void act() {
move();
}
}
package agents;
import behaviors.ThreePhased;
public non-sealed interface ThreePhasedAgent extends Agent, ThreePhased {
}
package agents.seirs;
import agents.CyclicAgent;
import agents.states.SEIRSState;
import behaviors.Infectious;
import behaviors.Positionable2D;
public interface CyclicSEIRSAgent extends CyclicAgent, SEIRSAgent {
void wakeUp();
}
package agents.seirs;
import agents.states.SEIRSState;
import agents.states.SuceptibleSEIRSState;
import behaviors.Randomized;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.*;
import java.util.List;
public abstract class FairInfectionRWAgent extends Randomized implements SEIRSAgent {
protected Point position;
protected final SEIRSEnvironment environment;
protected SEIRSState state;
protected List<Point> authorizedPositions;
protected Point nextPosition;
public FairInfectionRWAgent(Point position, long seed, SEIRSEnvironment environment) {
super(seed);
this.position = position;
this.state = new SuceptibleSEIRSState(this);
this.environment = environment;
r.setSeed(seed);
}
protected void move() {
state.onMovement();
environment.notifyNewPosition(nextPosition,this);
position = nextPosition;
}
protected void perceiveAuthorizedPositions() {
authorizedPositions = environment.perceiveAuthorizedPositions(this);
}
protected void decideNextMove() {
int next = r.nextInt(authorizedPositions.size());
nextPosition = authorizedPositions.get(next);
}
@Override
public void changeState(SEIRSState SEIRSState) { this.state = SEIRSState; }
@Override
public boolean isExposed() {
boolean isExposed = false;
for (int i = 0 ; i<environment.getInfectedNeighbors(position).size() ; i++) {
int roll = r.nextInt(10000)+1;
if (roll <= YamlReader.getParams().infectionRate()*10000) {
isExposed = true;
}
}
return isExposed;
}
@Override
public boolean isInfected() {
boolean isSick = false;
int roll = r.nextInt(10000)+1;
if (roll <= YamlReader.getParams().incubationRate()*10000) {
isSick = true;
}
return isSick;
}
@Override
public boolean isRecovered() {
boolean isHealed = false;
int roll = r.nextInt(10000)+1;
if (roll <= YamlReader.getParams().recoveryRate()*10000) {
isHealed = true;
}
return isHealed;
}
@Override
public boolean hasLostImmunity() {
boolean hasLostImmunity = false;
int roll = r.nextInt(10000)+1;
if (roll <= YamlReader.getParams().looseImmunityRate()*10000) {
hasLostImmunity = true;
}
return hasLostImmunity;
}
@Override
public SEIRSState getState() { return this.state; }
@Override
public Point getPosition() { return position; }
}
package agents.seirs;
import agents.ThreePhasedAgent;
import environment.SEIRSEnvironment;
import java.awt.*;
public class FairInfectionRWAgent3P extends FairInfectionRWAgent implements ThreePhasedSEIRSAgent {
private String id;
public FairInfectionRWAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
this.id = String.valueOf(seed);
}
@Override
public void perceive() {
perceiveAuthorizedPositions();
}
@Override
public void decide() {
decideNextMove();
}
@Override
public void act() {
move();
}
@Override
public String getId() {
return this.id;
}
}
package agents.seirs;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.*;
public class FairInfectionRWAgentCyclic extends FairInfectionRWAgent implements CyclicSEIRSAgent {
private String id;
public FairInfectionRWAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
this.id = String.valueOf(seed);
}
@Override
public void wakeUp() {
perceiveAuthorizedPositions();
if (!authorizedPositions.isEmpty()) {
decideNextMove();
move();
}
}
@Override
public String getId() {
return this.id;
}
}
package agents;
package agents.seirs;
import agents.states.SEIRSState;
import agents.states.SuceptibleSEIRSState;
......@@ -6,52 +6,41 @@ import behaviors.Randomized;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.Point;
import java.awt.*;
import java.util.List;
public class RandomWalkingAgent extends Randomized implements SEIRSAgent {
public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent {
protected Point position;
protected final SEIRSEnvironment environment;
protected SEIRSState state;
private List<Point> authorizedPositions;
private Point nextPosition;
private final String id;
protected List<Point> authorizedPositions;
protected Point nextPosition;
public RandomWalkingAgent(Point position, long seed, SEIRSEnvironment environment) {
public RandomWakingAgent(Point position, long seed, SEIRSEnvironment environment) {
super(seed);
this.id = String.valueOf(seed);
this.position = position;
this.state = new SuceptibleSEIRSState(this);
this.environment = environment;
r.setSeed(seed);
}
private void move() {
protected void move() {
state.onMovement();
environment.notifyNewPosition(nextPosition,this);
position = nextPosition;
}
private void perceiveAuthorizedPositions() {
protected void perceiveAuthorizedPositions() {
authorizedPositions = environment.perceiveAuthorizedPositions(this);
}
private void decideNextMove() {
protected void decideNextMove() {
int next = r.nextInt(authorizedPositions.size());
nextPosition = authorizedPositions.get(next);
}
@Override
public void wakeUp() {
perceiveAuthorizedPositions();
if (!authorizedPositions.isEmpty()) {
decideNextMove();
move();
}
}
@Override
public void changeState(SEIRSState SEIRSState) { this.state = SEIRSState; }
......@@ -103,9 +92,4 @@ public class RandomWalkingAgent extends Randomized implements SEIRSAgent {
@Override
public Point getPosition() { return position; }
@Override
public String getId() {
return this.id;
}
}
package agents.seirs;
import agents.states.SEIRSState;
import agents.states.SuceptibleSEIRSState;
import behaviors.Randomized;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.Point;
import java.util.List;
public class RandomWalkingAgentCyclic extends RandomWakingAgent implements CyclicSEIRSAgent {
private String id;
public RandomWalkingAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
this.id = String.valueOf(seed);
}
@Override
public void wakeUp() {
perceiveAuthorizedPositions();
if (!authorizedPositions.isEmpty()) {
decideNextMove();
move();
}
}
@Override
public String getId() {
return this.id;
}
}
package agents.seirs;
import behaviors.Infectious;
import behaviors.Positionable2D;
public interface SEIRSAgent extends Positionable2D, Infectious {
}
package agents.seirs;
import agents.ThreePhasedAgent;
public interface ThreePhasedSEIRSAgent extends ThreePhasedAgent,SEIRSAgent {
}
package agents.states;
import agents.SEIRSAgent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class ExposedSEIRSState extends SEIRSState {
......
package agents.states;
import agents.SEIRSAgent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class InfectedSEIRSState extends SEIRSState {
......
package agents.states;
import agents.SEIRSAgent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class RecoveredSEIRSState extends SEIRSState {
......
package agents.states;
import agents.SEIRSAgent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public abstract class SEIRSState {
......@@ -9,7 +10,7 @@ public abstract class SEIRSState {
public final static String SUCEPTIBLE = "SUCEPTIBLE";
public final static String RECOVERED = "RECOVERED";
protected final agents.SEIRSAgent agent;
protected final SEIRSAgent agent;
SEIRSState(SEIRSAgent agent) {
this.agent = agent;
......
package agents.states;
import agents.SEIRSAgent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class SuceptibleSEIRSState extends SEIRSState {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment