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

added time calculation

parent 8f1a49e7
Branches
Tags
No related merge requests found
......@@ -26,8 +26,13 @@ def showDiagram(data):
plt.ylabel('Peoples')
plt.legend()
plt.show()
def runJavaJar(fileName):
import subprocess
subprocess.call(['java', '-jar', fileName])
runJavaJar('out/artifacts/SMA_SEIR_jar/SMA-SEIR.jar')
data = readCSV("src/main/resources/output.csv")
# data = readCSV("src/main/resources/output.csv")
showDiagram(data)
\ No newline at end of file
# showDiagram(data)
\ No newline at end of file
......@@ -13,6 +13,7 @@ public class Parameters {
private int nbOfCycles;
private int timeBetweenCycles;
private boolean synchronousMode;
private boolean graphicalMode;
public Parameters() {
}
......@@ -60,4 +61,8 @@ public class Parameters {
public int getTimeBetweenCycles() { return timeBetweenCycles; }
public void setTimeBetweenCycles(int timeBetweenCycles) { this.timeBetweenCycles = timeBetweenCycles; }
public boolean isGraphicalMode() { return graphicalMode; }
public void setGraphicalMode(boolean graphicalMode) { this.graphicalMode = graphicalMode; }
}
......@@ -15,6 +15,11 @@ import view.StatisticsCanvas;
import java.awt.*;
import java.io.IOException;
import java.sql.SQLOutput;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import java.util.Random;
......@@ -36,12 +41,8 @@ public class SMA {
parameters = YamlReader.getParams();
r = new Random(parameters.getSeed());
agents = new RandomWalkingAgent[parameters.getPopulation()];
statisticsCanvas = new StatisticsCanvas(500,500);
frameBuilder = new FrameBuilder();
}
private void populateEnvironment() {
for (int i = 0; i<parameters.getPopulation();i++) {
Point position = new Point(r.nextInt(parameters.getSize()),r.nextInt(parameters.getSize()));
......@@ -70,13 +71,20 @@ public class SMA {
populateEnvironment();
environment.initiateChunks();
infectPatientZero();
initScheduler();
if (parameters.isGraphicalMode()) {
initGraphics();
}
}
private void initGraphics() {
statisticsCanvas = new StatisticsCanvas(500,500);
display = new DisplaySquaredEnvironment(environment,agents);
frameBuilder = new FrameBuilder();
frameBuilder.addComponent(display,FrameBuilder.TOP);
frameBuilder.addComponent(statisticsCanvas,FrameBuilder.RIGHT);
frameBuilder.buildWindow();
initScheduler();
statisticsCanvas.updateValues(environment.getAgentStatus());
statisticsCanvas.repaint();
}
......@@ -91,14 +99,17 @@ public class SMA {
scheduler.nextCycle();
stats = environment.getAgentStatus();
StatsRecorder.writeToCSV(stats,"src/main/resources/output.csv");
updateGraphics();
if (parameters.isGraphicalMode()) {
updateGraphics();
}
if (parameters.getTimeBetweenCycles() > 0) {
Thread.sleep(parameters.getTimeBetweenCycles());
}
}
public void run() throws IOException, InterruptedException {
Instant startTime = Instant.now();
System.out.println("Starting simulation at : "+ Date.from(startTime));
if (parameters.getNbOfCycles() <0) {
while (true) {
doNextCycle();
......@@ -109,9 +120,12 @@ public class SMA {
doNextCycle();
cpt++;
}
Instant endTime = Instant.now();
System.out.println("Simulation done !");
Duration duration = Duration.between(startTime,endTime);
System.out.println("Elapsed time : " + duration.toHoursPart() + " hours, " + duration.toMinutesPart() + " minutes, " + duration.toSecondsPart() + "seconds.");
System.exit(0);
}
System.out.println("Simulation done !");
System.exit(0);
}
public static void main(String[] args) throws InterruptedException, IOException {
......
......@@ -6,6 +6,7 @@ infectionRate : 0.3 #chance that an infected agent will spread to a susceptible
incubationRate : 0.1 #chance that an exposed agent become infected 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
nbOfCycles : 10000 #if the number is negative, will run endlessly
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
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
graphicalMode : false #if false, will run without graphical interface
\ No newline at end of file
This diff is collapsed.
......@@ -6,6 +6,7 @@ infectionRate : 0.3 #chance that an infected agent will spread to a susceptible
incubationRate : 0.1 #chance that an exposed agent become infected 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
nbOfCycles : 10000 #if the number is negative, will run endlessly
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
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
graphicalMode : false #if false, will run without graphical interface
\ 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