Мне нужно ограничение, которое суммируется в соответствии со следующими индексами:
subject to shift[1]: x[1,2] + x[1,3] + x[1,4] + x[1,5] + x[1,6] >= 8;
subject to shift[2]: x[1,2] + x[2,3] + x[2,4] + x[2,5] + x[2,6] >= 7;
subject to shift[3]: x[1,3] + x[2,3] + x[3,4] + x[3,5] + x[3,6] >= 12;
subject to shift[4]: x[1,4] + x[2,4] + x[3,4] + x[4,5] + x[4,6] >= 9;
subject to shift[5]: x[1,5] + x[2,5] + x[3,5] + x[4,5] + x[5,6] >= 6;
subject to shift[6]: x[1,6] + x[2,6] + x[3,6] + x[4,6] + x[5,6] >= 10;
То, что у меня есть:
param n; # number of shifts possible
param demand {i in 1..n}; # demand of workers at each shift
var x {1..n, 1..n} >= 0; # number of workers per shift
# minimize function
subject to shift {t in 1..n}: sum{j in 1..(n)} x[t,j] >= demand[t];
Это неверно, поскольку дает следующее:
subject to shift[1]: x[1,1] + x[1,2] + x[1,3] + x[1,4] + x[1,5] + x[1,6] >= 8;
subject to shift[2]: x[2,1] + x[2,2] + x[2,3] + x[2,4] + x[2,5] + x[2,6] >= 7;
subject to shift[3]: x[3,1] + x[3,2] + x[3,3] + x[3,4] + x[3,5] + x[3,6] >= 12;
subject to shift[4]: x[4,1] + x[4,2] + x[4,3] + x[4,4] + x[4,5] + x[4,6] >= 9;
subject to shift[5]: x[5,1] + x[5,2] + x[5,3] + x[5,4] + x[5,5] + x[5,6] >= 6;
subject to shift[6]: x[6,1] + x[6,2] + x[6,3] + x[6,4] + x[6,5] + x[6,6] >= 10;