Commit 6b5da450 authored by Jose Ignacio Monreal Bailey's avatar Jose Ignacio Monreal Bailey
Browse files

Adding summary of messages sent by nodes, and disabling reuse of objects

parent 17891c48
......@@ -30,6 +30,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Random;
import de.tud.kom.p2psim.impl.util.Summary;
import org.apache.commons.math.random.JDKRandomGenerator;
import org.apache.commons.math.random.RandomGenerator;
......@@ -273,6 +274,8 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
// SkyNetBatchSimulator.getInstance().finish(finishedWithoutError);
// }
Summary.simulationFinished();
for (SimulatorObserver so : observers) {
so.simulationFinished();
}
......
......@@ -66,7 +66,7 @@ public class RSUMovementModel implements MovementModel, EventHandler {
private long timeBetweenMoveOperations;
private boolean initialized = false;
private boolean _reuseComponents = true;
private boolean _reuseComponents = false;
private TrafficLightController _controller;
private SimulationSetupExtractor _extractor;
......
......@@ -56,7 +56,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private static final Location DEFAULT_LOCATION = new PositionVector(Double.NaN, Double.NaN);
private boolean _reuseComponents = true;
private boolean _reuseComponents = false;
private static VehicleMovementModel MOVEMENT;
......
package de.tud.kom.p2psim.impl.util;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.vehicular.trafficlights.DefaultTrafficLightInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class Summary {
private static String csvOutputFilename = "";
public static void simulationFinished() {
Map<String, List<SimHost>> hosts = Simulator.getInstance().getScenario().getHosts();
List<SimHost> simHostList = hosts.getOrDefault("TrafficLights", null);
for (SimHost simHost : simHostList) {
try {
DefaultTrafficLightInformationComponent trafficLightInformationComponent = simHost.getComponent(DefaultTrafficLightInformationComponent.class);
csvOutputFilename = simHost.getProperties().getProperty("csvOutputFile");
writeToCSV(trafficLightInformationComponent.getTrafficLightId(), trafficLightInformationComponent.getNumberOfMessagesSent());
} catch (ComponentNotAvailableException e) {
e.printStackTrace();
}
}
}
private static void writeToCSV(String id, Double msgSent) {
try {
File file = new File(csvOutputFilename);
String log = "";
if (!file.exists()) {
file.createNewFile();
log += "id;messagesSent;\n";
}
FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
log += id + ";" + String.valueOf(msgSent) + ";\n";
bufferedWriter.write(log);
bufferedWriter.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
......@@ -19,12 +19,22 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo
private SimulationSetupExtractor extractor;
private String trafficLightId;
private Double numberOfMessagesSent;
public DefaultTrafficLightInformationComponent(Host host, TrafficLightController controller, SimulationSetupExtractor extractor) {
this.host = host;
this.controller = controller;
this.extractor = extractor;
this.numberOfMessagesSent = 0.0;
}
public void incrementNumberOfMessagesSent() {
numberOfMessagesSent++;
}
public double getNumberOfMessagesSent() {
return numberOfMessagesSent;
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment