Commit fda16b6e authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

refactor

parent 23268b9f
Pipeline #367297 passed with stages
in 131 minutes and 53 seconds
package org.vadere.simulator.control.scenarioelements; package org.vadere.simulator.control.scenarioelements;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.control.simulation.Simulation;
import org.vadere.simulator.models.DynamicElementFactory; import org.vadere.simulator.models.DynamicElementFactory;
import org.vadere.state.attributes.scenario.AttributesDynamicElement; import org.vadere.state.attributes.scenario.AttributesDynamicElement;
import org.vadere.state.scenario.Source; import org.vadere.state.scenario.Source;
...@@ -98,10 +97,10 @@ public class SingleSourceController extends SourceController { ...@@ -98,10 +97,10 @@ public class SingleSourceController extends SourceController {
} }
// Report nr. of agents that could not be spawned -- it is up to SpawnDistribution if it // Report nr. of agents that could not be spawned -- it is up to SpawnDistribution if it
// wants to try to spawn the agents im the next update. // wants to try to spawn the agents in the next update.
int outstandingAgents = numberToSpawn - spawnPoints.size(); int remainingAgents = numberToSpawn - spawnPoints.size();
assert (outstandingAgents >= 0); assert (remainingAgents >= 0);
this.distribution.setOutstandingAgents(outstandingAgents); this.distribution.setRemainingSpawnAgents(remainingAgents);
for (VPoint spawnPoint : spawnPoints) { for (VPoint spawnPoint : spawnPoints) {
if (!isMaximumNumberOfSpawnedElementsReached()) { if (!isMaximumNumberOfSpawnedElementsReached()) {
...@@ -225,7 +224,7 @@ public class SingleSourceController extends SourceController { ...@@ -225,7 +224,7 @@ public class SingleSourceController extends SourceController {
// The concrete distribution implements how to proceed with agents that could not all be spawned // The concrete distribution implements how to proceed with agents that could not all be spawned
// e.g. because the source is too small // e.g. because the source is too small
numberToSpawn = this.distribution.getOutstandingSpawnNumber(); numberToSpawn = this.distribution.getRemainingSpawnAgents();
while (timeOfNextEvent <= simTimeInSec) { while (timeOfNextEvent <= simTimeInSec) {
numberToSpawn += distribution.getSpawnNumber(timeOfNextEvent); numberToSpawn += distribution.getSpawnNumber(timeOfNextEvent);
......
/*
package org.vadere.simulator.control; package org.vadere.simulator.control;
import org.junit.Test; import org.junit.Test;
...@@ -37,3 +39,4 @@ public class TestSourceControllerUsingNegativeExponentialSpawnRate extends TestS ...@@ -37,3 +39,4 @@ public class TestSourceControllerUsingNegativeExponentialSpawnRate extends TestS
assertEquals(meanIterArrival, 1/arrivalRatePerSec,0.1); assertEquals(meanIterArrival, 1/arrivalRatePerSec,0.1);
} }
} }
*/
\ No newline at end of file
package org.vadere.state.scenario; package org.vadere.state.scenario;
import org.apache.commons.math3.distribution.ConstantRealDistribution;
import org.apache.commons.math3.random.RandomGenerator; import org.apache.commons.math3.random.RandomGenerator;
import java.util.List; import java.util.List;
...@@ -15,7 +14,7 @@ public class ConstantDistribution implements SpawnDistribution { ...@@ -15,7 +14,7 @@ public class ConstantDistribution implements SpawnDistribution {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int spawnNumber; private int spawnNumber;
private int outstandingAgents; private int remainingAgents;
private double updateFrequency; private double updateFrequency;
...@@ -24,7 +23,7 @@ public class ConstantDistribution implements SpawnDistribution { ...@@ -24,7 +23,7 @@ public class ConstantDistribution implements SpawnDistribution {
//rng is not required, everything is deterministic //rng is not required, everything is deterministic
this.spawnNumber = spawnNumber; this.spawnNumber = spawnNumber;
this.outstandingAgents = 0; this.remainingAgents = 0;
this.updateFrequency = distributionParameters.get(0); this.updateFrequency = distributionParameters.get(0);
// Only a single parameter is required and read for ConstantDistributionLegacy // Only a single parameter is required and read for ConstantDistributionLegacy
...@@ -40,13 +39,13 @@ public class ConstantDistribution implements SpawnDistribution { ...@@ -40,13 +39,13 @@ public class ConstantDistribution implements SpawnDistribution {
} }
@Override @Override
public int getOutstandingSpawnNumber() { public int getRemainingSpawnAgents() {
return this.outstandingAgents; return this.remainingAgents;
} }
@Override @Override
public void setOutstandingAgents(int outstandingAgents){ public void setRemainingSpawnAgents(int remainingAgents){
this.outstandingAgents = outstandingAgents; this.remainingAgents = remainingAgents;
} }
@Override @Override
......
...@@ -15,7 +15,7 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution { ...@@ -15,7 +15,7 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
private double spawnFrequency; private double spawnFrequency;
private TruncatedNormalDistribution truncNormalDist; private TruncatedNormalDistribution truncNormalDist;
private RandomGenerator randomGenerator; private RandomGenerator randomGenerator;
private int outstandingAgents = 0; private int remainingAgents = 0;
public LinearInterpolationSpawnDistribution(RandomGenerator rng, List<Double> distributionParameters){ public LinearInterpolationSpawnDistribution(RandomGenerator rng, List<Double> distributionParameters){
...@@ -45,17 +45,14 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution { ...@@ -45,17 +45,14 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
@Override @Override
public int getSpawnNumber(double timeCurrentEvent){ public int getSpawnNumber(double timeCurrentEvent){
int spawnNumber = (int) Math.round(this.interpolator.value(timeCurrentEvent)); // + this.truncNormalDist.sample()); int spawnNumber = (int) Math.round(this.interpolator.value(timeCurrentEvent)+ this.truncNormalDist.sample());
spawnNumber = Math.max(0, spawnNumber); spawnNumber = Math.max(0, spawnNumber);
//System.out.println("timeCurrentEvent " + timeCurrentEvent + " spawn number = " + spawnNumber);
return spawnNumber; return spawnNumber;
} }
@Override @Override
public int getOutstandingSpawnNumber(){ public int getRemainingSpawnAgents(){
// Agents that could not be spawned (e.g. because the Source is too small) are not taken to the next update // Agents that could not be spawned (e.g. because the source is too small) are not taken to the next update
return 0; return 0;
} }
...@@ -64,9 +61,8 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution { ...@@ -64,9 +61,8 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
return timeCurrentEvent + spawnFrequency; return timeCurrentEvent + spawnFrequency;
} }
@Override @Override
public void setOutstandingAgents(int outstandingAgents) { public void setRemainingSpawnAgents(int remainingAgents) {
this.remainingAgents = remainingAgents;
} }
} }
...@@ -5,12 +5,12 @@ public class SingleSpawnDistribution implements SpawnDistribution { ...@@ -5,12 +5,12 @@ public class SingleSpawnDistribution implements SpawnDistribution {
private int spawnNumber; private int spawnNumber;
private double spawnTime; private double spawnTime;
private int outstandingAgents; private int remainingAgents;
public SingleSpawnDistribution(int spawnNumber, double spawnTime){ public SingleSpawnDistribution(int spawnNumber, double spawnTime){
this.spawnNumber = spawnNumber; this.spawnNumber = spawnNumber;
this.spawnTime = spawnTime; this.spawnTime = spawnTime;
this.outstandingAgents = 0; this.remainingAgents = 0;
} }
@Override @Override
...@@ -24,13 +24,13 @@ public class SingleSpawnDistribution implements SpawnDistribution { ...@@ -24,13 +24,13 @@ public class SingleSpawnDistribution implements SpawnDistribution {
} }
@Override @Override
public void setOutstandingAgents(int outstandingAgents){ public void setRemainingSpawnAgents(int remainingAgents){
this.outstandingAgents = outstandingAgents; this.remainingAgents = remainingAgents;
} }
@Override @Override
public int getOutstandingSpawnNumber(){ public int getRemainingSpawnAgents(){
return this.outstandingAgents; return this.remainingAgents;
} }
} }
...@@ -4,7 +4,7 @@ public interface SpawnDistribution { ...@@ -4,7 +4,7 @@ public interface SpawnDistribution {
int getSpawnNumber(double timeCurrentEvent); int getSpawnNumber(double timeCurrentEvent);
double getNextSpawnTime(double timeCurrentEvent); double getNextSpawnTime(double timeCurrentEvent);
int getOutstandingSpawnNumber(); int getRemainingSpawnAgents();
void setOutstandingAgents(int outstandingAgents); void setRemainingSpawnAgents(int remainingAgents);
} }
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