Commit 7288e987 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Added package "simulator/models/potential/combinedPotentials/" to encapsulate...

Added package "simulator/models/potential/combinedPotentials/" to encapsulate strategy pattern classes for bang event.
parent af5e8f32
Pipeline #90611 failed with stages
in 3 minutes and 45 seconds
......@@ -3,6 +3,8 @@ package org.vadere.simulator.models.osm;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.StepSizeAdjuster;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.simulator.models.potential.combinedPotentials.TargetDistractionStrategy;
import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.simulator.models.SpeedAdjuster;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
......@@ -39,6 +41,8 @@ public class PedestrianOSM extends Pedestrian {
private transient IPotentialFieldTarget potentialFieldTarget;
private transient PotentialFieldObstacle potentialFieldObstacle;
private transient PotentialFieldAgent potentialFieldPedestrian;
// TODO: Provide method to change object here according to stragey pattern.
private transient CombinedPotentialStrategy combinedPotentialStrategy;
private transient List<SpeedAdjuster> speedAdjusters;
private transient List<StepSizeAdjuster> stepSizeAdjusters;
private VPoint nextPosition;
......@@ -73,6 +77,8 @@ public class PedestrianOSM extends Pedestrian {
this.potentialFieldTarget = potentialFieldTarget;
this.potentialFieldObstacle = potentialFieldObstacle;
this.potentialFieldPedestrian = potentialFieldPedestrian;
// TODO: Use "TargetAttractionStrategy" by default.
this.combinedPotentialStrategy = new TargetDistractionStrategy(potentialFieldTarget, potentialFieldObstacle, potentialFieldPedestrian);
this.stepCircleOptimizer = stepCircleOptimizer;
this.speedAdjusters = speedAdjusters;
......@@ -227,23 +233,7 @@ public class PedestrianOSM extends Pedestrian {
}
public double getPotential(IPoint newPos) {
double targetPotential = potentialFieldTarget.getPotential(newPos, this);
// The target potential is intialized with "Double.MAX_VALUE" in obstacle regions!
// Multiplying "Double.MAX_VALUE" with "-1" would cause an agent to walk into an obstacle.
if (targetPotential != Double.MAX_VALUE) {
targetPotential *= -1;
}
double pedestrianPotential = potentialFieldPedestrian
.getAgentPotential(newPos, this, relevantPedestrians);
double obstacleRepulsionPotential = potentialFieldObstacle
.getObstaclePotential(newPos, this);
return targetPotential + pedestrianPotential
+ obstacleRepulsionPotential;
return combinedPotentialStrategy.getValue(newPos, this, relevantPedestrians);
}
public void clearStrides() {
......
package org.vadere.simulator.models.potential.combinedPotentials;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.IPoint;
import java.util.Collection;
/**
* In "seitz-2012", the total potential for some point x (in R²)
* is the combination of different potentials:
*
* combined(x) = target(x) + obstacles(x) + agents(x)
*
* Use this interface to implement different combinations of these
* potentials. For instance, negate the target potential so that
* agents run away from targets:
*
* combined(x) = -target(x) + obstacles(x) + agents(x)
*
* The implementing classes require objects of following interfaces
* to calculate the combined potential:
* - {@link org.vadere.simulator.models.potential.fields.IPotentialFieldTarget}
* - {@link org.vadere.simulator.models.potential.fields.PotentialFieldObstacle}
* - {@link org.vadere.simulator.models.potential.fields.PotentialFieldAgent}
*
* At runtime, implementations of this interface can be replaced by using the strategy pattern.
*/
public interface CombinedPotentialStrategy {
/**
* Get the combined potential at given position.
*/
public double getValue(IPoint newPos, Agent thisAgent, Collection<? extends Agent> otherAgents);
}
package org.vadere.simulator.models.potential.combinedPotentials;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.PotentialFieldAgent;
import org.vadere.simulator.models.potential.fields.PotentialFieldObstacle;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.IPoint;
import java.util.Collection;
/**
* Combine potential so that agents get attracted by targets.
*/
public class TargetAttractionStrategy implements CombinedPotentialStrategy {
private IPotentialFieldTarget potentialFieldTarget;
private PotentialFieldObstacle potentialFieldObstacle;
private PotentialFieldAgent potentialFieldAgent;
public TargetAttractionStrategy(IPotentialFieldTarget potentialFieldTarget, PotentialFieldObstacle potentialFieldObstacle, PotentialFieldAgent potentialFieldAgent) {
this.potentialFieldTarget = potentialFieldTarget;
this.potentialFieldObstacle = potentialFieldObstacle;
this.potentialFieldAgent = potentialFieldAgent;
}
@Override
public double getValue(IPoint newPos, Agent thisAgent, Collection<? extends Agent> otherAgents) {
double targetPotential = potentialFieldTarget.getPotential(newPos, thisAgent);
double obstaclePotential = potentialFieldObstacle.getObstaclePotential(newPos, thisAgent);
double agentPotential = potentialFieldAgent.getAgentPotential(newPos, thisAgent, otherAgents);
return targetPotential + agentPotential + obstaclePotential;
}
}
package org.vadere.simulator.models.potential.combinedPotentials;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.PotentialFieldAgent;
import org.vadere.simulator.models.potential.fields.PotentialFieldObstacle;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.IPoint;
import java.util.Collection;
/**
* Combine potential so that agents get distracted by targets.
*/
public class TargetDistractionStrategy implements CombinedPotentialStrategy {
private IPotentialFieldTarget potentialFieldTarget;
private PotentialFieldObstacle potentialFieldObstacle;
private PotentialFieldAgent potentialFieldAgent;
public TargetDistractionStrategy(IPotentialFieldTarget potentialFieldTarget, PotentialFieldObstacle potentialFieldObstacle, PotentialFieldAgent potentialFieldAgent) {
this.potentialFieldTarget = potentialFieldTarget;
this.potentialFieldObstacle = potentialFieldObstacle;
this.potentialFieldAgent = potentialFieldAgent;
}
@Override
public double getValue(IPoint newPos, Agent thisAgent, Collection<? extends Agent> otherAgents) {
double targetPotential = potentialFieldTarget.getPotential(newPos, thisAgent);
// The target potential is intialized with "Double.MAX_VALUE" in obstacle regions!
// Multiplying "Double.MAX_VALUE" with "-1" would cause an agent to walk into an obstacle.
if (targetPotential != Double.MAX_VALUE) {
targetPotential *= -1;
}
double obstaclePotential = potentialFieldObstacle.getObstaclePotential(newPos, thisAgent);
double agentPotential = potentialFieldAgent.getAgentPotential(newPos, thisAgent, otherAgents);
return targetPotential + agentPotential + obstaclePotential;
}
}
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