【问题标题】:How to check if a custom solution violates any constraints in ORtools如何检查自定义解决方案是否违反 ORtools 中的任何约束
【发布时间】:2021-12-29 04:05:07
【问题描述】:

我正在使用 ORTOOLs 来解决 CP 问题。但是,该解决方案并不是我所期望的,并且存在更好的解决方案。因此,我想检查自定义解决方案是否可行,如果不可行,则检查违反了哪个约束。 反正我能做到吗? 感谢您的所有帮助。

【问题讨论】:

    标签: python or-tools constraint-programming


    【解决方案1】:

    目前只有 CP-SAT 求解器支持不可行性解释。

    在 Python 中:

    if status == cp_model.INFEASIBLE:
        print(f'{solver.SufficientAssumptionsForInfeasibility()}')
    

    见:https://github.com/google/or-tools/blob/stable/ortools/sat/samples/assumptions_sample_sat.py 要么 https://github.com/google/or-tools/blob/stable/ortools/sat/samples/assumptions_sample_sat.cc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-23
      • 2020-07-03
      • 1970-01-01
      • 2015-08-30
      • 2020-05-30
      • 2020-08-14
      • 1970-01-01
      • 2021-07-16
      相关资源
      最近更新 更多