Skip to content

Commit 5554695

Browse files
committed
Fixing capacity not being read correctly, gurobi status translation, simplification
1 parent 435d8b7 commit 5554695

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

java-gurobi-knapsack/src/main/java/com/nextmv/example/Input.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import java.util.stream.Collectors;
77

88
import com.google.gson.Gson;
9+
import com.google.gson.annotations.SerializedName;
910

1011
public class Input {
1112
private final List<Item> items;
13+
@SerializedName("weight_capacity")
1214
private final double weightCapacity;
1315

1416
public Input(List<Item> items, double weightCapacity) {

java-gurobi-knapsack/src/main/java/com/nextmv/example/Main.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
public final class Main {
99

1010
public static void main(String[] args) {
11-
gurobiKnapsack(args);
12-
}
13-
14-
public static void gurobiKnapsack(String[] args) {
1511
try {
1612
// Parse arguments.
1713
Options options = Options.fromArguments(args);
@@ -63,11 +59,11 @@ public static void gurobiKnapsack(String[] args) {
6359
}
6460
}
6561
Output output = new Output(
66-
inputItems,
62+
outputItems,
6763
model.get(GRB.DoubleAttr.Runtime),
6864
model.get(GRB.DoubleAttr.ObjVal),
6965
"Gurobi",
70-
String.valueOf(model.get(GRB.IntAttr.Status)),
66+
convertStatus(model.get(GRB.IntAttr.Status)),
7167
model.get(GRB.IntAttr.NumVars),
7268
model.get(GRB.IntAttr.NumConstrs));
7369

@@ -83,4 +79,45 @@ public static void gurobiKnapsack(String[] args) {
8379
e.printStackTrace();
8480
}
8581
}
82+
83+
public static String convertStatus(int status) {
84+
switch (status) {
85+
case GRB.Status.LOADED:
86+
return "LOADED";
87+
case GRB.Status.OPTIMAL:
88+
return "OPTIMAL";
89+
case GRB.Status.INFEASIBLE:
90+
return "INFEASIBLE";
91+
case GRB.Status.INF_OR_UNBD:
92+
return "INF_OR_UNBD";
93+
case GRB.Status.UNBOUNDED:
94+
return "UNBOUNDED";
95+
case GRB.Status.CUTOFF:
96+
return "CUTOFF";
97+
case GRB.Status.ITERATION_LIMIT:
98+
return "ITERATION_LIMIT";
99+
case GRB.Status.NODE_LIMIT:
100+
return "NODE_LIMIT";
101+
case GRB.Status.TIME_LIMIT:
102+
return "TIME_LIMIT";
103+
case GRB.Status.SOLUTION_LIMIT:
104+
return "SOLUTION_LIMIT";
105+
case GRB.Status.INTERRUPTED:
106+
return "INTERRUPTED";
107+
case GRB.Status.NUMERIC:
108+
return "NUMERIC";
109+
case GRB.Status.SUBOPTIMAL:
110+
return "SUBOPTIMAL";
111+
case GRB.Status.INPROGRESS:
112+
return "INPROGRESS";
113+
case GRB.Status.USER_OBJ_LIMIT:
114+
return "USER_OBJ_LIMIT";
115+
case GRB.Status.WORK_LIMIT:
116+
return "WORK_LIMIT";
117+
case GRB.Status.MEM_LIMIT:
118+
return "MEM_LIMIT";
119+
default:
120+
return "UNKNOWN";
121+
}
122+
}
86123
}

java-ortools-knapsack/src/main/java/com/nextmv/example/Input.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import java.util.stream.Collectors;
77

88
import com.google.gson.Gson;
9+
import com.google.gson.annotations.SerializedName;
910

1011
public class Input {
1112
private final List<Item> items;
13+
@SerializedName("weight_capacity")
1214
private final double weightCapacity;
1315

1416
public Input(List<Item> items, double weightCapacity) {

0 commit comments

Comments
 (0)