From 77b6fa736f774065a907c3871a991d043bc84baa Mon Sep 17 00:00:00 2001 From: Duc Pham Date: Tue, 10 Aug 2021 15:32:59 +0700 Subject: [PATCH] Initialize `vehicle_ordering` in its getter --- .../extensions/traffic/DrivingOperators.java | 28 +------------------ .../gaml/extensions/traffic/RoadSkill.java | 21 +++++++++++++- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingOperators.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingOperators.java index 387a67f24e..6930b8300c 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingOperators.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingOperators.java @@ -44,32 +44,6 @@ public class DrivingOperators { "as_intersection_graph", "as_distance_graph", "as_edge_graph" }) @no_test public static IGraph spatialDrivingFromEdges(final IScope scope, final IContainer edges, final IContainer nodes) { - final IGraph graph = new GamaSpatialGraph(edges, nodes, scope); - for (final Object edge : edges.iterable(scope)) { - if (edge instanceof IShape) { - IAgent agent = ((IShape) edge).getAgent(); - int numLanes = RoadSkill.getNumLanes(agent); - List> res = new LinkedList<>(); - //TODO: this should be tied to the setter of numLanes - for (int i = 0; i < numLanes; i += 1) { - res.add( - new CustomDualTreeBidiMap(new Comparator() { - @Override - public int compare(IAgent a, IAgent b) { - int r = a.getSpeciesName().compareTo(b.getSpeciesName()); - if (r != 0) { - return r; - } else { - return Integer.compare(a.getIndex(), b.getIndex()); - } - } - }, - Collections.reverseOrder()) - ); - } - RoadSkill.setVehicleOrdering(agent, res); - } - } - return graph; + return new GamaSpatialGraph(edges, nodes, scope); } } diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/RoadSkill.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/RoadSkill.java index 70461538e8..04ee3060a0 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/RoadSkill.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/RoadSkill.java @@ -247,7 +247,26 @@ public static double getTotalLength(final IAgent road) { @getter(VEHICLE_ORDERING) public static List> getVehicleOrdering(final IAgent road) { - return (List>) road.getAttribute(VEHICLE_ORDERING); + List> res = + (List>) road.getAttribute(VEHICLE_ORDERING); + if (res.isEmpty()) { + for (int i = 0; i < getNumLanes(road); i += 1) { + res.add( + new CustomDualTreeBidiMap(new Comparator() { + @Override + public int compare(IAgent a, IAgent b) { + int r = a.getSpeciesName().compareTo(b.getSpeciesName()); + if (r != 0) { + return r; + } else { + return Integer.compare(a.getIndex(), b.getIndex()); + } + } + }, Collections.reverseOrder()) + ); + } + } + return res; } @setter(VEHICLE_ORDERING)