d-krupke / cpsat-primer

The CP-SAT Primer: Using and Understanding Google OR-Tools' CP-SAT Solver
https://d-krupke.github.io/cpsat-primer/
Creative Commons Attribution 4.0 International
292 stars 27 forks source link

Add example for circuit constraint #14

Closed ngoc2210 closed 11 months ago

ngoc2210 commented 11 months ago

I don't know if I understood correctly what you mean by extending the full-TSP example, but I have added to this section some code to explain how the TSP problem is solved with a circuit constraint. However, I still don't know how to create the condition that each node is only traversed once with the variables b1, b2, b3.

d-krupke commented 11 months ago

You don't have to do the edges and the variables explicitly. You can do

edge_vars = {(u,v): model.BoolVar(f"e{u}-{v}") for u in V for v in V if u!=v}

We can talk about this in person soon.

ngoc2210 commented 11 months ago

Hi @d-krupke , I added the new example based on your feedback and hope it works. I'm ready to receive further feedback from you.

d-krupke commented 11 months ago

I quickly cleaned the example up. Please compare my changes to yours.