I have few tasks t1, t2, t3, t4, t5 which need to be assigned to resources r1, r2, the tasks are located across multiple districts d1, d2, for example t1, t2, t3 are located in district d1 and t4, t5 are located in district d2. Each task have some duration like t1 : 3 hours, t2 : 3 hours, t3 : 4 hours, t4 : 4 hours, t5 : 5 hours also each resource have 8 hours of daily capacity.

Here my question is how shall I create decision variables and constraints considering following requirements

  1. How do I enforce that in a day resource can only be in one district ? In other words, if resource is in district d1 then he can only attend t1, t2, t3
  2. task t3 can only be assigned to resource r1.

1 Answer 1


Start by defining the appropriate binary variable: $x_{ij}=1$ if and only if task $i$ is assigned to resource $j$.

  • A given task can only be assigned to one resource: $$ \sum_j x_{ij}=1 \quad \forall i $$
  • Daily capacity for each resource: $$ \sum_i \Delta_i x_{ij}\le 8 \quad \forall j $$ ($\Delta_i$ denotes the duration of task $i$)
  • task $t_3$ must be assigned to resource $r_1$: $$ x_{t_3,r_1}=1 $$

Can you take it from here ? I will leave you with question 1., which you should be able to do if you understand the above.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.