或工具NewIntVar似乎不支持python中的int64

时间:2020-04-17 13:15:01

标签: or-tools

亲爱的, 我正在尝试创建NewIntVar,其下限等于int64的上限:

(-9.223.372.036.854.775.808至+9.223.372.036.854.775.807)

但是当我尝试求解模型时,出现模型无效错误。我发现可以工作的最大范围(手动尝试)是以下模型.NewIntVar(-93.372.036.854.775.808,9.123.372.036.854.775.807,'pippo')

您知道为什么不支持int64吗?

谢谢 斯特凡诺

1 个答案:

答案 0 :(得分:2)

从源代码中,我看到:

https://github.com/google/or-tools/blob/stable/ortools/sat/cp_model_checker.cc#L90

  const int64 ub = proto.domain(proto.domain_size() - 1);
  if (lb < kint64min + 2 || ub > kint64max - 1) {
    return absl::StrCat(
        "var #", v, " domain do not fall in [kint64min + 2, kint64max - 1]. ",
        ProtobufShortDebugString(proto));
  }

  // We do compute ub - lb in some place in the code and do not want to deal
  // with overflow everywhere. This seems like a reasonable precondition anyway.
  if (lb < 0 && lb + kint64max < ub) {
    return absl::StrCat(
        "var #", v,
        " has a domain that is too large, i.e. |UB - LB| overflow an int64: ",
        ProtobufShortDebugString(proto));
  }

所以这些值实际上是:

  • cp_model.INT_MIN + 2(-9223372036854775806)
  • cp_model.INT_MAX-1(9223372036854775806)

max-min不能超过kint64max(9223372036854775807)

您可以改用INT32_MAX和INT32_MIN或满足这些条件的范围。