Skip to content
Snippets Groups Projects
Commit 56118efb authored by AxelCarayon's avatar AxelCarayon
Browse files

fix bug with invalid neighbor checking

parent eb2b5e08
No related branches found
No related tags found
No related merge requests found
<component name="ArtifactManager">
<artifact build-on-make="true" name="SMA-SEIR:jar">
<output-path>$PROJECT_DIR$/out/artifacts/SMA_SEIR_jar</output-path>
<root id="root">
<element id="archive" name="SMA-SEIR.jar">
<element id="module-output" name="SMA-SEIR" />
</element>
<element id="library" level="project" name="Maven: com.fasterxml.jackson.core:jackson-core:2.13.2" />
<element id="library" level="project" name="Maven: org.yaml:snakeyaml:1.30" />
<element id="library" level="project" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2" />
<element id="library" level="project" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.2" />
<element id="library" level="project" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.13.2.2" />
</root>
</artifact>
</component>
\ No newline at end of file
This diff is collapsed.
import csv
import matplotlib.pyplot as plt
def readCSV(fileName):
with open(fileName, 'r') as csvfile:
reader = csv.reader(csvfile)
return list(reader)
def showDiagram(data):
suceptible = []
exposed = []
recovred = []
infected = []
for row in data[1:]:
suceptible.append(int(row[0]))
exposed.append(int(row[1]))
recovred.append(int(row[2]))
infected.append(int(row[3]))
plt.plot(suceptible, label='Suceptible', color='gray')
plt.plot(exposed, label='Exposed', color='yellow')
plt.plot(infected, label='Infected', color='red')
plt.plot(recovred, label='Recovered', color='green')
plt.xlabel('Cycles')
plt.ylabel('Peoples')
plt.legend()
plt.show()
data = readCSV("output.csv")
showDiagram(data)
\ No newline at end of file
......@@ -110,6 +110,8 @@ public class SMA {
cpt++;
}
}
System.out.println("Simulation done !");
System.exit(0);
}
public static void main(String[] args) throws InterruptedException, IOException {
......
......@@ -48,7 +48,7 @@ public class RandomWalkingAgent implements Agent {
boolean isExposed = false;
for (Agent neighbor: environment.getNeighbors(position)) {
if (neighbor.getState() instanceof InfectedState) {
int roll = r.nextInt(100);
int roll = r.nextInt(100)+1;
if (roll <= YamlReader.getParams().getInfectionRate()*100) {
isExposed = true;
}
......@@ -60,7 +60,7 @@ public class RandomWalkingAgent implements Agent {
@Override
public boolean isInfected() {
boolean isSick = false;
int roll = r.nextInt(100);
int roll = r.nextInt(100)+1;
if (roll <= YamlReader.getParams().getIncubationRate()*100) {
isSick = true;
}
......@@ -70,7 +70,7 @@ public class RandomWalkingAgent implements Agent {
@Override
public boolean isRecovered() {
boolean isHealed = false;
int roll = r.nextInt(100);
int roll = r.nextInt(100)+1;
if (roll <= YamlReader.getParams().getRecoveryRate()*100) {
isHealed = true;
}
......@@ -80,7 +80,7 @@ public class RandomWalkingAgent implements Agent {
@Override
public boolean hasLostImmunity() {
boolean hasLostImmunity = false;
int roll = r.nextInt(100);
int roll = r.nextInt(100)+1;
if (roll <= YamlReader.getParams().getLooseImmunityRate()*100) {
hasLostImmunity = true;
}
......
......@@ -58,8 +58,8 @@ public class SquaredChunksEnvironment implements Environment {
}
private List<Agent> getChunkNeighbors(int relativeTo, Point p) {
Point chunk = new Point(p.x/CHUNK_SIZE,p.y/CHUNK_SIZE);
Point newPosition = getRelativePoint(relativeTo,p);
Point chunk = new Point(newPosition.x/CHUNK_SIZE,newPosition.y/CHUNK_SIZE);
var neighbors = new ArrayList<Agent>();
try{
for (Agent agent : chunks[chunk.x][chunk.y]) {
......
Manifest-Version: 1.0
Class-Path: jackson-core-2.13.2.jar snakeyaml-1.30.jar jackson-dataforma
t-yaml-2.13.2.jar jackson-annotations-2.13.2.jar jackson-databind-2.13.
2.2.jar
Main-Class: sma.SMA
......@@ -4,8 +4,8 @@ size : 500 #size of the world in pixels
nbOfPatientZero : 1
infectionRate : 0.3 #chance that an infected agent will spread to a susceptible agent
incubationRate : 0.1 #chance that an exposed agent become infected each cycle
recoveryRate : 0.05 #chance that an infected agent become recovered each cycle
recoveryRate : 0.3 #chance that an infected agent become recovered each cycle
looseImmunityRate : 0.05 #chance that a recovered agent become suceptible again
nbOfCycles : -1 #if the number is negative, will run endlessly
timeBetweenCycles : 50 #in milliseconds, 0 or lower will run cycles as fast as possible
timeBetweenCycles : 0 #in milliseconds, 0 or lower will run cycles as fast as possible
synchronousMode : false #if true, will wake synchronously the agents in a pseudo-random order based on the given seed otherwise will wake up the agents asynchronously
\ No newline at end of file
Manifest-Version: 1.0
Class-Path: jackson-core-2.13.2.jar snakeyaml-1.30.jar jackson-dataforma
t-yaml-2.13.2.jar jackson-annotations-2.13.2.jar jackson-databind-2.13.
2.2.jar
Main-Class: sma.SMA
......@@ -4,8 +4,8 @@ size : 500 #size of the world in pixels
nbOfPatientZero : 1
infectionRate : 0.3 #chance that an infected agent will spread to a susceptible agent
incubationRate : 0.1 #chance that an exposed agent become infected each cycle
recoveryRate : 0.05 #chance that an infected agent become recovered each cycle
recoveryRate : 0.3 #chance that an infected agent become recovered each cycle
looseImmunityRate : 0.05 #chance that a recovered agent become suceptible again
nbOfCycles : -1 #if the number is negative, will run endlessly
timeBetweenCycles : 50 #in milliseconds, 0 or lower will run as many cycles as possible
timeBetweenCycles : 0 #in milliseconds, 0 or lower will run cycles as fast as possible
synchronousMode : false #if true, will wake synchronously the agents in a pseudo-random order based on the given seed otherwise will wake up the agents asynchronously
\ 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