Commit ec8a1bdb authored by stefanSchuhbaeck's avatar stefanSchuhbaeck
Browse files

Fix Issue #29 multiple output columns in outputprocessor-file

Clear list of DataProcessors in OutputFile before init to prevent
duplicated DataProcessors after second run of scenario.
parent 16e03511
......@@ -73,6 +73,7 @@ public abstract class OutputFile<K extends DataKey<K>> {
@SuppressWarnings("unchecked")
public void init(final ProcessorManager manager) {
this.dataProcessors.clear();
processorIds.forEach(pid -> this.dataProcessors.add((DataProcessor<K, ?>) manager.getProcessor(pid)));
}
......
{
"name" : "basic_1_chicken_osm1",
"description" : "",
"release" : "0.2",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "out.txt",
"processors" : [ 1 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 1
} ],
"isTimestamped" : true
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
"pedPotentialWidth" : 0.5,
"pedPotentialHeight" : 12.6,
"obstPotentialWidth" : 0.25,
"obstPotentialHeight" : 20.1,
"useHardBodyShell" : false,
"obstDistanceDeviation" : 0.0,
"visionFieldRadius" : 5.0
},
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 18,
"numberOfCircles" : 1,
"varyStepDirection" : false,
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"optimizationType" : "DISCRETE",
"movementType" : "ARBITRARY",
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"minimumStepLength" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompact",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompact",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"timeCostAttributes" : {
"standardDerivation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT"
}
}
},
"attributesSimulation" : {
"finishTime" : 200.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.0,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"needsBoundary" : false,
"digitsPerCoordinate" : 2,
"useRandomSeed" : true,
"randomSeed" : 1
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 35.0,
"height" : 60.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true
},
"obstacles" : [ {
"shape" : {
"x" : 10.0,
"y" : 40.0,
"width" : 15.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 9.0,
"y" : 21.0,
"width" : 1.0,
"height" : 20.0,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 25.0,
"y" : 21.0,
"width" : 1.0,
"height" : 20.0,
"type" : "RECTANGLE"
},
"id" : -1
} ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 10.0,
"y" : 51.0,
"width" : 15.0,
"height" : 5.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"sources" : [ {
"id" : -1,
"shape" : {
"x" : 10.0,
"y" : 6.0,
"width" : 15.0,
"height" : 5.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 200,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : false,
"targetIds" : [ 1 ],
"dynamicElementType" : "PEDESTRIAN"
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.195,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.3,
"maximumSpeed" : 3.0,
"acceleration" : 2.0
},
"attributesCar" : null
}
}
}
\ No newline at end of file
package org.vadere.simulator.dataprocessing;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.MainModelBuilder;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.util.io.IOUtils;
public class TestOutputFileAfterMultipleRuns {
private Scenario testScenario;
private MainModel mainModel;
@Before
public void setup() {
try {
String json = IOUtils
.readTextFile(getClass().getResource("/data/basic_1_chicken_osm1.scenario").getPath());
testScenario = JsonConverter.deserializeScenarioRunManager(json);
MainModelBuilder modelBuilder = new MainModelBuilder(testScenario.getScenarioStore());
modelBuilder.createModelAndRandom();
mainModel = modelBuilder.getModel();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* If a scenario is run multiple times each processor should only be present once.
*/
@Test()
public void testFileFormatAfterMultipleSimulationRuns() {
ArrayList<String> headerAfterFirstRun = new ArrayList<>();
ArrayList<String> headerAfterSecondRun = new ArrayList<>();
ProcessorManager manager = testScenario.getDataProcessingJsonManager()
.createProcessorManager(mainModel);
manager.initOutputFiles();
List<OutputFile<?>> outputFiles = testScenario.getDataProcessingJsonManager().getOutputFiles();
outputFiles.forEach(f -> headerAfterFirstRun.add(f.getHeader()));
manager.initOutputFiles();
outputFiles.forEach(f -> headerAfterSecondRun.add(f.getHeader()));
assertEquals("Duplicated Processors in OutputFile after multiple Simulations",
headerAfterFirstRun, headerAfterSecondRun);
}
}
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