【问题标题】:Is it possible to modify a cp_sat model after construction?是否可以在构建后修改 cp_sat 模型?
【发布时间】:2019-03-22 11:02:42
【问题描述】:

我有一个模型用于查找特定类别的整数(“Keith 数”),它运行良好,但速度很慢,因为它需要多次构建新模型。有没有办法更新模型,特别是改变约束中的系数。换句话说,改变模型以匹配不同的mat,而不重构整个事物?

def _construct_model(self, mat):
  model = cp_model.CpModel()
  digit = [model.NewIntVar(0, 9, f'digit[{i}]') for i in range(self.k)]

  # Creates the constraint.
  model.Add(sum([mat[i] * digit[i] for i in range(self.k)]) == 0)

  model.Add(digit[0] != 0)
  return model, digit

【问题讨论】:

    标签: constraint-programming or-tools


    【解决方案1】:

    是的,但你自己一个人。

    您可以从模型中访问底层的cp_model_proto protobuf,并直接对其进行修改。

    他目前没有计划在 cp_model API 之上添加修改 API。

    【讨论】:

      猜你喜欢
      • 2014-10-28
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      相关资源
      最近更新 更多