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

Commit d103f2e9 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Moved BHM navigation classes to new package "helpers.navigation" and...

Moved BHM navigation classes to new package "helpers.navigation" and implemented "NavigationBuilder" to instantiate model from string in scenario file
parent ee1ae4bb
Pipeline #348211 failed with stages
in 4 minutes and 46 seconds
......@@ -46,12 +46,13 @@
"stepLengthDeviation" : false,
"navigationCluster" : false,
"navigationFollower" : false,
"followerProximityNavigation" : true,
"navigationModel" : "NavigationProximity",
"directionWallDistance" : false,
"tangentialEvasion" : true,
"sidewaysEvasion" : false,
"onlyEvadeContraFlow" : false,
"makeSmallSteps" : false,
"followerProximityNavigation" : true,
"differentBehaviour" : false,
"differentEvasionBehaviourPercentage" : [ ],
"varyingBehaviour" : true,
......
......@@ -46,12 +46,13 @@
"stepLengthDeviation" : false,
"navigationCluster" : false,
"navigationFollower" : false,
"followerProximityNavigation" : true,
"navigationModel" : "NavigationProximity",
"directionWallDistance" : false,
"tangentialEvasion" : true,
"sidewaysEvasion" : false,
"onlyEvadeContraFlow" : false,
"makeSmallSteps" : false,
"followerProximityNavigation" : true,
"differentBehaviour" : false,
"differentEvasionBehaviourPercentage" : [ ],
"varyingBehaviour" : true,
......
......@@ -28,12 +28,13 @@
"stepLengthDeviation" : true,
"navigationCluster" : false,
"navigationFollower" : false,
"followerProximityNavigation" : true,
"navigationModel" : "NavigationProximity",
"directionWallDistance" : false,
"tangentialEvasion" : false,
"sidewaysEvasion" : false,
"onlyEvadeContraFlow" : false,
"makeSmallSteps" : false,
"followerProximityNavigation" : false,
"differentBehaviour" : false,
"differentEvasionBehaviourPercentage" : [ ],
"varyingBehaviour" : false,
......@@ -220,4 +221,4 @@
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
}
......@@ -28,12 +28,13 @@
"stepLengthDeviation" : true,
"navigationCluster" : false,
"navigationFollower" : false,
"followerProximityNavigation" : true,
"navigationModel" : "NavigationProximity",
"directionWallDistance" : false,
"tangentialEvasion" : true,
"sidewaysEvasion" : true,
"onlyEvadeContraFlow" : false,
"makeSmallSteps" : false,
"followerProximityNavigation" : false,
"differentBehaviour" : false,
"differentEvasionBehaviourPercentage" : [ ],
"varyingBehaviour" : false,
......@@ -100,7 +101,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : null
"strategyModel" : null,
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......@@ -215,4 +218,4 @@
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
}
......@@ -28,12 +28,13 @@
"stepLengthDeviation" : true,
"navigationCluster" : false,
"navigationFollower" : false,
"followerProximityNavigation" : true,
"navigationModel" : "NavigationProximity",
"directionWallDistance" : false,
"tangentialEvasion" : false,
"sidewaysEvasion" : false,
"onlyEvadeContraFlow" : false,
"makeSmallSteps" : false,
"followerProximityNavigation" : false,
"differentBehaviour" : false,
"differentEvasionBehaviourPercentage" : [ ],
"varyingBehaviour" : false,
......@@ -100,7 +101,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : null
"strategyModel" : null,
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......@@ -122,7 +125,7 @@
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 2
}, {
"shape" : {
"x" : 1.0,
......@@ -131,7 +134,7 @@
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 3
}, {
"shape" : {
"x" : 1.0,
......@@ -140,7 +143,7 @@
"height" : 19.5,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 4
}, {
"shape" : {
"x" : 1.0,
......@@ -149,7 +152,7 @@
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 5
}, {
"shape" : {
"x" : 33.0,
......@@ -158,7 +161,7 @@
"height" : 18.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 6
}, {
"shape" : {
"x" : 2.5,
......@@ -167,7 +170,7 @@
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 7
}, {
"shape" : {
"x" : 2.5,
......@@ -176,7 +179,7 @@
"height" : 16.4,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 8
}, {
"shape" : {
"x" : 2.5,
......@@ -185,7 +188,7 @@
"height" : 1.0,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 9
}, {
"shape" : {
"x" : 24.0,
......@@ -194,7 +197,7 @@
"height" : 12.5,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 10
}, {
"shape" : {
"x" : 20.1,
......@@ -203,7 +206,7 @@
"height" : 11.4,
"type" : "RECTANGLE"
},
"id" : -1
"id" : 11
} ],
"measurementAreas" : [ ],
"stairs" : [ ],
......@@ -228,7 +231,7 @@
"targetChangers" : [ ],
"absorbingAreas" : [ ],
"sources" : [ {
"id" : -1,
"id" : 12,
"shape" : {
"x" : 16.0,
"y" : 2.0,
......@@ -269,4 +272,4 @@
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
}
package org.vadere.simulator.models.bhm;
import org.vadere.util.geometry.shapes.VPoint;
public interface Navigation {
public VPoint getNavigationPosition();
}
......@@ -2,6 +2,9 @@ package org.vadere.simulator.models.bhm;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.bhm.helpers.navigation.INavigation;
import org.vadere.simulator.models.bhm.helpers.navigation.NavigationBuilder;
import org.vadere.simulator.models.bhm.helpers.navigation.NavigationEvasion;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.attributes.scenario.AttributesAgent;
......@@ -35,10 +38,10 @@ public class PedestrianBHM extends Pedestrian {
private VPoint lastPosition;
private VPoint targetDirection;
private final transient Navigation navigation;
private final transient INavigation navigation;
private final transient List<DirectionAddend> directionAddends;
protected int action;
public int action;
private boolean evadesTangentially;
private boolean evadesSideways;
......@@ -75,27 +78,8 @@ public class PedestrianBHM extends Pedestrian {
// model building ...
// TODO: Implement a model builder class similar to "CognitionModelBuilder".
// Select a "Navigation" class by passing a simple string.
this.navigation = new NavigationEvasion(this, topography);
/*
if (attributesBHM.isNavigationCluster()) {
this.navigation = new NavigationCluster(this, topography, random);
if (attributesBHM.isNavigationFollower()) {
logger.warn("Only one navigation heuristic can be chosen."
+ "Choosing cluster navigation.");
}
} else if (attributesBHM.isNavigationFollower()) {
this.navigation = new NavigationFollower(this, topography, random);
if (attributesBHM.isNavigationCluster()) {
logger.warn("Only one navigation heuristic can be chosen."
+ "Choosing follower navigation.");
}
} else {
this.navigation = new NavigationProximity(this, random);
}
*/
String navigationModel = attributesBHM.getNavigationModel();
this.navigation = NavigationBuilder.instantiateModel(navigationModel, this, topography, random);
if (attributesBHM.isDirectionWallDistance()) {
directionAddends.add(new DirectionAddendObstacle(this));
......@@ -192,7 +176,7 @@ public class PedestrianBHM extends Pedestrian {
// do nothing
} else if (selfCategory == SelfCategory.EVADE) {
// TODO: Force tangential or sideways evasion using BHM's internal methods
// or by implementing "Navigation" interface myself and always evade to the right hand side.
// or by implementing "INavigation" interface myself and always evade to the right hand side.
nextPosition = navigation.getNavigationPosition();
makeStep();
}
......@@ -229,7 +213,7 @@ public class PedestrianBHM extends Pedestrian {
}
}
VPoint stepAwayFromCollision(final Pedestrian collisionPed) {
public VPoint stepAwayFromCollision(final Pedestrian collisionPed) {
return getPosition().subtract(collisionPed.getPosition()).norm().scalarMultiply(stepLength).add(getPosition());
}
......@@ -258,7 +242,7 @@ public class PedestrianBHM extends Pedestrian {
// target direction methods...
VPoint computeTargetStep() {
public VPoint computeTargetStep() {
return UtilsBHM.getTargetStep(this, getPosition(), getTargetDirection());
}
......@@ -316,7 +300,7 @@ public class PedestrianBHM extends Pedestrian {
}
}
VPoint computeMovementProjection() {
public VPoint computeMovementProjection() {
return getPosition().add(getTargetDirection().scalarMultiply(
stepLength * attributesBHM.getPlannedStepsAhead()));
}
......@@ -351,7 +335,7 @@ public class PedestrianBHM extends Pedestrian {
/**
* Check collisions on the path.
*/
boolean collidesWithPedestrianOnPath(VPoint position) {
public boolean collidesWithPedestrianOnPath(VPoint position) {
Pedestrian collision = findCollisionPedestrian(position, true);
return collision != null;
......@@ -361,7 +345,7 @@ public class PedestrianBHM extends Pedestrian {
* If findAny is false, return the first collision on the path to position.
* If findAny is true, return the first collision that was found (could be any).
*/
Pedestrian findCollisionPedestrian(VPoint position, boolean findAny) {
public Pedestrian findCollisionPedestrian(VPoint position, boolean findAny) {
Pedestrian result = null;
double minDistance = Double.MAX_VALUE;
......@@ -417,7 +401,7 @@ public class PedestrianBHM extends Pedestrian {
/**
* This does not check collisions on the path, just collisions with position!
*/
List<Obstacle> detectObstacleProximity(@NotNull VPoint position, double proximity) {
public List<Obstacle> detectObstacleProximity(@NotNull VPoint position, double proximity) {
Collection<Obstacle> obstacles = topography.getObstacles();
List<Obstacle> result = new LinkedList<>();
......
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Random;
public interface INavigation {
public void initialize(PedestrianBHM pedestrianBHM, Topography topography, Random random);
public VPoint getNavigationPosition();
}
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.state.scenario.Topography;
import org.vadere.util.reflection.DynamicClassInstantiator;
import java.util.Random;
/**
* This class encapsulates the creation of a concrete {@link INavigation}
* which is defined by the user in the JSON scenario description.
*
* The user provides the simple class name in the JSON scenario file.
* I.e., no fully qualified classname.
*/
public class NavigationBuilder {
public static final String JAVA_PACKAGE_SEPARATOR = ".";
public static INavigation instantiateModel(String simpleClassName, PedestrianBHM pedestrianBHM, Topography topography, Random random) {
String classSearchPath = INavigation.class.getPackageName();
String fullyQualifiedClassName = classSearchPath + JAVA_PACKAGE_SEPARATOR + simpleClassName;
DynamicClassInstantiator<INavigation> instantiator = new DynamicClassInstantiator<>();
INavigation navigationModel = instantiator.createObject(fullyQualifiedClassName);
navigationModel.initialize(pedestrianBHM, topography, random);
return navigationModel;
}
}
package org.vadere.simulator.models.bhm;
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.simulator.models.bhm.UtilsBHM;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -11,20 +13,22 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class NavigationCluster implements Navigation {
public class NavigationCluster implements INavigation {
private static Logger logger = Logger.getLogger(NavigationCluster.class);
private final Topography topography;
private final AttributesBHM attributesBHM;
private final PedestrianBHM me;
private final NavigationProximity proximityNavigation;
private Topography topography;
private AttributesBHM attributesBHM;
private PedestrianBHM me;
private NavigationProximity proximityNavigation;
public NavigationCluster(PedestrianBHM me, Topography topography, Random random) {
this.me = me;
@Override
public void initialize(PedestrianBHM pedestrianBHM, Topography topography, Random random) {
this.me = pedestrianBHM;
this.topography = topography;
this.attributesBHM = me.getAttributesBHM();
this.proximityNavigation = new NavigationProximity(me, random);
this.proximityNavigation = new NavigationProximity();
proximityNavigation.initialize(me, topography, random);
}
@Override
......
package org.vadere.simulator.models.bhm;
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -11,6 +12,7 @@ import org.vadere.util.logging.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
......@@ -24,18 +26,16 @@ import java.util.stream.Collectors;
* <li>Wait.</li>
* </ol>
*/
public class NavigationEvasion implements Navigation {
public class NavigationEvasion implements INavigation {
private static Logger logger = Logger.getLogger(NavigationEvasion.class);
private final PedestrianBHM me;
private final Topography topography;
private final AttributesBHM attributesBHM;
private PedestrianBHM me;
private Topography topography;
public NavigationEvasion(PedestrianBHM me, Topography topography) {
this.me = me;
public void initialize(PedestrianBHM pedestrianBHM, Topography topography, Random random) {
this.me = pedestrianBHM;
this.topography = topography;
this.attributesBHM = me.getAttributesBHM();
}
@Override
......
package org.vadere.simulator.models.bhm;
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.simulator.models.bhm.UtilsBHM;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -10,20 +12,21 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class NavigationFollower implements Navigation {
public class NavigationFollower implements INavigation {
private static Logger logger = Logger.getLogger(NavigationFollower.class);
private final Topography topography;
private final AttributesBHM attributesBHM;
private final PedestrianBHM me;
private final NavigationProximity proximityNavigation;
private Topography topography;
private AttributesBHM attributesBHM;
private PedestrianBHM me;
private NavigationProximity proximityNavigation;
public NavigationFollower(PedestrianBHM me, Topography topography, Random random) {
this.me = me;
public void initialize(PedestrianBHM pedestrianBHM, Topography topography, Random random) {
this.me = pedestrianBHM;
this.topography = topography;
this.attributesBHM = me.getAttributesBHM();
this.proximityNavigation = new NavigationProximity(me, random);
this.proximityNavigation = new NavigationProximity();
this.proximityNavigation.initialize(me, topography, random);
}
@Override
......
package org.vadere.simulator.models.bhm;
package org.vadere.simulator.models.bhm.helpers.navigation;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.bhm.PedestrianBHM;
import org.vadere.simulator.models.bhm.UtilsBHM;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -14,16 +17,16 @@ import java.util.List;
import java.util.Optional;
import java.util.Random;
public class NavigationProximity implements Navigation {
public class NavigationProximity implements INavigation {
private static Logger logger = Logger.getLogger(NavigationProximity.class);
private final Random random;
private final AttributesBHM attributesBHM;
private final PedestrianBHM me;
private Random random;
private AttributesBHM attributesBHM;
private PedestrianBHM me;
public NavigationProximity(PedestrianBHM me, Random random) {
this.me = me;
public void initialize(PedestrianBHM pedestrianBHM, Topography topography, Random random) {
this.me = pedestrianBHM;
this.random = random;
this.attributesBHM = me.getAttributesBHM();
}
......
package org.vadere.simulator.models.bhm;
import org.junit.Test;
import org.vadere.simulator.models.bhm.helpers.navigation.NavigationEvasion;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTargetGrid;
import org.vadere.simulator.projects.Domain;
import org.vadere.state.attributes.Attributes;
......@@ -8,7 +9,6 @@ import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesTarget;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VCircle;
......
......@@ -18,15 +18,17 @@ public class AttributesBHM extends Attributes {
private double stepLengthSD = 0.036;
private boolean stepLengthDeviation = false;
// TODO: Remove boolean navigation variables (including migration). Instead, use new "NavigationBuilder".
private boolean navigationCluster = false;
private boolean navigationFollower = false;
private boolean directionWallDistance = false;
private boolean followerProximityNavigation = true;
private String navigationModel = "NavigationProximity";
private boolean directionWallDistance = false;
private boolean tangentialEvasion = true;
private boolean sidewaysEvasion = false;
private boolean onlyEvadeContraFlow = false;
private boolean makeSmallSteps = false;
private boolean followerProximityNavigation = true;
private boolean differentBehaviour = false;
private LinkedList<Double> differentEvasionBehaviourPercentage = new LinkedList<>();
......@@ -78,6 +80,12 @@ public class AttributesBHM extends Attributes {
return navigationFollower;
}
public boolean isFollowerProximityNavigation() {
return followerProximityNavigation;
}
public String getNavigationModel() { return navigationModel; }
public boolean isDirectionWallDistance() {
return directionWallDistance;
}
......@@ -98,9 +106,6 @@ public class AttributesBHM extends Attributes {
return makeSmallSteps;
}
public boolean isFollowerProximityNavigation() {
return followerProximityNavigation;
}
public double getEvasionDetourThreshold() {
return evasionDetourThreshold;
......