大家好!下面的问题,需要您的帮助
使用CP;
int nbPilots = 50;
int nbLocations = 7;
int nbDays = 30;
远程飞行员= 1..nbPilots;
范围天数= 1..nbDays;
范围位置= 1..nbLocations;
dvar boolean分配[飞行员] [天] [位置];
dvar布尔值休息[飞行员] [天] [位置];
最大化总和(i代表飞行员,j代表天,l代表位置)assign [i] [j] [l];
要遵守{
forall(飞行员中的i,天中的j,地点中的l)(assign [i] [j] [l] + assign [i] [j + 1] [l] + assign [i] [j + 2 ] [l] + assign [i] [j + 3] [l] + assign [i] [j + 4] [l] + assign [i] [j + 5] [l] + assign [i] [j +6] [l] + rest [i] [j + 7] [l] + rest [i] [j + 8] [l] == 9); }
我如何处理[j + 8]也将在<= 30
天之内答案 0 :(得分:0)
using CP;
int nbPilots = 50;
int nbLocations = 7;
int nbDays = 30;
range pilots = 1..nbPilots; range days = 1..nbDays; range locations = 1..nbLocations;
//decision variable/
dvar boolean assign [pilots][days][locations] ; dvar boolean rest [pilots][days][locations];
//objective/
minimize sum(i in pilots, j in days, l in locations)assign[i][j][l];
//constraints/
subject to{
forall(i in pilots, j in days, l in locations:(j+8) in days)
(assign[i][j][l]+assign[i][j+1][l]+assign[i][j+2][l]+assign[i][j+3][l]+
assign[i][j+4][l]+assign[i][j+5][l]+assign[i][j+6][l]+rest[i][j+7][l]+rest[i][j+8][l] == 9);
}
工作正常