Search code examples
optaplanner

how to dynamically add / remove constraints in optaplanner


We are using optaplanner for VRP. One challenge we have is many of our constraints are specific to a local area. For example, in one state Technician can't cross state line where as in other states technicians can cross state line.

Under such scenario we want create a generic solution where user can add hard constraints and generic solution pick that constraint from data base to provide solution.

Has anyone designed such a solution?

Thanks


Solution

  • Either use different <scoreDrl> elements:

    • general.drl
    • ny-specific.drl
    • ca-specific.drl
    • tx-specific.drl
    • ...

    Or if you need to solve a single dataset that contains both tx and ny employees, then do something like

    class Employee {
        State state;
    }
    
    rule noCross
    when
        Employee(state = "Texas") // doesn't apply to California
        // ... crosses lines
    then
        ...
    end