obj function: min |Xij*Pij - Xik*Pik| (i=1..10, j=1..4, k=5..8)
constraints:
Xij\<=Tij ∀i,j;
ΣXij*Cij\<=Bi ∀i;
ΣXij*Cij\>=0.02ΣBi ∀j;
ΣXij*Pij\>=S ∀i,j;
I try this but it doesn't work(Infeasible model):
obj funct:
GRBVar w = model.addVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "w");
GRBLinExpr obj = new GRBLinExpr();
obj.addTerm(1, w);
model.setObjective(obj);
model.set(GRB.IntAttr.ModelSense, GRB.MINIMIZE);
constraints:
w >= xir pir - xin pin
GRBLinExpr expr = new GRBLinExpr();
for(int i=0; i<M; i++) {
for(int r=0; r<4; r++) {
expr.addTerm(pij[i][r], xij[i][r]);
}
for(int n=4; n<K; n++) {
expr.addTerm(-pij[i][n], xij[i][n]);
}
}
model.addConstr(w, GRB.GREATER_EQUAL, expr, "vincolo " + count);
count++;
w >= xin pin - xir pir
expr = new GRBLinExpr();
for(int i=0; i<M; i++) {
for(int n=4; n<K; n++) {
expr.addTerm(pij[i][n], xij[i][n]);
}
for(int r=0; r<4; r++) {
expr.addTerm(-pij[i][r], xij[i][r]);
}
}
model.addConstr(w, GRB.GREATER_EQUAL, expr, "vincolo " + count);
count++;
xij <= tij
expr = new GRBLinExpr();
for(int i=0; i<M; i++) {
for(int j=0; j<K; j++) {
expr.addTerm(1, xij[i][j]);
model.addConstr(expr, GRB.LESS_EQUAL, tij[i][j], "vincolo " + count);
count++;
}
}
xij cij <= bi
expr = new GRBLinExpr();
for(int i=0; i<M; i++) {
for(int j=0; j<K; j++) {
expr.addTerm(cij[i][j], xij[i][j]);
}
model.addConstr(expr, GRB.LESS_EQUAL, bi[i], "vincolo " + count);
count++;
}
xij cij >= 0.02*bi
expr = new GRBLinExpr();
int budget = 0;
double value = 0;
for(int i=0; i<M; i++) {
budget += bi[i];
}
value = budget*0.02;
for(int j=0; j<K; j++) {
for(int i=0; i<M;i++) {
expr.addTerm(cij[i][j], xij[i][j]);
}
model.addConstr(expr, GRB.GREATER_EQUAL, valore, "vincolo " + count);
count++;
}
xij pij >= s
expr = new GRBLinExpr();
for(int i=0; i<M; i++) {
for(int j=0; j<K; j++) {
expr.addTerm(pij[i][j], xij[i][j]);
}
}
model.addConstr(expr, GRB.GREATER_EQUAL, s, "vincolo" + count);