【问题标题】:Possible integer overflow in constraint: linear约束中可能的整数溢出:线性
【发布时间】:2021-01-25 15:28:20
【问题描述】:

亲爱的,我在 python 中使用 CP-SAT。 我有两个变量:

pippo = model.NewIntVar(-93372036854775808,9123372036854775807, 'pippo')
test = model.NewIntVar(-93372036854775808,9123372036854775807, 'test')

以及以下决策变量:

for r in self.all_records:
            memory = {}
            for p in self.all_decisions:
                # create bool decision variables
                memory[p] = model.NewBoolVar('c' + str(r) + self.scenario.decisions[p].name)
            self.decision_var[r] = memory

我有两个限制:

1) test==sum(self.scenario.dataset['is_fraud'][r]*self.decision_var[r][0] for r in self.all_records)

2) pippo == test


                                                                  

如果我删除约束 2) 一切正常,但使用约束 2 我会收到此错误:

Possible integer overflow in constraint: linear {
  vars: 126660
  vars: 126661
  coeffs: -1
  coeffs: 1
  domain: 0
  domain: 0
}
and Status is MODEL_INVALID.

我真的不明白为什么。你能帮帮我吗?

【问题讨论】:

    标签: or-tools cp-sat-solver


    【解决方案1】:

    求解器主动检查可能的溢出。 如果模型有潜在的整数溢出,则视为无效。

    您正在看到此消息。请减少整数变量的界限(int32 min/max 很可能就足够了)。

    【讨论】:

    • 有没有办法避免这种预先检查?我的意思是不执行它
    • 不,在这种情况下求解器并不可靠。所以解决方案很可能是无效的。但是你可以在求解之前调用 validate 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    相关资源
    最近更新 更多