forked from xiongwq16/exact-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUflpSolution.java
More file actions
76 lines (59 loc) · 2.05 KB
/
UflpSolution.java
File metadata and controls
76 lines (59 loc) · 2.05 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
76
package uflp;
import ilog.cplex.IloCplex.CplexStatus;
import java.util.ArrayList;
/**
* UFLP的解.
*
* @author Xiong Wangqi
* @version V1.0
* @since JDK1.8
*/
class UflpSolution {
/** The milliseconds to seconds conversion factor. */
private static final double MS_TO_SEC = 0.001;
private CplexStatus status;
private double solveTime;
/** supply[j][k] = 1 if warehouse j supplies customer k, 0 if not. */
private double[][] supply;
/** 开设的仓库的编号数组. */
private ArrayList<Integer> openWarehouses;
private double totalCost;
UflpSolution(int warehouseNum, int customerNum) {
supply = new double[warehouseNum][customerNum];
}
/**
* 输出 UFLP 的解,包括解的类型,总成本,开设的仓库,客户的供应方案.
*/
void output() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("It takes %.2f seconds to find the %s solution with cost %.2f",
solveTime, status, totalCost));
int openWarehouseNum = openWarehouses.size();
int customerNum = supply[0].length;
for (int j = 0; j < openWarehouseNum; j++) {
int warehouseIndex = openWarehouses.get(j);
sb.append("\nWarehouse" + warehouseIndex + " is open, it serves customters: ");
for (int k = 0; k < customerNum; k++) {
if (supply[warehouseIndex][k] == 1) {
sb.append(k + "\t");
}
}
}
System.out.println(sb.toString());
}
void setSupply(int warehouseIndex, int customerindex) {
supply[warehouseIndex][customerindex] = 1;
}
void setTotalCost(double totalCost) {
this.totalCost = totalCost;
}
void setOpenWarehouses(ArrayList<Integer> openWarehouses) {
this.openWarehouses = openWarehouses;
}
void setStatus(CplexStatus status) {
this.status = status;
}
void setSolveTime(long solveTime) {
this.solveTime = solveTime * MS_TO_SEC;
}
}