drools-planneroptaplanner

How to solve many to many relationship using OptaPlanner?


How do we solve many to many problems using OptaPlanner 6? For example, in cloud balancing example, what do we need to do if we want to put each process on multiple computers/threads? More like parallel execution of the process.


Solution

  • The same way as you solve it if you want to store a many2many relationship in a relational database: create an extra Class.

    For example: In cloud balancing, create a class Assignment that has a many2one relationship to Process and a many2one relationship to Computer. In curriculum course scheduling, this is already the case: there is a many2many relationship between Course and Period/Room, which is implemented by the class Lecture.

    Now, where it becomes interesting is if the number of that many2many-class instances is variable during planning, because that means that your number of planning entities is variable. In curriculum course scheduling, this is not the case: each Course has a fixed amount of lectures (and each Lecture has an indexInCourse) and those lectures are initialized before solve() is called.

    If the number of planning entities is variable: OptaPlanner 6.0 is designed for that (there is plumbing in ScoreDirector, Selector, ...), but not tested yet. In a future version we'll add such an example and integration tests and stress tests...