Commit c3f30c06 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

refactoring of agent and obstacle potential classes, add distance computation...

refactoring of agent and obstacle potential classes, add distance computation via fmm to all obstacle potentials except the GNM.
parent 61c14c1d
Pipeline #54135 passed with stage
in 46 seconds
......@@ -31,7 +31,7 @@ public interface Model {
void update(final double simTimeInSec);
public static <T extends Attributes> T findAttributes(List<Attributes> attributesList, final Class<T> type) {
static <T extends Attributes> T findAttributes(List<Attributes> attributesList, final Class<T> type) {
try {
final T a = FindByClass.findSingleObjectOfClass(attributesList, type);
if (a != null) {
......
......@@ -85,10 +85,10 @@ public class GradientNavigationModel extends ODEModel<Pedestrian, AttributesAgen
models.add(iPotentialTargetGrid);
this.potentialFieldObstacle = PotentialFieldObstacle.createPotentialField(
modelAttributesList, topography, random, attributes.getObstaclePotentialModel());
modelAttributesList, topography, attributesPedestrian, random, attributes.getObstaclePotentialModel());
this.potentialFieldPedestrian = PotentialFieldAgent.createPotentialField(
modelAttributesList, topography, attributes.getPedestrianPotentialModel());
modelAttributesList, topography, attributesPedestrian, random, attributes.getPedestrianPotentialModel());
models.add(this);
}
......
......@@ -5,6 +5,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
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.AttributesPotentialGNM;
......@@ -27,14 +28,20 @@ public class PotentialFieldObstacleGNM implements GradientProvider, PotentialFie
private Collection<Obstacle> obstacles;
private Topography topography;
private double epsDV = 1e-10;
private final AttributesPotentialGNM attributesPotential;
private AttributesPotentialGNM attributesPotential;
public PotentialFieldObstacleGNM() {}
public PotentialFieldObstacleGNM(Collection<Obstacle> obstacles,
AttributesPotentialGNM attributesDynamicPotentialGNM) {
this.obstacles = obstacles;
this.attributesPotential = attributesDynamicPotentialGNM;
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
this.attributesPotential = Model.findAttributes(attributesList, AttributesPotentialGNM.class);
this.obstacles = topography.getObstacles();
this.topography = topography;
}
@Override
......@@ -55,6 +62,7 @@ public class PotentialFieldObstacleGNM implements GradientProvider, PotentialFie
completeGrad[0] = 0;
completeGrad[1] = 0;
// we could save the closest obstacle in the grid.
for (Obstacle obstacle : obstacles) {
closest = new VPoint(0, 0);
......@@ -116,13 +124,10 @@ public class PotentialFieldObstacleGNM implements GradientProvider, PotentialFie
@Override
public PotentialFieldObstacle copy() {
return new PotentialFieldObstacleGNM(new LinkedList<>(obstacles), attributesPotential);
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
PotentialFieldObstacleGNM potentialFieldObstacleGNM = new PotentialFieldObstacleGNM();
potentialFieldObstacleGNM.attributesPotential = attributesPotential;
potentialFieldObstacleGNM.obstacles = new LinkedList<>(topography.getObstacles());
return potentialFieldObstacleGNM;
}
}
......@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
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.AttributesPotentialGNM;
......@@ -19,11 +20,14 @@ import org.vadere.util.math.MathUtil;
public class PotentialFieldPedestrianGNM implements PotentialFieldAgent {
private final AttributesPotentialGNM attributes;
private AttributesPotentialGNM attributes;
public PotentialFieldPedestrianGNM(
AttributesPotentialGNM attributesPotential) {
this.attributes = attributesPotential;
public PotentialFieldPedestrianGNM() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
this.attributes = Model.findAttributes(attributesList, AttributesPotentialGNM.class);
}
@Override
......@@ -106,11 +110,4 @@ public class PotentialFieldPedestrianGNM implements PotentialFieldAgent {
return closePedestrians;
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
}
}
......@@ -103,11 +103,8 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel {
this.potentialFieldTarget = iPotentialTargetGrid;
models.add(iPotentialTargetGrid);
this.potentialFieldObstacle = PotentialFieldObstacle.createPotentialField(
modelAttributesList, topography, random, attributesOSM.getObstaclePotentialModel());
this.potentialFieldPedestrian = PotentialFieldAgent.createPotentialField(
modelAttributesList, topography, attributesOSM.getPedestrianPotentialModel());
this.potentialFieldObstacle = PotentialFieldObstacle.createPotentialField(modelAttributesList, topography, attributesPedestrian, random, attributesOSM.getObstaclePotentialModel());
this.potentialFieldPedestrian = PotentialFieldAgent.createPotentialField(modelAttributesList, topography, attributesPedestrian, random, attributesOSM.getPedestrianPotentialModel());
Optional<CentroidGroupModel> opCentroidGroupModel = models.stream().
filter(ac -> ac instanceof CentroidGroupModel).map(ac -> (CentroidGroupModel)ac).findAny();
......
package org.vadere.simulator.models.potential;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
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.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VPoint;
public class PotentialFieldObstacleCompact implements PotentialFieldObstacle {
private final AttributesPotentialCompact attributes;
private AttributesPotentialCompact attributes;
private Random random;
private double width;
private double height;
private Collection<Obstacle> obstacles;
private Topography topography;
private final Random random;
public PotentialFieldObstacleCompact() {
private final double width;
private final double height;
}
private Collection<Obstacle> obstacles;
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
init(Model.findAttributes(attributesList, AttributesPotentialCompact.class), topography, random);
}
public PotentialFieldObstacleCompact(AttributesPotentialCompact attributes, Collection<Obstacle> obstacles,
Random random) {
private void init(final AttributesPotentialCompact attributes, final Topography topography, final Random random) {
this.attributes = attributes;
this.topography = topography;
this.obstacles = new ArrayList<>(topography.getObstacles());
this.random = random;
this.width = attributes.getObstPotentialWidth() +
attributes.getObstDistanceDeviation() * (random.nextDouble() * 2 - 1);
this.height = attributes.getObstPotentialHeight();
this.obstacles = obstacles;
}
@Override
public double getObstaclePotential(VPoint pos, Agent pedestrian) {
double potential = 0;
for (Obstacle obstacle : obstacles) {
double distance = obstacle.getShape().distance(pos);
//for (Obstacle obstacle : obstacles) {
//double distance = obstacle.getShape().distance(pos);
double distance = topography.distanceToObstacle(pos);
if (attributes.isUseHardBodyShell()) {
distance = distance - pedestrian.getRadius();
......@@ -63,7 +69,7 @@ public class PotentialFieldObstacleCompact implements PotentialFieldObstacle {
if (potential < currentPotential)
potential = currentPotential;
}
//}
return potential;
}
......@@ -121,13 +127,9 @@ public class PotentialFieldObstacleCompact implements PotentialFieldObstacle {
@Override
public PotentialFieldObstacle copy() {
return new PotentialFieldObstacleCompact(attributes, new LinkedList<>(obstacles), random);
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
PotentialFieldObstacleCompact potentialFieldObstacleCompact = new PotentialFieldObstacleCompact();
init(attributes, topography, random);
return potentialFieldObstacleCompact;
}
}
package org.vadere.simulator.models.potential;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
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.AttributesPotentialCompactSoftshell;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -29,17 +29,24 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs
private Collection<Obstacle> obstacles;
private Topography topography;
public PotentialFieldObstacleCompactSoftshell(AttributesPotentialCompactSoftshell attributesPotential,
Topography topography, Random random) {
this.attributes = attributesPotential;
this.random = random;
public PotentialFieldObstacleCompactSoftshell() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
init(Model.findAttributes(attributesList, AttributesPotentialCompactSoftshell.class), topography, random);
}
this.width = attributesPotential.getObstPotentialWidth();
this.height = attributesPotential.getObstPotentialHeight();
private void init(AttributesPotentialCompactSoftshell attributes, Topography topography, Random random){
this.attributes = attributes;
this.width = attributes.getObstPotentialWidth();
this.height = attributes.getObstPotentialHeight();
this.random = random;
this.obstacles = new ArrayList<>(topography.getObstacles());
this.topography = topography;
this.obstacles = topography.getObstacles();
}
@Override
public double getObstaclePotential(VPoint pos, Agent pedestrian) {
......@@ -74,13 +81,8 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs
@Override
public PotentialFieldObstacle copy() {
return new PotentialFieldObstacleCompactSoftshell(attributes, topography, random);
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
PotentialFieldObstacleCompactSoftshell potentialFieldObstacle = new PotentialFieldObstacleCompactSoftshell();
potentialFieldObstacle.init(attributes, topography, random);
return potentialFieldObstacle;
}
}
package org.vadere.simulator.models.potential;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
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.AttributesPotentialOSM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VPoint;
public class PotentialFieldObstacleOSM implements PotentialFieldObstacle {
private final AttributesPotentialOSM attributes;
private AttributesPotentialOSM attributes;
private Collection<Obstacle> obstacles;
private Topography topography;
public PotentialFieldObstacleOSM(
AttributesPotentialOSM attributesDynamicPotentialOSM,
Collection<Obstacle> obstacles) {
this.attributes = attributesDynamicPotentialOSM;
this.obstacles = obstacles;
public PotentialFieldObstacleOSM() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
AttributesPotentialOSM attributesPotentialOSM = Model.findAttributes(attributesList, AttributesPotentialOSM.class);
this.attributes = attributesPotentialOSM;
this.topography = topography;
this.obstacles = new ArrayList<>(topography.getObstacles());
}
@Override
......@@ -33,11 +38,13 @@ public class PotentialFieldObstacleOSM implements PotentialFieldObstacle {
double potential = 0;
double repulsion = 0;
for (Obstacle obstacle : obstacles) {
//for (Obstacle obstacle : obstacles) {
double distance = topography.distanceToObstacle(pos) - pedestrian.getRadius();
// Shapes of pedestrians are assumed to be circles.
double distance = obstacle.getShape().distance(pos)
- pedestrian.getRadius();
/*double distance = obstacle.getShape().distance(pos)
- pedestrian.getRadius();*/
if (distance <= 0) {
repulsion = attributes.getObstacleBodyPotential();
......@@ -50,12 +57,10 @@ public class PotentialFieldObstacleOSM implements PotentialFieldObstacle {
* attributes.getObstacleRepulsionStrength();
}
// TODO [priority=medium] [task=bugfix] [Error?]: shouldn't the potential of all obstacles be added instead of taking the maximum? see paper 'Natural discretization...'
// TODO [priority=medium] [task=feature] If this algorithm is chosen: first compute distance, choose closest, and then compute potential.
if (repulsion > potential) {
potential = repulsion;
}
}
//}
return potential;
}
......@@ -121,12 +126,10 @@ public class PotentialFieldObstacleOSM implements PotentialFieldObstacle {
@Override
public PotentialFieldObstacle copy() {
return new PotentialFieldObstacleOSM(attributes, new LinkedList<>(obstacles));
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
PotentialFieldObstacleOSM potentialFieldObstacleOSM = new PotentialFieldObstacleOSM();
potentialFieldObstacleOSM.attributes = attributes;
potentialFieldObstacleOSM.topography = topography;
potentialFieldObstacleOSM.obstacles = topography.getObstacles();
return potentialFieldObstacleOSM;
}
}
......@@ -3,6 +3,7 @@ package org.vadere.simulator.models.potential;
import java.util.List;
import java.util.Random;
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.AttributesPotentialRingExperiment;
......@@ -25,13 +26,21 @@ import org.vadere.util.geometry.shapes.VPoint;
*/
public class PotentialFieldObstacleRingExperiment implements PotentialFieldObstacle {
private final AttributesPotentialRingExperiment attributes;
private AttributesPotentialRingExperiment attributes;
private final VPoint center;
private final double radiusInnerCircle;
private final double radiusOuterCircle;
private VPoint center;
private double radiusInnerCircle;
private double radiusOuterCircle;
public PotentialFieldObstacleRingExperiment(AttributesPotentialRingExperiment attributes) {
public PotentialFieldObstacleRingExperiment() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
init(Model.findAttributes(attributesList, AttributesPotentialRingExperiment.class));
}
private void init(final AttributesPotentialRingExperiment attributes) {
this.attributes = attributes;
center = attributes.getCenter();
......@@ -75,13 +84,8 @@ public class PotentialFieldObstacleRingExperiment implements PotentialFieldObsta
@Override
public PotentialFieldObstacle copy() {
return new PotentialFieldObstacleRingExperiment(attributes);
PotentialFieldObstacleRingExperiment potentialFieldObstacleRingExperiment = new PotentialFieldObstacleRingExperiment();
potentialFieldObstacleRingExperiment.init(attributes);
return potentialFieldObstacleRingExperiment;
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
}
}
......@@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
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.AttributesPotentialCompact;
......@@ -42,13 +43,16 @@ public class PotentialFieldPedestrianCompact implements PotentialFieldAgent {
}
}
private final AttributesPotentialCompact attributes;
private AttributesPotentialCompact attributes;
private double width;
private double height;
private final double width;
private final double height;
public PotentialFieldPedestrianCompact() {}
public PotentialFieldPedestrianCompact(AttributesPotentialCompact attributes) {
this.attributes = attributes;
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
this.attributes = Model.findAttributes(attributesList, AttributesPotentialCompact.class);
this.width = attributes.getPedPotentialWidth();
this.height = attributes.getPedPotentialHeight();
}
......@@ -145,10 +149,4 @@ public class PotentialFieldPedestrianCompact implements PotentialFieldAgent {
}
return result;
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
}
}
......@@ -5,6 +5,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
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;
......@@ -19,14 +20,17 @@ import org.vadere.util.math.MathUtil;
public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldAgent {
private AttributesPotentialCompactSoftshell attributes;
private double intimateWidth;
private double personalWidth;
private double height;
public PotentialFieldPedestrianCompactSoftshell(AttributesPotentialCompactSoftshell attributes) {
this.attributes = attributes;
public PotentialFieldPedestrianCompactSoftshell() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
this.attributes = Model.findAttributes(attributesList, AttributesPotentialCompactSoftshell.class);
this.intimateWidth = attributes.getPedPotentialIntimateSpaceWidth();
this.personalWidth = attributes.getPedPotentialPersonalSpaceWidth();
this.height = attributes.getPedPotentialHeight();
......@@ -96,11 +100,4 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA
Collection<? extends Agent> otherPedestrians) {
throw new UnsupportedOperationException("this method is not jet implemented.");
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
}
}
......@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
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.AttributesPotentialOSM;
......@@ -17,10 +18,14 @@ import org.vadere.util.geometry.shapes.VPoint;
public class PotentialFieldPedestrianOSM implements PotentialFieldAgent {
private final AttributesPotentialOSM attributes;
private AttributesPotentialOSM attributes;
public PotentialFieldPedestrianOSM(AttributesPotentialOSM attributes) {
this.attributes = attributes;
public PotentialFieldPedestrianOSM() {}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
this.attributes = Model.findAttributes(attributesList, AttributesPotentialOSM.class);
}
@Override
......@@ -114,10 +119,4 @@ public class PotentialFieldPedestrianOSM implements PotentialFieldAgent {
return result;
}
@Override
public void initialize(List<Attributes> attributesList, Topography topography,
AttributesAgent attributesPedestrian, Random random) {
// TODO should be used to initialize the Model
}
}
......@@ -2,6 +2,7 @@ package org.vadere.simulator.models.potential.fields;