From 4681192eccbea08097a3217779d5171db4c29d22 Mon Sep 17 00:00:00 2001 From: ptaillandier Date: Wed, 8 Sep 2021 13:31:50 +0700 Subject: [PATCH] add info on the fact that there is still a road in random drive --- .../gaml/extensions/traffic/DrivingSkill.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java index ff1ad4b8ee..f8ad333d31 100644 --- a/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java +++ b/simtools.gaml.extensions.traffic/src/simtools/gaml/extensions/traffic/DrivingSkill.java @@ -1328,7 +1328,7 @@ public IPath primComputePathFromNodes(final IScope scope) throws GamaRuntimeExce examples = { @example ("do drive_random init_node: some_node;") } ) ) - public void primDriveRandom(final IScope scope) throws GamaRuntimeException { + public Boolean primDriveRandom(final IScope scope) throws GamaRuntimeException { IAgent vehicle = getCurrentAgent(scope); GamaSpatialGraph graph = (GamaSpatialGraph) scope.getArg("graph", IType.GRAPH); Map roadProba = (Map) scope.getArg("proba_roads", IType.MAP); @@ -1347,7 +1347,7 @@ public void primDriveRandom(final IScope scope) throws GamaRuntimeException { setNextRoad(vehicle, chooseNextRoadRandomly(scope, graph, initNode, roadProba)); } - moveAcrossRoads(scope, true, graph, roadProba); + return moveAcrossRoads(scope, true, graph, roadProba); } @action( @@ -1603,7 +1603,7 @@ private void updateVehicleOrdering(final IScope scope, final int newLowestLane, setLowestLane(vehicle, newLowestLane); } - private void moveAcrossRoads(final IScope scope, + private Boolean moveAcrossRoads(final IScope scope, final boolean isDrivingRandomly, final GamaSpatialGraph graph, final Map roadProba) { @@ -1623,15 +1623,15 @@ private void moveAcrossRoads(final IScope scope, if (!isDrivingRandomly && loc.equals(finalTarget.getLocation())) { // Final node in path clearDrivingStates(scope); - return; + return true; } else if (loc.equals(targetLoc)) { // Intermediate node in path IAgent newRoad = getNextRoad(vehicle); - if (newRoad == null) return; + if (newRoad == null) return false; GamaPoint srcNodeLoc = (GamaPoint) RoadSkill.getSourceNode(newRoad).getLocation(); boolean violatingOneway = !loc.equals(srcNodeLoc); // check traffic lights and vehicles coming from other roads if (!readyToCross(scope, vehicle, currentTarget, newRoad)) { - return; + return true; } // Choose a lane on the new road @@ -1642,7 +1642,7 @@ private void moveAcrossRoads(final IScope scope, int lowestLane = (int) actionCL.executeOn(scope); laneAndAccPair = MOBIL.chooseLane(scope, vehicle, newRoad, lowestLane); if (laneAndAccPair == null) { - return; + return true; } double newAccel = laneAndAccPair.getRight(); double newSpeed = computeSpeed(scope, newAccel, newRoad); @@ -1657,7 +1657,7 @@ private void moveAcrossRoads(final IScope scope, if (currentRoad != null && goingToBlock) { blockIntersection(scope, currentRoad, newRoad, currentTarget); } - return; + return true; } IStatement.WithArgs actionOnNewRoad = context.getAction("on_entering_new_road"); actionOnNewRoad.executeOn(scope); @@ -1668,7 +1668,7 @@ private void moveAcrossRoads(final IScope scope, actionImpactEF.setRuntimeArgs(scope, argsEF); remainingTime = (Double) actionImpactEF.executeOn(scope); if (remainingTime <= 0.0) { - return; + return true; } // Find the new next road in advance in order to look for leaders further ahead @@ -1705,7 +1705,9 @@ private void moveAcrossRoads(final IScope scope, int lowestLane = laneAndAccPair.getLeft(); double accel = laneAndAccPair.getRight(); remainingTime = moveAcrossSegments(scope, accel, remainingTime, lowestLane); + } + return true; }