optaplannerplanning

Optaplanner passing a variable through planning solution


I have a planning entity Request and a planning variable as taxi.

I want to pass the Date(a particular day) to the drools file for cab allocation.

I tried adding Date to the planning solution but the rule always failed where i captured the Date.

Planning Solution

@PlanningSolution

public class NRequest extends AbstractPersistable implements Solution<HardMediumSoftScore> {


private Date date;  

private List<Cabs> list_cabs;

@PlanningEntityCollectionProperty
private List<Requests> list_req;
.....
.....
}

Drools file

rule "Check overlap Shift1"

when    
    $date:Date()     
then

    scoreHolder.addHardConstraintMatch(kcontext, 3);
    scoreHolder.addSoftConstraintMatch(kcontext, 2);
end

Solution

  • I'd suggest the NurseRosteringParametrization appoach.

    The FooSolution class has a single FooParameterization class, which holds things like the date or the planning window starting date or the specific score weights etc. Then simply match on FooParameterization in your drools rules (you know there is only 1 instance) and that's it. Make sure that FooParameterization is part getProblemFacts() or @ProblemFactProperty