jonas1289
jonas1289

Reputation: 1

Drools Knapsack Optaplanner

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

Upvotes: 0

Views: 384

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

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)
    )

Upvotes: 0

Related Questions