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

added calculation of density

parent 1a6dc23a
Branches
No related tags found
No related merge requests found
Showing
with 32 additions and 45 deletions
......@@ -31,14 +31,14 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
<version>2.13.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.2</version>
<version>2.13.3</version>
</dependency>
</dependencies>
......
package agents;
import behaviors.Cyclic;
public sealed interface Agent
permits CyclicAgent, ThreePhasedAgent{
......
......@@ -8,7 +8,7 @@ import java.awt.*;
public class RandomWalkingAgent3P extends RandomWakingAgent implements ThreePhasedSEIRSAgent {
private String id;
private final String id;
public RandomWalkingAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
......
package agents.seirs;
import agents.CyclicAgent;
import agents.states.SEIRSState;
import behaviors.Infectious;
import behaviors.Positionable2D;
public interface CyclicSEIRSAgent extends CyclicAgent, SEIRSAgent {
......
......@@ -45,9 +45,13 @@ public abstract class FairInfectionRWAgent extends Randomized implements SEIRSAg
@Override
public boolean isExposed() {
return rollExposition(environment, position, r.nextInt(10000));
}
static boolean rollExposition(SEIRSEnvironment environment, Point position, int i2) {
boolean isExposed = false;
for (int i = 0 ; i<environment.getInfectedNeighbors(position).size() ; i++) {
int roll = r.nextInt(10000)+1;
for (int i = 0; i< environment.getInfectedNeighbors(position).size() ; i++) {
int roll = i2 +1;
if (roll <= YamlReader.getParams().infectionRate()*10000) {
isExposed = true;
}
......
package agents.seirs;
import agents.ThreePhasedAgent;
import environment.SEIRSEnvironment;
import java.awt.*;
public class FairInfectionRWAgent3P extends FairInfectionRWAgent implements ThreePhasedSEIRSAgent {
private String id;
private final String id;
public FairInfectionRWAgent3P(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
......
package agents.seirs;
import environment.SEIRSEnvironment;
import utils.YamlReader;
import java.awt.*;
public class FairInfectionRWAgentCyclic extends FairInfectionRWAgent implements CyclicSEIRSAgent {
private String id;
private final String id;
public FairInfectionRWAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
this.id = String.valueOf(seed);
......
......@@ -9,6 +9,8 @@ import utils.YamlReader;
import java.awt.*;
import java.util.List;
import static agents.seirs.FairInfectionRWAgent.rollExposition;
public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent {
protected Point position;
......@@ -46,14 +48,7 @@ public abstract class RandomWakingAgent extends Randomized implements SEIRSAgent
@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;
return rollExposition(environment, position, r.nextInt(10000));
}
@Override
......
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;
private final String id;
public RandomWalkingAgentCyclic(Point position, long seed, SEIRSEnvironment environment) {
super(position, seed, environment);
......
package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class ExposedSEIRSState extends SEIRSState {
......
package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class InfectedSEIRSState extends SEIRSState {
......
package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class RecoveredSEIRSState extends SEIRSState {
......
package agents.states;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
public class SuceptibleSEIRSState extends SEIRSState {
......
package environment;
import agents.Agent;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
import agents.states.InfectedSEIRSState;
import agents.states.SEIRSState;
......@@ -50,8 +49,8 @@ public class ChunkedSEIRSEnvironment implements SEIRSEnvironment {
private Point getRelativePoint(int relativeTo, Point p) {
return switch (relativeTo) {
case LEFT -> new Point(p.x-1,p.y);
case RIGHT -> new Point(p.x+1,p.y);
//case LEFT -> 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 DOWN -> new Point(p.x,p.y+1);
case CENTER -> p;
......
package environment;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
import java.awt.*;
......
package environment;
import agents.seirs.CyclicSEIRSAgent;
import agents.seirs.SEIRSAgent;
import behaviors.Positionable2D;
......
......@@ -178,6 +178,7 @@ public class SEIRS_SMA extends Randomized implements SMA{
@Override
public void run() {
calculateDensity();
Instant startTime = Instant.now();
System.out.println("Starting simulation at : "+ Date.from(startTime));
if (parameters.nbOfCycles() <0) {
......@@ -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) {
SMA sma = new SEIRS_SMA(YamlReader.getParams());
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
incubationRate: 0.3
infectionRate: 0.8
looseImmunityRate: 0.008
recoveryRate: 0.14
nbOfCycles: 2000
incubationRate: 0.33
infectionRate: 0.5
looseImmunityRate: 0.0027
recoveryRate: 0.10
nbOfCycles: 720
nbOfPatientZero: 1
population: 3000
population: 1000
recordExperiment: false
playRecord: false
seed: 120
size: 1000
size: 400
wrappingWorld : true
synchronousMode: false
timeBetweenCycles: 0
infectionStacks : false
infectionStacks : true
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