我正在开发一个项目,其中我在节点之间有一个距离矩阵,我将其导入cplex。我是这样做的:
tuple arc{
float x;
float y;
float d;
float Ttime; //Time to travell the arc
}
tuple vehicle{
key int id;
int STdepot; //Starting Depot (1 or 2)
int MaxCars; //Maximum number of cars in a vehicle
float AvSpeed; //Average Speed of a vehicle
}
tuple cavities{
key int id;
float x;
float y;
float rate; //Consumption Rate
float iniStock; //Initial Stock to be consumed at cavitie x
float deadline; //Deadline to arrive at cavitie x
int ProdCons; //Production Consumed at cavitie x
}
tuple CAVtype{
key int id;
int CarsCons; //Consuming cars of 12 or 20
}
tuple nodes{
key int id;
float x; //Coordinates in X
float y; //Coordinates in Y
string type;
}
setof(arc) OD = ...; //DistanceMatrix
setof(vehicle) K=...; //Vehicles
setof(cavities) C=...; //Cavities
setof(CAVtype) T=...; // Cavities Type
setof(nodes) N=...; //Nodes
float d[N][N];
float t[N][N];
execute preProcess{
cplex.tilim=300;
for(var i in N){
for(var j in N){
d[i][j] = 9999;
t[i][j] = 9999;
}
}
for(var arc in OD){
var origin = N.get(arc.x);
var destination = N.get(arc.y);
d[origin][destination] = arc.d;
t[origin][destination] = arc.Ttime;
}
}
它会导入所有内容,但是当我添加限制时,不会考虑距离矩阵,变量会显示没有连接的节点之间的连接。此外,最后的限制改变了q的值,为什么会发生这种情况呢?我该如何解决这个问题?
提前致谢。
目标函数和限制如下:
dexpr float MachineStoppage = sum(k in K,i in N,j in N) d[i][j] * x[i][j][k] +
sum(g in C,k in K) penalize *phi[g] + sum(i in N,g in C) u[i][g]; //(1)
minimize MachineStoppage;
//*******************************|Restrictions|***********************************************************
subject to{
forall (i in C, k in K) //(2)
FlowConservation:
sum(j in N: i.id!=j.id) x[<i.id>][j][k] == z[<i.id>][k];
forall (i in C, k in K) //(3)
FlowConservation2:
sum(j in N: i.id!=j.id) x[j][<i.id>][k] == z[<i.id>][k];
forall(i in N, k in K: i.type == "d" && k.STdepot!= i.id) //(5)
DepartingFromAnyDepot:
sum(j in N: i.id!=j.id) x[i][j][k] == 0;
forall(i in N)
sum(k in K) z[i][k]==1;
forall(i in N,j in N,k in K: i!=j && j.id!=0) //(8)
ArrivalTimeTracking1:
w[k][i] + t[i][j] <= w[k][j] + M*(1-x[i][j][k]);
forall(i in N,j in N,k in K: i!=j && j.id!=0) //(9)
ArrivalTimeTracking2:
w[k][i] + t[i][j] >= w[k][j]- M*(1-x[i][j][k]);
forall(k in K, g in C, i in N) //(10)
ReplenishmentDelay:
//w[k][<g.id>] <= g.deadline + phi[g];
w[k][<g.id>] <= g.deadline + phi[g];
forall(i in N, g in C, k in K) //(11)
QuantitiesToBeDeliveredToTheCavities:
q[k][g] == ((g.rate*w[k][<g.id>]) + u[i][g] + (g.ProdCons-g.iniStock));
forall(i in N,g in C,k in K) //(12)
LimitofQuantitiesToBeDelivered:
q[k][g] >= z[i][k] * g.ProdCons;
//q[k][g] >= z[<i.id>][k] * g.ProdCons;
forall(h in T, k in K) //(13)
NumberOfCarsOfEachTypeinEachVehicle:
sum(i in N,g in C) q[k][g] <= h.CarsCons*y[k][h];
/*
forall(k in K, g in C) //(14)
MaximumOfCarsinaVehicle:
sum(h in T) y[k][h] <=b;
*/
答案 0 :(得分:1)
IDE和OPL&gt; CPLEX Studio IDE&gt; IDE教程
你可以查看
部分放宽不可行的模型
问候