Commit 4be8e49f authored by Christina Maria Mayr's avatar Christina Maria Mayr

Merge branch 'number_instead_mean_time' into 'master'

Use Poisson distribution for spawn generation and measure the real parameter value with data processor

See merge request !131
parents dd7564e3 e5148ef7
Pipeline #262012 passed with stages
in 155 minutes and 33 seconds
package org.vadere.simulator.projects.dataprocessing.processor;
import org.apache.commons.collections.CollectionUtils;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesNumberOfGeneratedPedsProcessor;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@DataProcessorClass(label = "NumberOfGeneratedPedsProcessor")
public class NumberOfGeneratedPedsProcessor extends DataProcessor<TimestepKey, Double> {
private List<Integer> pedIds = new ArrayList<Integer>();
public NumberOfGeneratedPedsProcessor(){
super("NumAgentsGenPerSecond");
}
@Override
protected void doUpdate(SimulationState state) {
double t = state.getSimTimeInSec();
if ( t + 1e-7 >= getAttributes().getStartTime() && t - 1e-7 <= getAttributes().getEndTime() ) {
int numAgentsGen;
List<Integer> newPedIds = state.getTopography().getElements(Pedestrian.class).stream().map(Agent::getId).collect(Collectors.toList());
if (this.getPedsIds() == null){
numAgentsGen = newPedIds.size();
}
else {
List<Integer> oldPedIds = this.getPedsIds();
List<Integer> list = new ArrayList<Integer>(CollectionUtils.disjunction(newPedIds, oldPedIds));
list.removeAll(oldPedIds);
numAgentsGen = list.size();
}
this.setPedsIds(newPedIds);
double poissonParameter = numAgentsGen/state.getScenarioStore().getAttributesSimulation().getSimTimeStepLength();
putValue(new TimestepKey(state.getStep()), poissonParameter);
}
}
@Override
public AttributesNumberOfGeneratedPedsProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesNumberOfGeneratedPedsProcessor());
}
return (AttributesNumberOfGeneratedPedsProcessor)super.getAttributes();
}
private List<Integer> getPedsIds(){
return this.pedIds;
}
private void setPedsIds(List<Integer> pedsId){
this.pedIds = pedsId;
}
}
package org.vadere.state.attributes.processor;
public class AttributesNumberOfGeneratedPedsProcessor extends AttributesProcessor {
private double startTime = 0.0;
private double endTime = -1; // -1 until simulation finished
public double getStartTime() {
return startTime;
}
public double getEndTime() {
if (endTime >= startTime - 1e-7)
return endTime;
else
return Double.MAX_VALUE;
}
}
package org.vadere.state.scenario;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import org.apache.commons.math3.random.RandomGenerator;
/**
* -> Scope: Definition of spawn generation in source
* Use the PoissonDistribution to generate agents with a Poisson process.
* The Poisson process is a random process.
* Hence, the generation time of a specific agent is independent from other generation times.
* The Poisson distribution and the exponential distribution are related.
* The reciprocal value of the Poisson parameter is the mean inter arrival time used in the exponential distribution.
* @author Christina Mayr
* @since 2020-05-27
*/
public class PoissonDistribution extends ExponentialDistribution {
/**
*
* @param numberPedsPerSecond Unit: agents/second. Reciprocal value of mean inter-arrival time [seconds].
*/
public PoissonDistribution(RandomGenerator rng, double numberPedsPerSecond) {
super(rng, 1/numberPedsPerSecond);
}
}
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