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 10, 2023
1 parent 0f52861 commit a1bece1
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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 @@ -467,6 +467,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, use shouldRollbackIfUnsatisfied() 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

0 comments on commit a1bece1

Please sign in to comment.