简体   繁体   中英

How can I escape local optima score that repeatedly breaks the same hard constraint in Optaplanner?

I am working on a timetable planning problem with Optaplanner 8.31.0. This is built on top of the Spring Boot School Timetabling Quickstart example. There are 6 hard constraints defined and no soft constraints. During benchmarking the best score I can achieve on a solved dataset is -8hard/0soft. I am trying to get to 0hard/0soft. Looking at the 'Constraint Match Total Best Score' graph from the benchmarker, it always reports the same constraint that is being broken in the final score. Each time, it reports that 8 Teacher Conflict constraints have been broken. The specific constraint mentioned is one of the included constraints with the example:

`

Constraint teacherConflict(ConstraintFactory constraintFactory) {
  // A teacher can teach at most one lesson at the same time.
  return constraintFactory
      .forEachUniquePair(Lesson.class,
          Joiners.equal(Lesson::getTimeslot),
          Joiners.equal(Lesson::getTeacher))
      .penalize(HardSoftScore.ONE_HARD)
      .asConstraint("Teacher conflict");
}

`

I have tried FIRST_FIT, FIRST_FIT_DECREASING and ALLOCATE_ENTITY_FROM_QUEUE construction heuristics with all local search algorithms. The best construction heuristics seem to be FIRST_FIT_DECREASING and ALLOCATE_ENTITY_FROM_QUEUE with the STEP_COUNTING_HILL_CLIMBING local search. These combinations always result in the -8hard score with other combinations and algorithms giving worse scores. I have tried adding another phase to the solver with various move selectors to try to break out of the local optima that it seems to be stuck in. However, I can't seem to find any combination of move selectors and local search algorithm to improve the score.

I found some questions relating to breaking out of local optima such as this where the advice is to check for score traps; introduce various moves; and implement something called iterative local search whereby you can ruin part of the solution and then recreate it randomly.

Due to the fact that the reported hard constraint above comes from the provided school timetable example I don't think my problem is with a score trap. However I could be wrong about that. Is there a chance that the above constraint is falling into a score trap?

I have experimented with various move selectors except for mimic selection and nearby selection . Would these move types help in this situation?

Finally, could anyone suggest how to implement the iterative local search idea where you can destroy part of the solution and recreate it? Perhaps this would be helpful in mixing things up enough to break the local optima?

Any help is much appreciated.

This is a lot of questions for a single StackOverflow question. Next time, please break them up.

Wrt. score trap - not including any soft constraints is the score trap. The original example has plenty of soft constraints which allow the solver to better distinguish between different solutions with the same hard score. (How else is the solver supposed to do that?)

(To be more precise: it doesn't really matter whether the scores are hard or soft. What matters is that if two solutions are different, their scores are also different. This is not always possible, but every time the constraints fail to do that, a score trap is introduced.)

Wrt. nearby selection - I don't see how that could help here; that is predominantly used in vehicle routing, where the concept of a "neighborhood" makes more sense. That said, you may want to try enabling pillar swap and pillar change moves, maybe that will help. Still, avoiding score traps is the better bet.

Wrt. iterative local search - I am not sure why the documentation even mentions that. Implementing that would be a major development effort in OptaPlanner core, one which we have not yet undertaken. That said, I totally agree, this could help somewhat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM