I have used constraint solvers in the past, and they are truly magical in what they can do. The problem is that there are not many available resources for the novice. Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts. Which is a shame, because I think huge swaths of problems could be solved by thes…
I think the reason why these tools are not accessible as they could be is because the vast majority of solvers are MIPs (Mixed Integer Programming) based, meaning the domain need to be written down using mathematical equations. This in turn means a user would need to be familiar with both the domain and mathematics in order to correctly write constraints. That being said, MIPs are not the only kind of solvers. There…
A practical introduction to constraint programming using CP-SAT and Python
21–30 of 41 posts
Re: A practical introduction to constraint programming using CP-SAT and Python
#22I have used constraint solvers in the past, and they are truly magical in what they can do. The problem is that there are not many available resources for the novice. Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts. Which is a shame, because I think huge swaths of problems could be solved by thes…
I have about 5 years of experience in MiniZinc solving scheduling problems but sadly all that code is locked behind closed doors never to be open sourced. I would love put together some fully worked constraint programming examples complete with containerisation / visualisation/ modeling etc but the barrier to doing so is finding problems that are actually worth solving and have open source data to work on.
Re: A practical introduction to constraint programming using CP-SAT and Python
#23I used a lot of solvers in the early 2000s in my Operations Research master after my econometrics study. While now working on software (web) that uses python I’m thrilled to see these deep dives on this subject! I love the subject and reading this brought back a lot of memories. Also the realization that translating constraints to a model (variables, structure etc) is 90% of the work and the most difficult part.
I used program called GAMS in mine. Its syntax structure is totally free form! https://www.gams.com/latest/docs/UG_GAMSPrograms.html#UG_GAM...
Re: A practical introduction to constraint programming using CP-SAT and Python
#24How does this compare with mixed integer programming? For problems in physics
The advantage of CP-SAT is that it handles boolean and integer variables and constraints much more efficiently than a MIP solver, specially higher-level constraints like all_different.
Re: A practical introduction to constraint programming using CP-SAT and Python
#25I have used constraint solvers in the past, and they are truly magical in what they can do. The problem is that there are not many available resources for the novice. Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts. Which is a shame, because I think huge swaths of problems could be solved by thes…
> Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts Exactly. I was looking at using a sat solver for a rules engine and couldn't make heads or tails how to use it. After alot of deduction, got a basic POC working, but couldn't extend it to what was actually needed. But the gulf between toy implemen…
Re: A practical introduction to constraint programming using CP-SAT and Python
#26I have used constraint solvers in the past, and they are truly magical in what they can do. The problem is that there are not many available resources for the novice. Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts. Which is a shame, because I think huge swaths of problems could be solved by thes…
You totally nailed it. The actual syntax / API of constraint solvers are so simple they can be learned in no time at all. What actually takes time and expertise is modelling problems in this fashion and there are almost 0 real world (in size and complexity) examples out there for others to reference. I have about 5 years of experience in MiniZinc solving scheduling problems but sadly all that code is locked behind cl…
I’d definitely be interested in that.
Re: A practical introduction to constraint programming using CP-SAT and Python
#27I have a short chapter on using MiniZinc with Python in one of my old books that I am currently rewriting https://leanpub.com/pythonai/read#constraint-programming-wit... (link directly to this chapter online) MiniZinc is a constraint programming system. There is a good Coursera class using MiniZinc.
Re: A practical introduction to constraint programming using CP-SAT and Python
#28Earlier quoted context omitted.
I think the reason why these tools are not accessible as they could be is because the vast majority of solvers are MIPs (Mixed Integer Programming) based, meaning the domain need to be written down using mathematical equations. This in turn means a user would need to be familiar with both the domain and mathematics in order to correctly write constraints. That being said, MIPs are not the only kind of solvers. There…
What’s a real world thing or two that this could solve vs writing code
For example, to do the "Some employees are qualified to do either role, but others can only be a cashier, or a restocker." constraint in the article, it would be written like this:
def required_skill(constraint_factory: ConstraintFactory):
return (constraint_factory.for_each(Shift)
.filter(lambda shift: shift.required_skill not in shift.employee.skills)
.penalize(HardSoftScore.ONE_HARD)
.as_constraint("Missing required skill")
)
Some examples taken from Timefold quickstarts:- Employee scheduling (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)
- Vehicle routing (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)
- School timetabling (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)
Re: A practical introduction to constraint programming using CP-SAT and Python
#29I have used constraint solvers in the past, and they are truly magical in what they can do. The problem is that there are not many available resources for the novice. Most of the material you can find is how to solve sudoku (the hello world of the space) or highly technical primary research literate meant exclusively for domain experts. Which is a shame, because I think huge swaths of problems could be solved by thes…
Re: A practical introduction to constraint programming using CP-SAT and Python
#30I have a short chapter on using MiniZinc with Python in one of my old books that I am currently rewriting https://leanpub.com/pythonai/read#constraint-programming-wit... (link directly to this chapter online) MiniZinc is a constraint programming system. There is a good Coursera class using MiniZinc.
Do you have a link to the Coursera course?
https://www.coursera.org/learn/basic-modeling
https://www.coursera.org/learn/advanced-modeling
https://www.coursera.org/learn/solving-algorithms-discrete-o...
They are indeed excellent and highly enjoyable.