0

I would like to simplify a group of repetitive constraints that appear in a model.
The aim is to ensure that a group of experts is staffed with a quantity of skills, each expert having 0..n skills.
Currently, I have to repeat the constraint for each skill in the set, but there is surely a way to simplify this with one "generic" constraint...

Relevant bit:

%Each group needs at least one expert with skill 1
constraint forall(g in Groups) (sum(e in Experts where expertskills[e,1]=1 \/ expertskills[e,2]=1) (assignment[g,e,1])>=1);
%Each group needs at least one expert with skill 2
constraint forall(g in Groups) (sum(e in Experts where expertskills[e,1]=2 \/ expertskills[e,2]=2) (assignment[g,e,2])>=1);
etc...
user1454590
  • 71
  • 1
  • 3
  • I guess that you can combine an extra loop (s in 1..num_skill) and then use bool2int() in the sum instead of the where clause. It would be easier to give detailed advice if you show a complete (but small) model. – hakank Mar 01 '15 at 08:06
  • Thank you. I did not realize I could use nested "forall". With that, it is already looking better: `constraint forall(g in Groups) ( forall(s in Skills) (sum(e in Experts where expertskills[e,1]=s \/ expertskills[e,2]=s) (assignment[g,e,s])>=1) );` Now I need to figure out out to make the index / disjunctions in the expert skills array independent of the number of skills. I can share the model with you Hakank, but would prefer to do it privately. – user1454590 Mar 01 '15 at 10:17
  • Looks like it can be made completely generic this way: `%Each group requires at least n experts with skill s %groupskills[g,s] is the amount of skills s required in group g constraint forall(g in Groups) ( forall(s in Skills) (sum(e in Experts, i in Skills where expertskills[e,i]=s) (assignment[g,e,s])>=groupskills[g,s]) );` Tested. Works. – user1454590 Mar 01 '15 at 12:17

0 Answers0