Skip to content

Commit

Permalink
Initialize vehicle_ordering in its getter
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc0711 committed Aug 10, 2021
1 parent 8d8d8eb commit 77b6fa7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
Expand Up @@ -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<OrderedBidiMap<IAgent, Double>> 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<IAgent, Double>(new Comparator<IAgent>() {
@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);
}
}
Expand Up @@ -247,7 +247,26 @@ public static double getTotalLength(final IAgent road) {

@getter(VEHICLE_ORDERING)
public static List<OrderedBidiMap<IAgent, Double>> getVehicleOrdering(final IAgent road) {
return (List<OrderedBidiMap<IAgent, Double>>) road.getAttribute(VEHICLE_ORDERING);
List<OrderedBidiMap<IAgent, Double>> res =
(List<OrderedBidiMap<IAgent, Double>>) road.getAttribute(VEHICLE_ORDERING);
if (res.isEmpty()) {
for (int i = 0; i < getNumLanes(road); i += 1) {
res.add(
new CustomDualTreeBidiMap<IAgent, Double>(new Comparator<IAgent>() {
@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)
Expand Down

0 comments on commit 77b6fa7

Please sign in to comment.