2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 35020ae4 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

change speed-adjuster to step-size-adjuster.

parent 9469482c
Pipeline #78288 failed with stages
in 52 seconds
package org.vadere.simulator.models;
import org.vadere.state.scenario.Pedestrian;
public interface StepSizeAdjuster {
double getAdjustedStepSize(Pedestrian ped, double originalStepSize);
}
...@@ -201,10 +201,18 @@ public class CentroidGroup implements Group { ...@@ -201,10 +201,18 @@ public class CentroidGroup implements Group {
double result; double result;
VPoint pedLocation = ped.getPosition(); VPoint pedLocation = ped.getPosition();
double potentialSum = 0.0;
int size = 0;
for (Pedestrian p : members) {
if (!ped.equals(p) && !isLostMember(p)) {
potentialSum += potentialFieldTarget.getPotential(p.getPosition(), p);
size++;
}
}
double pedDistance = potentialFieldTarget.getPotential(pedLocation, ped); double pedDistance = potentialFieldTarget.getPotential(pedLocation, ped);
double centroidDistance = potentialFieldTarget.getPotential(getCentroidOthers(ped), ped);
result = centroidDistance - pedDistance; result = (potentialSum / size) - pedDistance;
if (result > POTENTIAL_DISTANCE_THRESHOLD) { if (result > POTENTIAL_DISTANCE_THRESHOLD) {
result = 0; result = 0;
......
...@@ -3,7 +3,9 @@ package org.vadere.simulator.models.groups; ...@@ -3,7 +3,9 @@ package org.vadere.simulator.models.groups;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.annotation.factories.models.ModelClass; import org.vadere.annotation.factories.models.ModelClass;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.PotentialFieldAgent; import org.vadere.simulator.models.potential.fields.PotentialFieldAgent;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesCGM; import org.vadere.state.attributes.models.AttributesCGM;
import org.vadere.state.attributes.scenario.AttributesAgent; import org.vadere.state.attributes.scenario.AttributesAgent;
...@@ -27,14 +29,17 @@ public class CentroidGroupPotential implements PotentialFieldAgent { ...@@ -27,14 +29,17 @@ public class CentroidGroupPotential implements PotentialFieldAgent {
private final AttributesCGM attributesCGM; private final AttributesCGM attributesCGM;
private final CentroidGroupModel groupCollection; private final CentroidGroupModel groupCollection;
private final PotentialFieldAgent potentialFieldPedestrian; private final PotentialFieldAgent potentialFieldPedestrian;
private final IPotentialFieldTarget potentialFieldTarget;
public CentroidGroupPotential(CentroidGroupModel groupCollection, public CentroidGroupPotential(CentroidGroupModel groupCollection,
PotentialFieldAgent pedestrianRepulsionPotential, PotentialFieldAgent pedestrianRepulsionPotential,
IPotentialFieldTarget potentialFieldTarget,
AttributesCGM attributesCGM) { AttributesCGM attributesCGM) {
this.attributesCGM = attributesCGM; this.attributesCGM = attributesCGM;
this.groupCollection = groupCollection; this.groupCollection = groupCollection;
this.potentialFieldPedestrian = pedestrianRepulsionPotential; this.potentialFieldPedestrian = pedestrianRepulsionPotential;
this.potentialFieldTarget = potentialFieldTarget;
} }
@Override @Override
...@@ -65,6 +70,8 @@ public class CentroidGroupPotential implements PotentialFieldAgent { ...@@ -65,6 +70,8 @@ public class CentroidGroupPotential implements PotentialFieldAgent {
if (leader != null) { if (leader != null) {
VPoint leaderPoint = leader.getPosition(); VPoint leaderPoint = leader.getPosition();
double leaderPotential = potentialFieldTarget.getPotential(leaderPoint, leader);
double pedPotential = potentialFieldTarget.getPotential(ped.getPosition(), ped);
final double[] distanceToCentroid = { final double[] distanceToCentroid = {
pos.getX() - leaderPoint.getX(), pos.getX() - leaderPoint.getX(),
...@@ -72,9 +79,8 @@ public class CentroidGroupPotential implements PotentialFieldAgent { ...@@ -72,9 +79,8 @@ public class CentroidGroupPotential implements PotentialFieldAgent {
result = attributesCGM.getLeaderAttractionFactor() result = attributesCGM.getLeaderAttractionFactor()
* Math.pow( * Math.pow(
Math.pow(distanceToCentroid[0], 2) leaderPotential - pedPotential,
+ Math.pow(distanceToCentroid[1], 2), 4);
2);
} }
return result; return result;
...@@ -111,7 +117,7 @@ public class CentroidGroupPotential implements PotentialFieldAgent { ...@@ -111,7 +117,7 @@ public class CentroidGroupPotential implements PotentialFieldAgent {
double potential = potentialFieldPedestrian.getAgentPotential(pos, double potential = potentialFieldPedestrian.getAgentPotential(pos,
pedestrian, otherPedestrian); pedestrian, otherPedestrian);
if (group.equals(groupOther)) { if (group != null && group.equals(groupOther)) {
potential *= attributesCGM.getGroupMemberRepulsionFactor(); potential *= attributesCGM.getGroupMemberRepulsionFactor();
} }
......
package org.vadere.simulator.models.groups;
import org.vadere.simulator.models.StepSizeAdjuster;
import org.vadere.state.scenario.Pedestrian;
public class CentroidGroupStepSizeAdjuster implements StepSizeAdjuster {
private final CentroidGroupModel groupCollection;
public CentroidGroupStepSizeAdjuster(CentroidGroupModel groupCollection) {
this.groupCollection = groupCollection;
}
@Override
public double getAdjustedStepSize(Pedestrian ped, double originalStepSize) {
double result = 1.0;
double aheadDistance = 0;
CentroidGroup group = groupCollection.getGroup(ped);
if (group != null) {
aheadDistance = group.getRelativeDistanceCentroid(ped);
// TODO [priority=low] [task=refactoring] move Parameters to AttributesCGM
if (!group.isLostMember(ped)) {
if (aheadDistance > 8) {
result = Double.MIN_VALUE;
} else if (aheadDistance >= 1) {
result /= 1.0 + aheadDistance / 8 - 1 / 8 + 1;
} else if (aheadDistance >= 0) {
result /= 1.0 + Math.pow(aheadDistance, 2);
} else if (aheadDistance >= -1) {
result /= 0.75;
} else {
result /= 0.65;
}
}
}
return originalStepSize * result;
}
}
...@@ -8,10 +8,12 @@ import org.vadere.simulator.control.factory.SourceControllerFactory; ...@@ -8,10 +8,12 @@ import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.MainModel; import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model; import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.SpeedAdjuster; import org.vadere.simulator.models.SpeedAdjuster;
import org.vadere.simulator.models.StepSizeAdjuster;
import org.vadere.simulator.models.SubModelBuilder; import org.vadere.simulator.models.SubModelBuilder;
import org.vadere.simulator.models.groups.CentroidGroupModel; import org.vadere.simulator.models.groups.CentroidGroupModel;
import org.vadere.simulator.models.groups.CentroidGroupPotential; import org.vadere.simulator.models.groups.CentroidGroupPotential;
import org.vadere.simulator.models.groups.CentroidGroupSpeedAdjuster; import org.vadere.simulator.models.groups.CentroidGroupSpeedAdjuster;
import org.vadere.simulator.models.groups.CentroidGroupStepSizeAdjuster;
import org.vadere.simulator.models.osm.optimization.ParticleSwarmOptimizer; import org.vadere.simulator.models.osm.optimization.ParticleSwarmOptimizer;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer; import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizerBrent; import org.vadere.simulator.models.osm.optimization.StepCircleOptimizerBrent;
...@@ -58,14 +60,17 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami ...@@ -58,14 +60,17 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami
private PotentialFieldObstacle potentialFieldObstacle; private PotentialFieldObstacle potentialFieldObstacle;
private PotentialFieldAgent potentialFieldPedestrian; private PotentialFieldAgent potentialFieldPedestrian;
private List<SpeedAdjuster> speedAdjusters; private List<SpeedAdjuster> speedAdjusters;
private List<StepSizeAdjuster> stepSizeAdjusters;
private Topography topography; private Topography topography;
private double lastSimTimeInSec; private double lastSimTimeInSec;
private int pedestrianIdCounter; private int pedestrianIdCounter;
private ExecutorService executorService; private ExecutorService executorService;
private List<Model> models = new LinkedList<>(); private List<Model> models = new LinkedList<>();
public OptimalStepsModel() { public OptimalStepsModel() {
this.pedestrianIdCounter = 0; this.pedestrianIdCounter = 0;
this.speedAdjusters = new LinkedList<>(); this.speedAdjusters = new LinkedList<>();
this.stepSizeAdjusters = new LinkedList<>();
} }
@Override @Override
...@@ -103,10 +108,11 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami ...@@ -103,10 +108,11 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami
this.potentialFieldPedestrian = this.potentialFieldPedestrian =
new CentroidGroupPotential(centroidGroupModel, new CentroidGroupPotential(centroidGroupModel,
potentialFieldPedestrian, centroidGroupModel.getAttributesCGM()); potentialFieldPedestrian, potentialFieldTarget, centroidGroupModel.getAttributesCGM());
SpeedAdjuster speedAdjusterCGM = new CentroidGroupSpeedAdjuster(centroidGroupModel); SpeedAdjuster speedAdjusterCGM = new CentroidGroupSpeedAdjuster(centroidGroupModel);
this.speedAdjusters.add(speedAdjusterCGM); this.speedAdjusters.add(speedAdjusterCGM);
this.stepSizeAdjusters.add(new CentroidGroupStepSizeAdjuster(centroidGroupModel));
} }
this.stepCircleOptimizer = createStepCircleOptimizer( this.stepCircleOptimizer = createStepCircleOptimizer(
...@@ -264,7 +270,7 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami ...@@ -264,7 +270,7 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel, Dynami
PedestrianOSM pedestrian = new PedestrianOSM(attributesOSM, PedestrianOSM pedestrian = new PedestrianOSM(attributesOSM,
attributesAgent, topography, random, potentialFieldTarget, attributesAgent, topography, random, potentialFieldTarget,
potentialFieldObstacle.copy(), potentialFieldPedestrian, potentialFieldObstacle.copy(), potentialFieldPedestrian,
speedAdjusters, stepCircleOptimizer.clone()); stepSizeAdjusters, stepCircleOptimizer.clone());
pedestrian.setPosition(position); pedestrian.setPosition(position);
return pedestrian; return pedestrian;
} }
......
...@@ -2,6 +2,7 @@ package org.vadere.simulator.models.osm; ...@@ -2,6 +2,7 @@ package org.vadere.simulator.models.osm;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.StepSizeAdjuster;
import org.vadere.util.geometry.shapes.Vector2D; import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.simulator.models.SpeedAdjuster; import org.vadere.simulator.models.SpeedAdjuster;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer; import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
...@@ -39,6 +40,7 @@ public class PedestrianOSM extends Pedestrian { ...@@ -39,6 +40,7 @@ public class PedestrianOSM extends Pedestrian {
private transient PotentialFieldObstacle potentialFieldObstacle; private transient PotentialFieldObstacle potentialFieldObstacle;
private transient PotentialFieldAgent potentialFieldPedestrian; private transient PotentialFieldAgent potentialFieldPedestrian;
private transient List<SpeedAdjuster> speedAdjusters; private transient List<SpeedAdjuster> speedAdjusters;
private transient List<StepSizeAdjuster> stepSizeAdjusters;
private double durationNextStep; private double durationNextStep;
private VPoint nextPosition; private VPoint nextPosition;
private VPoint lastPosition; private VPoint lastPosition;
...@@ -62,7 +64,7 @@ public class PedestrianOSM extends Pedestrian { ...@@ -62,7 +64,7 @@ public class PedestrianOSM extends Pedestrian {
Random random, IPotentialFieldTarget potentialFieldTarget, Random random, IPotentialFieldTarget potentialFieldTarget,
PotentialFieldObstacle potentialFieldObstacle, PotentialFieldObstacle potentialFieldObstacle,
PotentialFieldAgent potentialFieldPedestrian, PotentialFieldAgent potentialFieldPedestrian,
List<SpeedAdjuster> speedAdjusters, List<StepSizeAdjuster> stepSizeAdjusters,
StepCircleOptimizer stepCircleOptimizer) { StepCircleOptimizer stepCircleOptimizer) {
super(attributesPedestrian, random); super(attributesPedestrian, random);
...@@ -74,7 +76,8 @@ public class PedestrianOSM extends Pedestrian { ...@@ -74,7 +76,8 @@ public class PedestrianOSM extends Pedestrian {
this.potentialFieldPedestrian = potentialFieldPedestrian; this.potentialFieldPedestrian = potentialFieldPedestrian;
this.stepCircleOptimizer = stepCircleOptimizer; this.stepCircleOptimizer = stepCircleOptimizer;
this.speedAdjusters = speedAdjusters; this.speedAdjusters = new LinkedList<>();
this.stepSizeAdjusters = stepSizeAdjusters;
this.relevantPedestrians = new HashSet<>(); this.relevantPedestrians = new HashSet<>();
this.timeCredit = 0; this.timeCredit = 0;
...@@ -125,7 +128,7 @@ public class PedestrianOSM extends Pedestrian { ...@@ -125,7 +128,7 @@ public class PedestrianOSM extends Pedestrian {
} else if (topography.getTarget(getNextTargetId()).getShape().contains(getPosition())) { } else if (topography.getTarget(getNextTargetId()).getShape().contains(getPosition())) {
this.nextPosition = getPosition(); this.nextPosition = getPosition();
} else { } else {
VCircle reachableArea = new VCircle(getPosition(), getStepSize()); VCircle reachableArea = new VCircle(getPosition(), getDesiredStepSize());
// get stairs pedestrian is on - remains null if on area // get stairs pedestrian is on - remains null if on area
Stairs stairs = null; Stairs stairs = null;
...@@ -166,6 +169,16 @@ public class PedestrianOSM extends Pedestrian { ...@@ -166,6 +169,16 @@ public class PedestrianOSM extends Pedestrian {
} }
} }
public double getDesiredStepSize() {
double desiredStepSize = getStepSize();
for (StepSizeAdjuster adjuster : stepSizeAdjusters) {
desiredStepSize = adjuster.getAdjustedStepSize(this, desiredStepSize);
}
return desiredStepSize;
}
public double getDesiredSpeed() { public double getDesiredSpeed() {
double desiredSpeed = getFreeFlowSpeed(); double desiredSpeed = getFreeFlowSpeed();
......
...@@ -34,7 +34,7 @@ public class ParticleSwarmOptimizer implements StepCircleOptimizer { ...@@ -34,7 +34,7 @@ public class ParticleSwarmOptimizer implements StepCircleOptimizer {
VCircle circle = ((VCircle) reachableArea); VCircle circle = ((VCircle) reachableArea);
double stepSize = circle.getRadius(); double stepSize = circle.getRadius();
List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, random); List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, (VCircle) reachableArea, random);
// maximum possible angle of movement relative to ankerAngle // maximum possible angle of movement relative to ankerAngle
double angle; double angle;
......
...@@ -36,7 +36,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer { ...@@ -36,7 +36,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer {
assert reachableArea instanceof VCircle; assert reachableArea instanceof VCircle;
double stepSize = ((VCircle) reachableArea).getRadius(); double stepSize = ((VCircle) reachableArea).getRadius();
List<VPoint> positions = getReachablePositions(pedestrian, random); List<VPoint> positions = getReachablePositions(pedestrian, (VCircle) reachableArea, random);
PotentialEvaluationFunction potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian); PotentialEvaluationFunction potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian);
potentialEvaluationFunction.setStepSize(stepSize); potentialEvaluationFunction.setStepSize(stepSize);
...@@ -75,7 +75,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer { ...@@ -75,7 +75,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer {
return new StepCircleOptimizerDiscrete(movementThreshold, random); return new StepCircleOptimizerDiscrete(movementThreshold, random);
} }
public static List<VPoint> getReachablePositions(@NotNull final PedestrianOSM pedestrian, @NotNull final Random random) { public static List<VPoint> getReachablePositions(@NotNull final PedestrianOSM pedestrian, @NotNull VCircle reachableArea, @NotNull final Random random) {
final AttributesOSM attributesOSM = pedestrian.getAttributesOSM(); final AttributesOSM attributesOSM = pedestrian.getAttributesOSM();
int numberOfCircles = attributesOSM.getNumberOfCircles(); int numberOfCircles = attributesOSM.getNumberOfCircles();
...@@ -116,8 +116,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer { ...@@ -116,8 +116,7 @@ public class StepCircleOptimizerDiscrete implements StepCircleOptimizer {
return GeometryUtils.getDiscDiscretizationPoints( return GeometryUtils.getDiscDiscretizationPoints(
random, random,
attributesOSM.isVaryStepDirection(), attributesOSM.isVaryStepDirection(),
new VCircle(pedestrian.getPosition(), reachableArea,
pedestrian.getStepSize()),
numberOfCircles, numberOfCircles,
attributesOSM.getStepCircleResolution(), attributesOSM.getStepCircleResolution(),
anchorAngle, anchorAngle,
......
...@@ -37,7 +37,7 @@ public class StepCircleOptimizerEvolStrat implements StepCircleOptimizer { ...@@ -37,7 +37,7 @@ public class StepCircleOptimizerEvolStrat implements StepCircleOptimizer {
public VPoint getNextPosition(PedestrianOSM ped, Shape reachableArea) { public VPoint getNextPosition(PedestrianOSM ped, Shape reachableArea) {
double stepSize = ((VCircle) reachableArea).getRadius(); double stepSize = ((VCircle) reachableArea).getRadius();
List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(ped, random); List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(ped, (VCircle)reachableArea, random);
int numberOfParents = positions.size(); int numberOfParents = positions.size();
int numberOfChildren = numberOfParents * 7; int numberOfChildren = numberOfParents * 7;
......
...@@ -35,7 +35,7 @@ public class StepCircleOptimizerNelderMead implements StepCircleOptimizer { ...@@ -35,7 +35,7 @@ public class StepCircleOptimizerNelderMead implements StepCircleOptimizer {
public VPoint getNextPosition(PedestrianOSM pedestrian, Shape reachableArea) { public VPoint getNextPosition(PedestrianOSM pedestrian, Shape reachableArea) {
double stepSize = ((VCircle) reachableArea).getRadius(); double stepSize = ((VCircle) reachableArea).getRadius();
List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, random); List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, (VCircle)reachableArea, random);
PotentialEvaluationFunction potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian); PotentialEvaluationFunction potentialEvaluationFunction = new PotentialEvaluationFunction(pedestrian);
potentialEvaluationFunction.setStepSize(stepSize); potentialEvaluationFunction.setStepSize(stepSize);
......
...@@ -38,7 +38,7 @@ public class StepCircleOptimizerPowell implements StepCircleOptimizer { ...@@ -38,7 +38,7 @@ public class StepCircleOptimizerPowell implements StepCircleOptimizer {
PointValuePair newMinimum = new PointValuePair(position, potentialEvaluationFunction.value(position)); PointValuePair newMinimum = new PointValuePair(position, potentialEvaluationFunction.value(position));
List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, random); List<VPoint> positions = StepCircleOptimizerDiscrete.getReachablePositions(pedestrian, (VCircle)reachableArea, random);
try { try {
newMinimum = optimizer.optimize(1000, (MultivariateFunction) potentialEvaluationFunction, GoalType.MINIMIZE, newMinimum = optimizer.optimize(1000, (MultivariateFunction) potentialEvaluationFunction, GoalType.MINIMIZE,
......
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