Last active
June 5, 2024 19:30
-
-
Save bokner/dc02b77dd582c9f974f0c6244f494ff2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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