Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This was solved using Choco version 2.1. Choco also supports reals, but to make things easy, I used price in cents.

Code Block
import static choco.Choco.*
import choco.kernel.model.variables.integer.IntegerVariable

def m = new choco.cp.model.CPModel()
def s = new choco.cp.solver.CPSolver()

def menu = [
    'Mixed fruit'       : 215,
    'French fries'      : 275,
    'Side salad'        : 335,
    'Hot wings'         : 355,
    'Mozzarella sticks' : 420,
    'Sampler plate'     : 580
]
def varsnumOrdered = new IntegerVariable[menu.size()]
def coeffspriceEach = new int[menu.size()]
def sum = 1505
menu.eachWithIndex { k, v, i ->
    varsnumOrdered[i] = makeIntVar(k, 0, sum.intdiv(v))
    coeffspriceEach[i] = v
}
m.addConstraint(eq(scalar(coeffsnumOrdered, varspriceEach), sum))
s.read(m)

def more = s.solve()
while (more) {
    println "Found a solution:"
    varsnumOrdered.each {
        def v = s.getVar(it)
        if (v.val) println "  $v.val * $v.name"
    }
    more = s.nextSolution()
}

...