0

I try to solve the Knapsack-Problem with the Optaplanner by using drools. Did someone this before? This refers to the example by optaplanner.

Thanks for your help

I have implemented these rules as follows:


rule "weigth" dialect "java" when
$knapsack : Knapsack($capacity : capacity) $weightTotal : Number(intValue > $capacity) from accumulate( Item( $weight : weight), sum($weight) ) then scoreHolder.addHardConstraintMatch(kcontext, $capacity - $weightTotal.intValue()) end

jonas1289
  • 1
  • 1

1 Answers1

0

Presuming Item is your planning entity and that it has a planning variable boolean used, then you 'll want to only check the items that are used == true:

    ... from accumulate(
        Item(used == true,
            $weight : weight),
        sum($weight)
    )
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120