我想向我的TSP
添加一个Pickup约束,因此驱动程序首先拾取一个项目,然后将其删除。我在cplex
中使用java
,但不知道如何正确设置它。
V[i] = a decision variable
:第i点的车辆容量取决于3个供应点和3个需求点q [] = [1、1、1,-1,-1,-1];
IloCplex cplex = new IloCplex();
IloNumVar[][] x = new IloNumVar[t.length][t.length];
for (int i = 0; i < t.length; i++) {
for (int j = 0; j < t.length; j++) {
if (i != j) {
x[i][j] = cplex.boolVar("x." + i + "." + j);
}
}
}
IloNumVar[] u = new IloNumVar[t.length];
for (int i = 1; i <t.length; i++) {
u[i] = cplex.numVar(0, Double.MAX_VALUE, "u." + i);
}
IloNumVar[] V = new IloNumVar[t.length];
for (int i = 1; i <t.length; i++) {
V[i] = cplex.numVar(Math.max(0,q[i]), Math.min(Capacity, Capacity + q[i]), "V." + i);
}
IloLinearNumExpr obj = cplex.linearNumExpr();
for (int i = 0; i < t.length; i++) {
for (int j = 0; j < t.length; j++) {
if (i != j) {
obj.addTerm(costs[i][j], x[i][j]);
}
}
}
cplex.addMinimize(obj);
//
for (int j = 0; j < t.length; j++) {
IloLinearNumExpr expr0 = cplex.linearNumExpr();
for (int i = 0; i < t.length; i++) {
if (i != j) {
expr0.addTerm(1, x[i][j]);
}
}
cplex.addEq(expr0, 1);
}
//
for (int i = 0; i <t.length; i++) {
IloLinearNumExpr expr1 = cplex.linearNumExpr();
for (int j = 0; j < t.length; j++) {
if (j != i) {
expr1.addTerm(1, x[i][j]);
}
}
cplex.addEq(expr1, 1) ;
}
//route connectivity MTZ constraint
for (int i = 1; i < t.length; i++) {
for (int j = 1; j < t.length; j++) {
if (i!=j){
IloLinearNumExpr expr2 = cplex.linearNumExpr();
expr2.addTerm(1, u[i]);
expr2.addTerm(-1, u[j]);
expr2.addTerm(t.length - 1, x[i][j]);
cplex.addLe(expr2, t.length - 2);
}
}
}
//提取限制?看起来像
V [j] = V [i] + q [i];
cplex.solve();
} catch (IloException e) {
e.printStackTrace();
}
}
}