Skip to content

Commit

Permalink
some improvment of the pedestrian skill
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed May 20, 2021
1 parent 3c3767f commit ae03f63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Expand Up @@ -94,7 +94,7 @@ global {
}

species pedestrian_path skills: [pedestrian_road]{
aspect default {
aspect default {
draw shape color: #gray;
}
aspect free_area_aspect {
Expand Down
Expand Up @@ -39,6 +39,7 @@
import msi.gama.util.graph.IGraph;
import msi.gaml.operators.Spatial;
import msi.gaml.operators.Spatial.Operators;
import msi.gaml.operators.Spatial.Punctal;
import msi.gaml.operators.Spatial.Transformations;
import msi.gaml.skills.Skill;
import msi.gaml.species.ISpecies;
Expand Down Expand Up @@ -210,7 +211,7 @@ public static IList<IAgent> getCloseAgents(final IAgent agent) {
value = "action to initialize the free space of roads",
examples = { @example ("do initialize distance: 10.0 obstacles: [building];") }))
@SuppressWarnings("unchecked")
public void primWalkEscape(final IScope scope) throws GamaRuntimeException {
public void primInitialize(final IScope scope) throws GamaRuntimeException {
final IAgent agent = getCurrentAgent(scope);

int status = scope.hasArg("status") ? scope.getIntArg("status") : (agent.getGeometry().hasAttribute(PEDESTRIAN_ROAD_STATUS) ? GamaIntegerType
Expand Down Expand Up @@ -422,6 +423,8 @@ public static IList<GamaPoint> getConnectedOutput(IScope scope, IShape currentRo
@SuppressWarnings("unchecked")
public static void register(IScope scope, IAgent road, IAgent pedestrian ) {
((IList<IAgent> ) road.getAttribute(AGENTS_ON)).add(pedestrian);
if (!pedestrian.getLocation().intersects(getFreeSpace(road)))
pedestrian.setLocation(Punctal._closest_point_to(pedestrian.getLocation(), getFreeSpace(road)));
pedestrian.setAttribute("current_edge", road);
}

Expand Down
Expand Up @@ -28,7 +28,6 @@
import msi.gama.util.path.IPath;
import msi.gaml.descriptions.ConstantExpressionDescription;
import msi.gaml.operators.Cast;
import msi.gaml.operators.Maths;
import msi.gaml.operators.Points;
import msi.gaml.operators.Random;
import msi.gaml.operators.Spatial;
Expand Down Expand Up @@ -105,7 +104,7 @@
type = IType.FLOAT,
init = "2.0",
doc = @doc ("Value of B in the SFM model for obstacles - the range (in meters) of repulsive interactions")),
@variable (
@variable (
name = "k_SFM",
type = IType.FLOAT,
init = "200",
Expand Down Expand Up @@ -279,8 +278,6 @@ public void setKappaSFM(final IAgent agent, final double s) {





@getter (OBSTACLE_SPECIES)
public GamaList<ISpecies> getObstacleSpecies(final IAgent agent) {
return (GamaList<ISpecies>) agent.getAttribute(OBSTACLE_SPECIES);
Expand Down Expand Up @@ -410,8 +407,6 @@ public void setBObstSFM(final IAgent agent, final Double val) {
agent.setAttribute(B_OBSTACLES_SFM, val);
}



@getter (AVOID_OTHER)
public Boolean getAvoidOther(final IAgent agent) {
return (Boolean) agent.getAttribute(AVOID_OTHER);
Expand Down Expand Up @@ -444,8 +439,6 @@ public void setToleranceTarget(final IAgent agent, final double s) {
agent.setAttribute(TOLERANCE_TARGET, s);
}



@getter (TARGETS)
public IList<IShape> getTargets(final IAgent agent) {
return (IList<IShape>) agent.getAttribute(TARGETS);
Expand Down Expand Up @@ -573,7 +566,10 @@ public double walkWithForceModel(IScope scope, IAgent agent, IShape currentTarge
IShape bounds, IContainer<Integer, ?> pedestrianList, IContainer<Integer, ?> obstaclesList, double maxDist) {
GamaPoint location = (GamaPoint) getLocation(agent).copy(scope);
GamaPoint target = currentTarget.isPoint() ? currentTarget.getLocation().toGamaPoint() : Punctal._closest_point_to(location, currentTarget).toGamaPoint();
target.setZ(target.z);
double dist = location.distance(target);
//System.out.println("location: " + location +" target: " + target + " dist: " + dist);

if (dist == 0.0) return 0.0;

if( !currentTarget.isPoint() && bounds != null && getCurrentEdge(agent) != null) {
Expand All @@ -598,6 +594,7 @@ public double walkWithForceModel(IScope scope, IAgent agent, IShape currentTarge
double distPercep = Math.max(maxDist, getPedestrianConsiderationDistance(agent));
double distPercepObst = Math.max(maxDist, getObstacleConsiderationDistance(agent));
velocity = avoidSFM(scope, agent, location, target, distPercep,distPercepObst,pedestrianList,obstaclesList);
velocity = velocity.multiplyBy(dist);
} else {
velocity = target.copy(scope).minus(location);
}
Expand Down Expand Up @@ -645,8 +642,6 @@ public GamaPoint avoidSFM(IScope scope, IAgent agent, GamaPoint location, GamaPo
double dist = location.euclidianDistanceTo(currentTarget);
if (dist == 0 || getSpeed(agent) <= 0.0)
return new GamaPoint(0,0,0);
double step = scope.getSimulation().getClock().getStepInSeconds();
double speed = getSpeed(agent);
IList<IAgent> obstacles = GamaListFactory.create(Types.AGENT);
IList<IAgent> pedestrians = GamaListFactory.create(Types.AGENT);

Expand Down Expand Up @@ -743,14 +738,7 @@ public GamaPoint avoidSFM(IScope scope, IAgent agent, GamaPoint location, GamaPo
forcesMap.put(agent, fdest);
agent.setAttribute(FORCES, forcesMap);
GamaPoint forces = fdest.add(forcesPedestrian);

GamaPoint pref_velocity = current_velocity.add(forces.multiplyBy(step));
double norm_vel = Maths.sqrt(scope, pref_velocity.x * pref_velocity.x +pref_velocity.y * pref_velocity.y+pref_velocity.z * pref_velocity.z);
if (norm_vel > speed) {
current_velocity = pref_velocity.divideBy(norm_vel * speed);
} else {
current_velocity = pref_velocity;
}
current_velocity = current_velocity.add(forces).normalize();
return current_velocity;
}

Expand Down Expand Up @@ -781,7 +769,6 @@ public IPath primComputeVirtualPath(final IScope scope) throws GamaRuntimeExcept
IShape source = agent.getLocation();

thePath = ((GraphTopology) graph.getTopology(scope)).pathBetween(scope, source, target);

// If there is no path between source and target ...
if(thePath == null) { return thePath; }
IMap<IShape,IShape> roadTarget = GamaMapFactory.create();
Expand All @@ -794,7 +781,6 @@ public IPath primComputeVirtualPath(final IScope scope) throws GamaRuntimeExcept
IShape cRoad = thePath.getRealObject(cSeg);
IMap<IAgent,IShape> map = PedestrianRoadSkill.getConnectedSegmentsIntersection((IAgent) cRoad);

//Double dist = PedestrianRoadSkill.getDistance(cRoad.getAgent());
IShape geom = null,cRoadNext = null,geomNext = null;
if (useGeometryTarget) {
geom = PedestrianRoadSkill.getFreeSpace(cRoad.getAgent());
Expand Down Expand Up @@ -901,7 +887,6 @@ public void primArrivedAtDestination(final IScope scope) throws GamaRuntimeExcep
public void primWalk(final IScope scope) throws GamaRuntimeException {
final IAgent agent = getCurrentAgent(scope);
if (agent == null || agent.dead()) { return; }

final IShape finalTarget = getFinalTarget(agent);
if (finalTarget == null) { return; }

Expand All @@ -910,6 +895,7 @@ public void primWalk(final IScope scope) throws GamaRuntimeException {

GamaPoint location = (GamaPoint) getLocation(agent).copy(scope);
double maxDist = computeDistance(scope, agent);

boolean movement = true;
int maxIndex = targets.size() - 1;
while(movement) {
Expand All @@ -918,7 +904,7 @@ public void primWalk(final IScope scope) throws GamaRuntimeException {
int index = getCurrentIndex(agent);
IShape currentTarget = getCurrentTarget(agent);
IAgent road = (IAgent) getRoadsTargets(agent).get(currentTarget);

IShape bounds = null;
boolean avoidOther = getAvoidOther(agent);

Expand Down Expand Up @@ -948,6 +934,7 @@ public void primWalk(final IScope scope) throws GamaRuntimeException {

if (arrivedAtTarget(scope,location,currentTarget,getToleranceTarget(agent), index, maxIndex, targets)) {
if (road != null) PedestrianRoadSkill.unregister(scope, road, agent);

if (index < maxIndex) {
index++;

Expand Down

0 comments on commit ae03f63

Please sign in to comment.