问题
Dears, I'm trying to create NewIntVar with lower bound an higher bound equal to the one of the int64:
(-9.223.372.036.854.775.808 to +9.223.372.036.854.775.807)
But I get the Model invalid error when I try to solve the model. The max range I found as working (trying manually) is the following model.NewIntVar(-93.372.036.854.775.808, 9.123.372.036.854.775.807,'pippo')
Do you know why int64 is not supported?
Thanks Stefano
回答1:
From the source code I see:
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));
}
So the values actually are:
- cp_model.INT_MIN + 2 (-9223372036854775806)
- cp_model.INT_MAX - 1 (9223372036854775806)
And max-min can't exceed kint64max
(9223372036854775807)
You could use INT32_MAX and INT32_MIN instead or a range that satisfies these conditions.
来源:https://stackoverflow.com/questions/61272596/or-tools-newintvar-seems-not-supporting-int64-in-python