6

I am working on a geometry problem with the OR-Tools constraint programming tools.

Could one of you tell me the procedure to create a custom constraint? I dont really understand demon, model visitor behavior...

Also, can any type of constraint be inserted?

Thank you in advance

4
  • Please elaborate your question: What kind of constraint do you want to add? What have you tried, and what feedback did you get? Commented Jan 8, 2018 at 8:37
  • I use Or-tools to generate polygons under certain constraints. I would like to know if it is possible to create custom constraints using functions of other libraries (I think especially in my case Boost and more particularly Boost geometry). Considering (Xi, Yi) the coordinates of the points of a polygon. I would like to create a constraint of this type: void AreaConstraint (Solver * solver, IntVar * X1, IntVar * Y1, IntVar * X2, IntVar * Y2, IntVar * X3, IntVar * Y3, IntVar * X4, IntVar * Y4, IntVar * X5, IntVar * Y5, IntVar * X6 , IntVar * Y6) Commented Jan 8, 2018 at 8:40
  • int64 x [] = {X1 -> Value (), X2 -> Value (), X3 -> Value (), X4 -> Value (), X5 -> Value (), X6 -> Value ()}; int64 y [] = {Y1 -> Value (), Y2 -> Value (), Y3 -> Value (), Y4 -> Value (), Y5 -> Value (), Y6 -> Value ()}; -> there I have a problem, I obviously do not have the "right" to access Xi -> Value (). Commented Jan 8, 2018 at 8:41
  • I tried to create a class in the same style as : class AllDifferentExcept : public Constraint { ....} Commented Jan 8, 2018 at 8:50

1 Answer 1

2

To write a constraint, you need to understand that during search, variables are not instantiated (domain is reduced to a single value). Therefore, calling Value() does not work.

You can access the current domain (min, max, list of possible values, and then you can write deduction rule from there).

See https://github.com/google/or-tools/blob/stable/examples/cpp/dobble_ls.cc.

Now, the CP solver is replaced by the CP-SAT solver, which does not allow writing custom constraints. In that case, maybe you can express you constraints with boolean logic, and arithmetic operators.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.