Reputation: 61
Suppose that you have a car that is required to visit cities A, B, C, D and E in the shortest possible time or distance. But there is order of precedence in which these cities can be visited. For e.g., B must be visited first before you visit “A,” and “E” must be visited first before you can visit “C.” So all of the following solutions are valid: Car -> B, D, E, A, C Or Car -> D, E, B, A, C Or Car -> E, B, A, D, C Following routes will be invalid: Car -> A, B, D, E, C (Constraint violated since B must be visited first before you can visit A) Or Car -> B, D, A, C, E (Constraint violated since E must be visited first before you can visit C)
In Optaplanner, is there any way to enforce such constraints? I think this has to be done while forming a chain. The default chain might have to be manually revisited to enforce such a constraint. But I don’t know how. Any pointers will be greatly appreciated. Vikas
Upvotes: 2
Views: 241
Reputation: 27312
Introduce a shadow variable that keeps the chainIndex
in a chain of a vehicles.
For example: Vehicle A starts in Brussels then goes to Paris then to London. Vehicle B starts in Brussels then goes to Berlin and then to Prague. Then it works like this:
chainIndex
is 1.chainIndex
is 2.chainIndex
is 1.chainIndex
is 2.Adding your constraint by using that chainIndex
and the anchor is then trivial.
Upvotes: 1