-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelSetting.cpp
More file actions
75 lines (65 loc) · 1.85 KB
/
Copy pathmodelSetting.cpp
File metadata and controls
75 lines (65 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "modelSetting.h"
void
setFirstStageConstr(IloModel modelFirst, Var2D w, Var1D y, Var1D z) {
IloEnv env = modelFirst.getEnv();
//constraints
//7b
/*for (int i = 0; i < I_mobile; i++) {
for (int j = 0; j < J_customer; j++) {
modelFirst.add(IloRange(w[i][j] - z[i] <= 0));
}
}*/
//7c
for (int j = 0; j < J_customer; j++) {
IloExpr sum(env);
for (int i = 0; i < I_mobile; i++) {
sum += w[i][j];
}
modelFirst.add(IloRange(sum + y[j] == 1));
sum.end();
}
//7d
/*for (int i = 0; i < I_mobile; i++) {
modelFirst.add(IloRange(IloSum(w[i]) <= C_capacity));
}*/
//combine 7b and 7d
for (int i = 0; i < I_mobile; i++) {
modelFirst.add(IloRange(IloSum(w[i]) - C_capacity * z[i] <= 0));
}
//valid inequality
modelFirst.add(IloRange(C_capacity * IloSum(z) - (J_customer - IloSum(y)) >= 0));
}
void setSecondStage(IloEnv env, IloExpr& objSecond, IloNumVarArray v, Var3D p, IloRangeArray constr9b, IloRangeArray constr9c, Constr2D constr9d) {
//objective
objSecond = IloScalProd(cost_v, v);
for (int i = 0; i < I_mobile; i++) {
for (int j = 0; j < J_customer; j++) {
objSecond += IloScalProd(cost_p[i][j], p[i][j]);
}
}
//constraints 9b
for (int k = 0; k < K_shipper; k++) {
IloExpr sum(env);
for (int i = 0; i < I_mobile; i++) {
for (int j = 0; j < J_customer; j++) {
sum += p[i][j][k];
}
}
constr9b[k] = IloRange(sum <= 0.0);
sum.end();
}
//constraint 9c
for (int j = 0; j < J_customer; j++) {
IloExpr sum(env);
for (int i = 0; i < I_mobile; i++) sum += IloSum(p[i][j]);
constr9c[j] = IloRange(sum + v[j] == 1.0);
sum.end();
}
//constraint 9d
for (int i = 0; i < I_mobile; i++) {
constr9d[i] = IloRangeArray(env, J_customer);
for (int j = 0; j < J_customer; j++) {
constr9d[i][j] = IloRange(IloSum(p[i][j]) <= 0.0);
}
}
}