/******************************************************************** ** Optimizes the group assignments (mapping abstract groups to ** ** opt groups) due to the provided distances that shall be walked. ** ** ** ** n: number of groups - must be a multiple of 3 ** ** k: number of predefined groups - must be n/3 ** ** ** ** pre_abs: ids of abstract groups that are predefined ** ** (main course gruops) ** ** pre_opt: ids of opt groups that are mapped to predefined ** ** abstract groups ** ** The mapping is done like pre_abs[i] -> pre_opt[i] ** ** ** ** wd: walking distances ** ** wd[i][j] := dist(j, id_hs_loc(i)) ** ** + dist(j, id_hs_loc(guest1(i))) ** ** + dist(j, id_hs_loc(guest2(i))) ** ** ** ** ** ** Output is written to the output stream ** ** - decicion variables are prefixed with "--x--", follow by the ** ** indeizes i and j divided by ":", followed by "--" followed ** ** by the value; every value is written to a ** ** new linear ** ** example: x[i][j] = a --> "--x--i:j--a" ** ** - the objective value is output as "--o--a" where a is the ** ** objective value ** ** ** ********************************************************************/ /*******************************************************************/ /************************** linear program *************************/ /*******************************************************************/ /* number of groups -> loaded as data */ param n, integer, > 0; /* number of predefined mappings */ param k, integer, > 0; /* index sets */ set I := 1..n; set J := 1..n; set K := 1..k; /* walking distances -> loaded as data */ param wd{i in I, j in J}, >= 0; /* mapping of predefined abstract to opt groups -> loaded as data */ /* pre_abs[i] is mapped to pre_opt[i] */ param pre_abs{l in K}, integer, >= 0; param pre_opt{l in K}, integer, >= 0; /* decision variables */ var x{i in I, j in J}, >= 0, binary; /* row sum constraint */ s.t. rowSum{i in I}: sum{j in J} x[i, j] = 1; /* col sum constraint */ s.t. colSum{j in J}: sum{i in I} x[i, j] = 1; /* predefined groups groups */ s.t. predefined{l in K}: x[pre_abs[l],pre_opt[l]] = 1; /* objective */ minimize obj: (sum{i in I, j in J} wd[i,j] * x[i,j]); solve; /* output */ printf{i in I, j in J} "--x--%d:%d--%d\n", i, j, x[i,j]; printf "--o--%d\n", obj; /*******************************************************************/ /****************************** data *******************************/ /*******************************************************************/ data; /* number of groups */ param n := INSERT_N; /* number of predefined groups */ /* assert k = n/3 */ param k := INSERT_K; /* walking dists! not dists! */ param wd: INSERT_WD; /* mapping of predefined abstract to opt groups */ /* assert len pre_abs = k = len pre_opt */ param pre_abs := INSERT_PRE_ABS; param pre_opt := INSERT_PRE_OPT; end;