Skip to content

Instantly share code, notes, and snippets.

@bokner
Last active June 5, 2024 19:30
Show Gist options
  • Save bokner/dc02b77dd582c9f974f0c6244f494ff2 to your computer and use it in GitHub Desktop.
Save bokner/dc02b77dd582c9f974f0c6244f494ff2 to your computer and use it in GitHub Desktop.
alias CPSolver.IntVariable
alias CPSolver.Model
alias CPSolver.Constraint
alias CPSolver.Constraint.Factory
alias CPSolver.Constraint.NotEqual
alias CPSolver.Constraint.Equal
import CPSolver.Variable.View.Factory # For linear
x = IntVariable.new(0..3, name: "x")
y = IntVariable.new(0..3, name: "y")
z = IntVariable.new(0..3, name: "z")
{sum_var, add_constraint} = Factory.add(x, y)
{:ok, res} = CPSolver.solve_sync(Model.new([x, y, z], [Equal.new(z, sum_var), add_constraint]))
## Alternatively:
'''
x = IntVariable.new(0..3, name: "x")
y = IntVariable.new(0..3, name: "y")
z = IntVariable.new(0..3, name: "z")
{:ok, res} = CPSolver.solve_sync(Model.new([x, y, z], [Sum.new(z, [x, y])]))
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment