Skip to content
Snippets Groups Projects
Commit 22d4e53b authored by AxelCarayon's avatar AxelCarayon
Browse files

added calculation of density

parent 1a6dc23a
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 45 deletions
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version> <version>2.13.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml --> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId> <artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.2</version> <version>2.13.3</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
package agents; package agents;
import behaviors.Cyclic;
public sealed interface Agent public sealed interface Agent
permits CyclicAgent, ThreePhasedAgent{ permits CyclicAgent, ThreePhasedAgent{
......
...@@ -8,7 +8,7 @@ import java.awt.*; ...@@ -8,7 +8,7 @@ import java.awt.*;
public class RandomWalkingAgent3P extends RandomWakingAgent implements ThreePhasedSEIRSAgent { public class RandomWalkingAgent3P extends RandomWakingAgent implements ThreePhasedSEIRSAgent {
private String id; private final String id;
public RandomWalkingAgent3P(Point position, long seed, SEIRSEnvironment environment) { public RandomWalkingAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment); super(position, seed, environment);
......
package agents.seirs; package agents.seirs;
import agents.CyclicAgent; import agents.CyclicAgent;
import agents.states.SEIRSState;
import behaviors.Infectious;
import behaviors.Positionable2D;
public interface CyclicSEIRSAgent extends CyclicAgent, SEIRSAgent { public interface CyclicSEIRSAgent extends CyclicAgent, SEIRSAgent {
......
...@@ -45,9 +45,13 @@ public abstract class FairInfectionRWAgent extends Randomized implements SEIRSAg ...@@ -45,9 +45,13 @@ public abstract class FairInfectionRWAgent extends Randomized implements SEIRSAg
@Override @Override
public boolean isExposed() { public boolean isExposed() {
return rollExposition(environment, position, r.nextInt(10000));
}
static boolean rollExposition(SEIRSEnvironment environment, Point position, int i2) {
boolean isExposed = false; boolean isExposed = false;
for (int i = 0 ; i<environment.getInfectedNeighbors(position).size() ; i++) { for (int i = 0; i< environment.getInfectedNeighbors(position).size() ; i++) {
int roll = r.nextInt(10000)+1; int roll = i2 +1;
if (roll <= YamlReader.getParams().infectionRate()*10000) { if (roll <= YamlReader.getParams().infectionRate()*10000) {
isExposed = true; isExposed = true;
} }
......
package agents.seirs; package agents.seirs;
import agents.ThreePhasedAgent;
import environment.SEIRSEnvironment; import environment.SEIRSEnvironment;
import java.awt.*; import java.awt.*;
public class FairInfectionRWAgent3P extends FairInfectionRWAgent implements ThreePhasedSEIRSAgent { public class FairInfectionRWAgent3P extends FairInfectionRWAgent implements ThreePhasedSEIRSAgent {
private String id; private final String id;
public FairInfectionRWAgent3P(Point position, long seed, SEIRSEnvironment environment) { public FairInfectionRWAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment); super(position, seed, environment);
......
package agents.seirs; package agents.seirs;
import environment.SEIRSEnvironment; import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.*; import java.awt.*;
public class FairInfectionRWAgentCyclic extends FairInfectionRWAgent implements CyclicSEIRSAgent { public class FairInfectionRWAgentCyclic extends FairInfectionRWAgent implements CyclicSEIRSAgent {
private String id; private final String id;
public FairInfectionRWAgentCyclic(Point position, long seed, SEIRSEnvironment environment) { public FairInfectionRWAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment); super(position, seed, environment);
this.id = String.valueOf(seed); this.id = String.valueOf(seed);
......
...@@ -9,6 +9,8 @@ import utils.YamlReader; ...@@ -9,6 +9,8 @@ import utils.YamlReader;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
import static agents.seirs.FairInfectionRWAgent.rollExposition;
public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent { public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent {
protected Point position; protected Point position;
...@@ -46,14 +48,7 @@ public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent ...@@ -46,14 +48,7 @@ public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent
@Override @Override
public boolean isExposed() { public boolean isExposed() {
boolean isExposed = false; return rollExposition(environment, position, r.nextInt(10000));
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 @Override
......
package agents.seirs; package agents.seirs;
import agents.states.SEIRSState;
import agents.states.SuceptibleSEIRSState;
import behaviors.Randomized;
import environment.SEIRSEnvironment; import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.Point; import java.awt.Point;
import java.util.List;
public class RandomWalkingAgentCyclic extends RandomWakingAgent implements CyclicSEIRSAgent { public class RandomWalkingAgentCyclic extends RandomWakingAgent implements CyclicSEIRSAgent {
private String id; private final String id;
public RandomWalkingAgentCyclic(Point position, long seed, SEIRSEnvironment environment) { public RandomWalkingAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment); super(position, seed, environment);
......
package agents.states; package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
public class ExposedSEIRSState extends SEIRSState { public class ExposedSEIRSState extends SEIRSState {
......
package agents.states; package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
public class InfectedSEIRSState extends SEIRSState { public class InfectedSEIRSState extends SEIRSState {
......
package agents.states; package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
public class RecoveredSEIRSState extends SEIRSState { public class RecoveredSEIRSState extends SEIRSState {
......
package agents.states; package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
public class SuceptibleSEIRSState extends SEIRSState { public class SuceptibleSEIRSState extends SEIRSState {
......
package environment; package environment;
import agents.Agent; import agents.Agent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
import agents.states.InfectedSEIRSState; import agents.states.InfectedSEIRSState;
import agents.states.SEIRSState; import agents.states.SEIRSState;
...@@ -50,8 +49,8 @@ public class ChunkedSEIRSEnvironment implements SEIRSEnvironment { ...@@ -50,8 +49,8 @@ public class ChunkedSEIRSEnvironment implements SEIRSEnvironment {
private Point getRelativePoint(int relativeTo, Point p) { private Point getRelativePoint(int relativeTo, Point p) {
return switch (relativeTo) { return switch (relativeTo) {
case LEFT -> new Point(p.x-1,p.y); //case LEFT -> new Point(p.x-1,p.y);
case RIGHT -> new Point(p.x+1,p.y); case LEFT, RIGHT -> new Point(p.x+1,p.y);
case UP -> new Point(p.x,p.y-1); case UP -> new Point(p.x,p.y-1);
case DOWN -> new Point(p.x,p.y+1); case DOWN -> new Point(p.x,p.y+1);
case CENTER -> p; case CENTER -> p;
......
package environment; package environment;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
import java.awt.*; import java.awt.*;
......
package environment; package environment;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent; import agents.seirs.SEIRSAgent;
import behaviors.Positionable2D; import behaviors.Positionable2D;
......
...@@ -178,6 +178,7 @@ public class SEIRS_SMA extends Randomized implements SMA{ ...@@ -178,6 +178,7 @@ public class SEIRS_SMA extends Randomized implements SMA{
@Override @Override
public void run() { public void run() {
calculateDensity();
Instant startTime = Instant.now(); Instant startTime = Instant.now();
System.out.println("Starting simulation at : "+ Date.from(startTime)); System.out.println("Starting simulation at : "+ Date.from(startTime));
if (parameters.nbOfCycles() <0) { if (parameters.nbOfCycles() <0) {
...@@ -203,6 +204,12 @@ public class SEIRS_SMA extends Randomized implements SMA{ ...@@ -203,6 +204,12 @@ public class SEIRS_SMA extends Randomized implements SMA{
} }
} }
private void calculateDensity() {
int pixels = parameters.size()*parameters.size();
int agents = parameters.population();
System.out.println("Population density is : " + (float)agents/pixels + " agents per pixel.");
}
public static void main(String[] args) { public static void main(String[] args) {
SMA sma = new SEIRS_SMA(YamlReader.getParams()); SMA sma = new SEIRS_SMA(YamlReader.getParams());
sma.run(); sma.run();
......
src/main/resources/output.png

63 KiB | W: | H:

src/main/resources/output.png

56.4 KiB | W: | H:

src/main/resources/output.png
src/main/resources/output.png
src/main/resources/output.png
src/main/resources/output.png
  • 2-up
  • Swipe
  • Onion skin
graphicalMode: true graphicalMode: true
incubationRate: 0.3 incubationRate: 0.33
infectionRate: 0.8 infectionRate: 0.5
looseImmunityRate: 0.008 looseImmunityRate: 0.0027
recoveryRate: 0.14 recoveryRate: 0.10
nbOfCycles: 2000 nbOfCycles: 720
nbOfPatientZero: 1 nbOfPatientZero: 1
population: 3000 population: 1000
recordExperiment: false recordExperiment: false
playRecord: false playRecord: false
seed: 120 seed: 120
size: 1000 size: 400
wrappingWorld : true wrappingWorld : true
synchronousMode: false synchronousMode: false
timeBetweenCycles: 0 timeBetweenCycles: 0
infectionStacks : false infectionStacks : true
threePhased : false threePhased : false
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment