You can formulate the problem as follows:
ressources=[a,b,b,a,b,a,a,...] tasks=[a,a,b,b,a,b,a,...]
We can define a cost function to assign task j to output i:
C(i,j)= (ressources[i]==tasks[j])*1+(ressources[i]!=tasks[j])*1000
I choose 1000 ā 1 in case you cannot fulfill the requirements.
Let the restriction be written:
- xi, j = 1 if you assigned task j ressource j and 0 otherwise.
- In addition, xi, j = 0 if ij> K
since you follow resources sequentially and you can wait k period max (ij <= K)
- Only one xi, j can be equal to one for all i, j.
Then you will get the following linear program:
Collapse: Sum (C (i, j) * xi, j)
Topic:
xi, j in {0,1}
The sum (xi, j) = 1 for all i
The sum (xi, j) = 1 for all j
xi, j = 0 if ij> K
xi, j> = 0 otherwise
You may need to fix the restrictions a bit ... after fixing this solution should be optimal, but I'm not sure if the greedy algorithm is not optimal yet.
It is more interesting to use this formulation with more than two different resources.
I hope I understand your question and it helps
Modifications:
I will translate this restriction:
m (i) <= Min {m (i ') st i'> i} + K
Note:
if xi,j =1 then Sum(j*xi,j on i) = j since only one xi,j = 1
"transfer":
with previous notation:
_m(i) <= Min{ m(i') st i'> i } + K_ < = > j <= Min{j' st i'>i and xi',j' =1 } + K_ (OK ?)
New linear constraint:
we have:
xi,j=1 < = > Sum(j*xi,j on j) = j for i and xi',j'=1 < = > Sum(j'*xi',j' on j') = j' for all i'
Consequently:
j <= Min{j' st i'>i and xi',j' =1 } + K_ < = > Sum(j*xi,j on j) <= Min { Sum(j'*xi',j' on j') , i'>i} + K
and less than min, equivalently less than each.
Then a new set of restrictions:
Sum(j*xi,j on j) <= Sum(j'*xi',j' on j') + K for all i' > i
You can add these restrictions to the previous ones, and you will get a linear program .
You can solve this with a simplex algorithm .