OR Tool - OnlyEnforceIf problem when used in constraint

35 views Asked by At

I have the following decision boolean variables x[t] and w[t], and an auxiliary variable p[t].

p[t] = p[t - 1] + w[t] * constant

p[t] <= Max Value

But I have also a condition where if x[t - 1] == 1 then p[t] will reset to 0.

I'm using OnlyEnforceIf as following:

model.Add(self.p[e, t] == 0).OnlyEnforceIf(x[e, t - 1] == 1)

But I am getting the following error

'Constraint' object has no attribute 'OnlyEnforceIf'

1

There are 1 answers

0
Laurent Perron On

as documented on this doc on channeling.

  x_is_one = model.NewBoolVar('x_is_one')
  model.Add(x == 1).OnlyEnforceIf(x_is_one)
  model.Add(x != 1).OnlyEnforceIf(x_is_one.Not())
  model.Add(self.p[e, t] == 0).OnlyEnforceIf(x_is_one)