or-tools NewIntVar 在 python 中似乎不支持 int64
or-tools NewIntVar seems not supporting int64 in python
亲爱的,
我正在尝试创建 NewIntVar,其下限和上限等于 int64:
(-9.223.372.036.854.775.808 至 +9.223.372.036.854.775.807)
但是当我尝试求解模型时出现模型无效错误。我发现工作(手动尝试)的最大范围如下 model.NewIntVar(-93.372.036.854.775.808, 9.123.372.036.854.775.807,'pippo')
你知道为什么不支持 int64 吗?
谢谢
斯特凡诺
从源码我看到:
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 或满足这些条件的范围。
亲爱的, 我正在尝试创建 NewIntVar,其下限和上限等于 int64:
(-9.223.372.036.854.775.808 至 +9.223.372.036.854.775.807)
但是当我尝试求解模型时出现模型无效错误。我发现工作(手动尝试)的最大范围如下 model.NewIntVar(-93.372.036.854.775.808, 9.123.372.036.854.775.807,'pippo')
你知道为什么不支持 int64 吗?
谢谢 斯特凡诺
从源码我看到:
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 或满足这些条件的范围。