简体   繁体   English

如何使用 OR-tools 的 CP-SAT 求解器构建我自己的全局约束?

[英]How to build my own global constraint with the CP-SAT solver of OR-tools?

I am a phd candidate in data mininig, and i have to create a global constraint with ORtools for a data mining purpose.我是数据挖掘的博士候选人,我必须使用 ORtools 创建一个全局约束以用于数据挖掘目的。

The problem is that there is a lack of documentation about creating your own global constraint with CP-Sat in the inte.net, and i don't know how to start.问题是在 inte.net 中缺少关于使用 CP-Sat 创建您自己的全局约束的文档,我不知道如何开始。

It is obviously possible, but very tedious, and very complex.这显然是可能的,但非常乏味且非常复杂。

Writing a new constraint implies:编写新约束意味着:

  • extending the proto to support the constraint扩展原型以支持约束
  • writing the input validation编写输入验证
  • writing the solution checker编写解决方案检查器
  • writing the loading (into CP-SAT engine) code编写加载(到 CP-SAT 引擎)代码
  • writing the presolve rules编写预求解规则
  • writing the propagation code.编写传播代码。 Which is complex as every deduction needs to be fully explained.这很复杂,因为每个推论都需要得到充分解释。
  • writing the linearization/cut generation code编写线性化/剪切生成代码

The last 3 items are extremely error prone, and very hard to debug, as the effect of cuts and explanations are delayed, and sometimes never used.最后 3 项极易出错,并且很难调试,因为剪辑和解释的效果会延迟,有时甚至根本不会使用。

For these reason, I recommend expanding the constraint into smaller ones.出于这些原因,我建议将约束扩展为更小的约束。 In fact, most of the CP constraints are expanded (alldiff, element, table, reservoir, inverse, automaton, some products, some modulos).事实上,大部分CP约束都是展开的(alldiff、element、table、reservoir、inverse、automaton、一些乘积、一些模数)。

You can also submit a feature request for a new constraint.您还可以提交新约束的功能请求。 It can happen if it is useful/general enough.如果它足够有用/足够通用,它就会发生。

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM