Versions Compared

Key

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

...

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 vars = new IntegerVariable[menu.size()]
def coeffs = new int[menu.size()]
def sum = 1505
menu.eachWithIndex { k, v, i ->
    vars[i] = makeIntVar(k, 0, sum.intdiv(v))
    coeffs[i] = v
}
m.addConstraint(eq(scalar(coeffs, vars), sum))
s.read(m)

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

It produces this output:

No Format

Found a solution:
  7 * Mixed fruit
Found a solution:
  1 * Mixed fruit
  2 * Hot wings
  1 * Sampler plate

tuProlog

tuProlog is a Java-based light-weight Prolog for Internet applications and infrastructures. It offers numerous integration options: allowing Prolog syntax to be used in the form of theories; programatic theory construction using a Java-based API; and mechanisms to call back into Groovy and Java from Prolog.

...