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