我正在尝试为目标建模。
这是分配问题的一个特例,我想最小化完成所有工作所需的工人。因此,所有工作都必须完成,但并非所有工人都必须做某事。
约束:
s.t. AllJobsHaveToBeDone {j in Jobs}:
sum {w in Workers} WhichWorkerDoWhichJob[w,j]=1;
s.t. JustDoWhatHeCanDo {w in Worker, j in Jobs}:
WhichWorkerDoWhichJob[w,j] <= WhatCanHeDo[e, j];
但我就是不能尽量减少目标中的工人数量。有没有办法计算变量中实际从事工作的工人,然后最小化该变量?
我对它很新,有什么建议吗?
set Jobs;
set Workers;
param WhatCanHeDo{w in Workers, j in Jobs}, binary;
param M;
var WhichWorkerDoWhichJob {w in Workers, j in Jobs}, binary;
var Y{w in Workers}, binary;
s.t. AllJobsHaveToBeDone {j in Jobs}:
sum {w in Workers} WhichWorkerDoWhichJob[w,j]=1;
s.t. JustDoWhatHeCanDo {w in Workers, j in Jobs}:
WhichWorkerDoWhichJob[w,j] <= WhatCanHeDo[w, j];
s.t. Newrule{w in Workers, j in Jobs}:
WhichWorkerDoWhichJob[w,j] >= M * Y[w];
minimize target: sum{w in Workers} Y[w];
solve;
printf "------------------------------------------\n" ;
#To check the values of each Y[w] -> but all will be zeros.
for{w in Workers}
printf "%s %s\n",w,Y[w];
for{w in Workers, j in Jobs:
WhichWorkerDoWhichJob[w,j]=1}
printf "%s do %s job. \n",w,j;
data;
set Jobs:= j1 j2 j3 j4 j5 j6 j7 j8;
set Workers:=w1 w2 w3 w4 w5;
param WhatCanHeDo: j1 j2 j3 j4 j5 j6 j7 j8 :=
w1 1 0 0 0 1 1 1 0
w2 1 1 0 1 0 1 0 0
w3 1 0 1 0 1 0 1 0
w4 1 1 1 0 0 0 1 1
w5 1 0 1 0 0 1 0 0
;
param M:=10000;
end;
有什么新的提示或建议吗?