From ae03f636b2028b2b88c2e7e11f385b9a72e231d4 Mon Sep 17 00:00:00 2001 From: ptaillandier Date: Thu, 20 May 2021 10:32:49 +0700 Subject: [PATCH] some improvment of the pedestrian skill --- .../models/Complex environment - walk.gaml | 2 +- .../skills/PedestrianRoadSkill.java | 5 ++- .../extensions/skills/PedestrianSkill.java | 31 ++++++------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/miat.gaml.extensions.pedestrian/models/Pedestrian Skill/models/Complex environment - walk.gaml b/miat.gaml.extensions.pedestrian/models/Pedestrian Skill/models/Complex environment - walk.gaml index 825e53fa2a..f58ff90e68 100644 --- a/miat.gaml.extensions.pedestrian/models/Pedestrian Skill/models/Complex environment - walk.gaml +++ b/miat.gaml.extensions.pedestrian/models/Pedestrian Skill/models/Complex environment - walk.gaml @@ -94,7 +94,7 @@ global { } species pedestrian_path skills: [pedestrian_road]{ - aspect default { + aspect default { draw shape color: #gray; } aspect free_area_aspect { diff --git a/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianRoadSkill.java b/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianRoadSkill.java index 3c5faeb42b..dec65b6a29 100644 --- a/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianRoadSkill.java +++ b/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianRoadSkill.java @@ -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; @@ -210,7 +211,7 @@ public static IList 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 @@ -422,6 +423,8 @@ public static IList getConnectedOutput(IScope scope, IShape currentRo @SuppressWarnings("unchecked") public static void register(IScope scope, IAgent road, IAgent pedestrian ) { ((IList ) 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); } diff --git a/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianSkill.java b/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianSkill.java index ba619ebc38..f852dcb9ff 100644 --- a/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianSkill.java +++ b/miat.gaml.extensions.pedestrian/src/miat/gaml/extensions/skills/PedestrianSkill.java @@ -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; @@ -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", @@ -279,8 +278,6 @@ public void setKappaSFM(final IAgent agent, final double s) { - - @getter (OBSTACLE_SPECIES) public GamaList getObstacleSpecies(final IAgent agent) { return (GamaList) agent.getAttribute(OBSTACLE_SPECIES); @@ -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); @@ -444,8 +439,6 @@ public void setToleranceTarget(final IAgent agent, final double s) { agent.setAttribute(TOLERANCE_TARGET, s); } - - @getter (TARGETS) public IList getTargets(final IAgent agent) { return (IList) agent.getAttribute(TARGETS); @@ -573,7 +566,10 @@ public double walkWithForceModel(IScope scope, IAgent agent, IShape currentTarge IShape bounds, IContainer pedestrianList, IContainer 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) { @@ -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); } @@ -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 obstacles = GamaListFactory.create(Types.AGENT); IList pedestrians = GamaListFactory.create(Types.AGENT); @@ -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; } @@ -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 roadTarget = GamaMapFactory.create(); @@ -794,7 +781,6 @@ public IPath primComputeVirtualPath(final IScope scope) throws GamaRuntimeExcept IShape cRoad = thePath.getRealObject(cSeg); IMap 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()); @@ -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; } @@ -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) { @@ -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); @@ -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++;