问题
I am trying to model the operation of a system component, the component will have two operating modes, let's call them 1 and 2, plus the idle mode 0
There is no limit on idling, but each operating mode will last for exactly 3 time-series points, so x_{i}= 1 means x_{i+1} = x_{i+2} = 1 (cannot post images, please use the link below for the equation) operation mode 1
same goes for operating mode 2.
For example. 011102220 is valid, but 01110220 is not.
111111 or 222222 are not valid, but this is taken care of in other resource related constraints (the system will not have enough resource to operate for more than 3 time-series points), so as long as the issue regarding to forcing three consecutive 1s or 2s in the variable array is address, it should be fine.
Thanks in advance,
回答1:
Let's simplify the problem somewhat: we assume we have only binary values, meaning, that we only care about 0's and 1's.
Introduce a new auxiliary binary vector start_block
. This vector mark beginnings of new blocks.
A non-zero value within this binary-vector is part of the constraints, which define the implication of a block.
Let's call the solution-vector X
.
The implication is done in a pairwise manner.
# zero-order logic
start_block[x] -> X[x]
start_block[x] -> X[x+1]
start_block[x] -> X[x+2]
<=>
# zero-order logic ( a->b <-> !a V b )
!start_block[x] V X[x]
!start_block[x] V X[x+1]
!start_block[x] V X[x+2]
<=>
# linear expression
(1 - start_block[x]) + X[x] >= 1
(1 - start_block[x]) + X[x+1] >= 1
(1 - start_block[x]) + X[x+2] >= 1
Do this for the whole decision-variable dimension of X
(caring about borders).
Keep in mind, that this only says: if there is a 1 in X
, it's part of a block of size >=3. It can be a block of 4. As i don't know your model exactly, that's the most general approach i can offer. Of course you can tune this further for your case!
Generalizing this for integer-variables should not be too hard, but might introduce new auxiliary variables.
回答2:
Runs of length exactly three can be modeled as:
y(t+1) >= y(t)-y(t-1)
y(t+2) >= y(t)-y(t-1)
1-y(t+3) >= y(t)-y(t-1)
where y(t) is a binary variable. Runs of length at least three can be modeled by dropping the last constraint:
y(t+1) >= y(t)-y(t-1)
y(t+2) >= y(t)-y(t-1)
来源:https://stackoverflow.com/questions/44496473/block-of-consecutive-variables-to-have-same-value-in-mixed-integer-linear-progra