Commit db6d93de authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Merge branch 'master' into psychology

parents bd7607f4 f248f23c
Pipeline #174319 passed with stages
in 119 minutes and 11 seconds
package org.vadere.simulator.models.potential;
import org.vadere.annotation.factories.models.ModelClass;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.potential.fields.PotentialFieldObstacle;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesPotentialCompact;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.Vector2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
@ModelClass
public class PotentialFieldObstacleCA extends PotentialFieldObstacleCompact implements PotentialFieldObstacle {
private Random random;
private Collection<Obstacle> obstacles;
private Topography topography;
public PotentialFieldObstacleCA() {
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
init(topography, random);
}
private void init(final Topography topography, final Random random) {
this.topography = topography;
this.obstacles = new ArrayList<>(topography.getObstacles());
this.random = random;
}
@Override
public double getObstaclePotential(IPoint pos, Agent pedestrian) {
double potential = 0;
double distance = topography.distanceToObstacle(pos);
double currentPotential = 0;
if (distance <= 0) {
currentPotential = 1000000;
}
if (potential < currentPotential)
potential = currentPotential;
return potential;
}
@Override
public PotentialFieldObstacle copy() {
PotentialFieldObstacleCA potentialFieldObstacleCA = new PotentialFieldObstacleCA();
potentialFieldObstacleCA.init(topography, random);
return potentialFieldObstacleCA;
}
}
package org.vadere.simulator.models.potential;
import org.vadere.annotation.factories.models.ModelClass;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.potential.fields.PotentialFieldAgent;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.Vector2D;
import java.util.Collection;
import java.util.List;
import java.util.Random;
// AgentPotential for the cellular automaton, no repulsion between agents.
@ModelClass
public class PotentialFieldPedestrianCA implements PotentialFieldAgent {
private final double GRID_BUFFER = 10E-5;
private final double height_potential = 1000;
public PotentialFieldPedestrianCA() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
}
@Override
public Collection<Pedestrian> getRelevantAgents(VCircle maxStepCircle,
Agent pedestrian, Topography scenario) {
List<Pedestrian> closePedestrians = scenario.getSpatialMap(Pedestrian.class).getObjects(maxStepCircle.getCenter(),
maxStepCircle.getRadius()*2); // factor 2 to assure that all surrounding relevant pedestrians are found
return closePedestrians;
}
@Override
public double getAgentPotential(IPoint pos, Agent pedestrian,
Agent otherPedestrian) {
double radii = pedestrian.getRadius() + otherPedestrian.getRadius(); // 2* r_p (sivers-2016b)
double potential = 0;
double distance = otherPedestrian.getPosition().distance(pos); // Euclidean distance d_j(x) between agent j and position x
if(radii - distance > GRID_BUFFER) {// do not add high potential value for touching agents (BUFFER)
potential += height_potential;
}
return potential;
}
@Override
public double getAgentPotential(IPoint pos, Agent pedestrian,
Collection<? extends Agent> otherPedestrians) {
double potential = 0;
for (Agent neighbor : otherPedestrians) {
if (neighbor.getId() != pedestrian.getId()) {
potential += getAgentPotential(pos, pedestrian, neighbor);
}
}
return potential;
}
@Override
public Vector2D getAgentPotentialGradient(IPoint pos,
Vector2D velocity, Agent pedestrian,
Collection<? extends Agent> otherPedestrians) {
throw new UnsupportedOperationException("not yet implemented.");
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.NoDataKey;
import org.vadere.state.attributes.processor.AttributesFlowProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import java.util.Collection;
import java.util.OptionalDouble;
/**
* @author Marion Goedel
*
*/
@DataProcessorClass()
public class FlowProcessor extends DataProcessor<NoDataKey, Double> {
private PedestrianLineCrossProcessor pedLineCross;
public FlowProcessor() {
super("flow");
setAttributes(new AttributesFlowProcessor());
}
@Override
protected void doUpdate(final SimulationState state) {
this.pedLineCross.update(state);
}
@Override
public void postLoop(final SimulationState state) {
pedLineCross.postLoop(state);
Collection<Double> lineCrossValues = pedLineCross.getValues();
OptionalDouble lineCrossMax = lineCrossValues.stream().mapToDouble(Double::doubleValue).max();
OptionalDouble lineCrossMin = lineCrossValues.stream().mapToDouble(Double::doubleValue).min();
double flow;
if(lineCrossMax.isPresent() && lineCrossMin.isPresent()){
double deltaT = lineCrossMax.getAsDouble() - lineCrossMin.getAsDouble();
double deltaN = lineCrossValues.size();
// double b = pedLineCross.getLine().length(); // width of corridor -> specific flow
flow = deltaN/deltaT;
} else {
flow = -1.0;
}
putValue(NoDataKey.key(), flow);
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesFlowProcessor att = (AttributesFlowProcessor) this.getAttributes();
this.pedLineCross = (PedestrianLineCrossProcessor) manager.getProcessor(att.getPedestrianLineCrossProcessorId());
}
@Override
public AttributesProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesFlowProcessor());
}
return super.getAttributes();
}
}
package org.vadere.state.attributes.processor;
/**
* @author Marion Goedel
*
*/
public class AttributesFlowProcessor extends AttributesProcessor {
private int pedestrianLineCrossProcessorId;
public int getPedestrianLineCrossProcessorId() {
return this.pedestrianLineCrossProcessorId;
}
public void setPedestrianLineCrossProcessorId(int pedestrianLineCrossProcessorId) {
checkSealed();
this.pedestrianLineCrossProcessorId = pedestrianLineCrossProcessorId;
}
}
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