Skip to content

Commit

Permalink
Short circuit in AND goal if rollback eventually
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienmaillard committed Oct 13, 2023
1 parent 7440931 commit 91c0b18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ private void rollback(Goal goal){
plan.remove(insertedActivities);
evalForGoal.removeAssociation(associatedActivities);
evalForGoal.removeAssociation(insertedActivities);
evalForGoal.setScore(-(evalForGoal.getNbConflictsDetected().get()));
evalForGoal.setScore(-(evalForGoal.getNbConflictsDetected().orElse(1)));
}

private void satisfyCompositeGoal(CompositeAndGoal goal) {
Expand All @@ -510,6 +510,13 @@ private void satisfyCompositeGoal(CompositeAndGoal goal) {
if (evaluation.forGoal(subgoal).getScore() == 0) {
logger.info("AND goal " + goal.getName() + ": subgoal " + subgoal.getName() + " has been satisfied, moving on to next subgoal");
nbGoalSatisfied++;
} else {
logger.info("AND goal " + goal.getName() + ": subgoal " + subgoal.getName() + " has NOT been satisfied");
if(goal.shouldRollbackIfUnsatisfied()){
logger.info("AND goal " + goal.getName() + ": stopping goal satisfaction after first failure, remove shouldRollbackIfUnsatisfied(true) on AND goal to maximize satisfaction instead of early termination");
break;
}
logger.info("AND goal " + goal.getName() + ": moving on to next subgoal (trying to maximize satisfaction)");
}
}
final var goalIsSatisfied = (nbGoalSatisfied == goal.getSubgoals().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void testAndWithBackTrack(){
Assertions.assertTrue(TestUtility.activityStartingAtTime(plan, t1hr, actTypeControllable));
Assertions.assertTrue(TestUtility.activityStartingAtTime(plan, t2hr, actTypeControllable));
Assertions.assertEquals(plan.getActivities().size(), 2);
assertEquals(4, problem.getSimulationFacade().countSimulationRestarts());
assertEquals(2, problem.getSimulationFacade().countSimulationRestarts());
}

@Test
Expand Down

0 comments on commit 91c0b18

Please sign in to comment.