Commit 749d3cfc authored by hm-mgoedel's avatar hm-mgoedel

Potentials for cellular automaton - no repulsion from walls / other...

Potentials for cellular automaton - no repulsion from walls / other pedestrians - only high values at other pedestrian's positions and at obstacles.
parent 9afa2262
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.");
}
}
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