Commit e980bc8c authored by BZoennchen's avatar BZoennchen

issue#135 test of an improved version of BHM + floor field.

parent 24ecda1f
Pipeline #72305 failed with stages
in 67 minutes
......@@ -118,7 +118,6 @@ public class BehaviouralHeuristicsModel implements MainModel {
@Override
public void update(final double simTimeInSec) {
// event driven update
if (!pedestrianEventsQueue.isEmpty()) {
while (pedestrianEventsQueue.peek().getTimeOfNextStep() < simTimeInSec) {
......
......@@ -68,6 +68,10 @@ public class NavigationProximity implements Navigation {
(!me.evadesTangentially() &&
me.collidesWithPedestrian(result, 2 * attributesBHM.getSpaceToKeep()))) {
/*if( me.collidesWithObstacle(result) ) {
System.out.println("obs collision " + me.getId());
}*/
result = me.getPosition();
me.action = 0; // LOGGING
}
......
......@@ -9,6 +9,8 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizerDiscrete;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.attributes.scenario.AttributesAgent;
......@@ -18,6 +20,7 @@ import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VLine;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -249,7 +252,7 @@ public class PedestrianBHM extends Pedestrian {
targetDirection = targetPoint.subtract(getPosition()).norm();
}
else {
Vector2D vec = potentialFieldTarget.getTargetPotentialGradient(getPosition(), this).multiply(-1.0);
Vector2D vec = new Vector2D(computeTargetDirectionByGradient());
if(vec.getLength() < GeometryUtils.DOUBLE_EPS) {
targetDirection = VPoint.ZERO;
}
......@@ -272,6 +275,33 @@ public class PedestrianBHM extends Pedestrian {
}
}
private VPoint computeTargetDirectionByGradient() {
return potentialFieldTarget.getTargetPotentialGradient(getPosition(), this).multiply(-1.0);
}
private VPoint computeTargetDirectionByOptimaization() {
Vector2D gradient = potentialFieldTarget.getTargetPotentialGradient(getPosition(), this).multiply(-1.0);
double angle = GeometryUtils.angleTo(gradient, new VPoint(1, 0));
List<VPoint> possibleNextPositions = GeometryUtils.getDiscDiscretizationPoints(
random,
false,
new VCircle(getPosition(), stepLength),
1,
15,
angle,
2*Math.PI);
VPoint nextOptimalPos = possibleNextPositions.stream()
.filter(p -> !collidesWithObstacle(p))
.min(
(p1, p2) -> Double.compare(potentialFieldTarget.getPotential(p1, this),
potentialFieldTarget.getPotential(p2, this))
).get();
return nextOptimalPos.subtract(getPosition());
}
/**
* Set the last target if beyond a certain threshold.
*/
......
......@@ -55,7 +55,7 @@ public class PotentialFieldTargetGrid extends AbstractPotentialFieldTarget {
@Override
public Vector2D getTargetPotentialGradient(VPoint pos, Agent ped) {
double potential = getPotential(pos, ped);
double eps = 0.01;
double eps = 0.001;
double dGradPX = (getPotential(pos.add(new VPoint(eps, 0)), ped) - potential) / eps;
double dGradPY = (getPotential(pos.add(new VPoint(0, eps)), ped) - potential) / eps;
return new Vector2D(dGradPX, dGradPY);
......
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