Skip to content
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="traffic_lights.cs" /> <Compile Include="traffic_lights.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="volsay.cs" /> <Compile Include="volsay.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="volsay2.cs" /> <Compile Include="volsay2.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="volsay3.cs" /> <Compile Include="volsay3.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="wedding_optimal_chart.cs" /> <Compile Include="wedding_optimal_chart.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="who_killed_agatha.cs" /> <Compile Include="who_killed_agatha.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="word_square.cs" /> <Compile Include="word_square.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="xkcd.cs" /> <Compile Include="xkcd.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="young_tableaux.cs" /> <Compile Include="young_tableaux.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="zebra.cs" /> <Compile Include="zebra.cs" />
<PackageReference Include="Google.OrTools" Version="7.7.*" /> <PackageReference Include="Google.OrTools" Version="7.8.*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -43,8 +43,7 @@ public class AssignmentMip { ...@@ -43,8 +43,7 @@ public class AssignmentMip {
// Solver // Solver
// [START solver] // [START solver]
// Create the linear solver with the CBC backend. // Create the linear solver with the CBC backend.
MPSolver solver = new MPSolver( MPSolver solver = MPSolver.createSolver("AssignmentMip", "CBC");
"AssignmentMip", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
// [END solver] // [END solver]
// Variables // Variables
......
...@@ -45,8 +45,7 @@ public class BinPackingMip { ...@@ -45,8 +45,7 @@ public class BinPackingMip {
// [START solver] // [START solver]
// Create the linear solver with the CBC backend. // Create the linear solver with the CBC backend.
MPSolver solver = new MPSolver( MPSolver solver = MPSolver.createSolver("BinPackingMip", "CBC");
"BinPackingMip", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
// [END solver] // [END solver]
// [START program_part2] // [START program_part2]
......
...@@ -50,12 +50,11 @@ public class CoinsGridMIP { ...@@ -50,12 +50,11 @@ public class CoinsGridMIP {
System.loadLibrary("jniortools"); System.loadLibrary("jniortools");
} }
private static MPSolver createSolver(String solverType) {
return new MPSolver("MIPDiet", MPSolver.OptimizationProblemType.valueOf(solverType));
}
private static void solve(String solverType) { private static void solve(String solverType) {
MPSolver solver = createSolver(solverType); System.out.println("---- CoinsGridMIP with " + solverType);
MPSolver solver = MPSolver.createSolver("CoinsGridMIP", solverType);
if (solver == null) return;
/** invariants */ /** invariants */
int n = 31; int n = 31;
...@@ -85,6 +84,8 @@ public class CoinsGridMIP { ...@@ -85,6 +84,8 @@ public class CoinsGridMIP {
solver.solve(); solver.solve();
System.out.println("Problem solved in " + solver.wallTime() + "ms");
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) { for (int j = 0; j < n; j++) {
System.out.print((int) x[i][j].solutionValue() + " "); System.out.print((int) x[i][j].solutionValue() + " ");
...@@ -94,23 +95,9 @@ public class CoinsGridMIP { ...@@ -94,23 +95,9 @@ public class CoinsGridMIP {
} }
public static void main(String[] args) { public static void main(String[] args) {
try { solve("SCIP");
System.out.println("---- Integer programming example with SCIP (recommended) ----"); solve("CBC");
solve("SCIP_MIXED_INTEGER_PROGRAMMING"); solve("GLPK");
} catch (java.lang.IllegalArgumentException e) { solve("SAT");
System.err.println("Bad solver type: " + e);
}
try {
System.out.println("---- Integer programming example with CBC ----");
solve("CBC_MIXED_INTEGER_PROGRAMMING");
} catch (java.lang.IllegalArgumentException e) {
System.err.println("Bad solver type: " + e);
}
try {
System.out.println("---- Integer programming example with GLPK ----");
solve("GLPK_MIXED_INTEGER_PROGRAMMING");
} catch (java.lang.IllegalArgumentException e) {
System.err.println("Bad solver type: " + e);
}
} }
} }
...@@ -39,12 +39,12 @@ public class ColoringMIP { ...@@ -39,12 +39,12 @@ public class ColoringMIP {
System.loadLibrary("jniortools"); System.loadLibrary("jniortools");
} }
private static MPSolver createSolver(String solverType) {
return new MPSolver("MIPDiet", MPSolver.OptimizationProblemType.valueOf(solverType));
}
private static void solve(String solverType) { private static void solve(String solverType) {
MPSolver solver = createSolver(solverType); System.out.println("---- CoinsGridMIP with " + solverType);
MPSolver solver = MPSolver.createSolver("CoinsGridMIP", solverType);
if (solver == null) return;
double infinity = MPSolver.infinity(); double infinity = MPSolver.infinity();
/** invariants */ /** invariants */
...@@ -115,6 +115,8 @@ public class ColoringMIP { ...@@ -115,6 +115,8 @@ public class ColoringMIP {
System.err.println("The problem does not have an optimal solution!"); System.err.println("The problem does not have an optimal solution!");
return; return;
} else { } else {
System.out.println("Problem solved in " + solver.wallTime() + "ms");
System.out.print("Colors used: "); System.out.print("Colors used: ");
for (MPVariable var : colUsed) { for (MPVariable var : colUsed) {
System.out.print((int) var.solutionValue() + " "); System.out.print((int) var.solutionValue() + " ");
...@@ -133,23 +135,9 @@ public class ColoringMIP { ...@@ -133,23 +135,9 @@ public class ColoringMIP {
} }
public static void main(String[] args) { public static void main(String[] args) {
try { solve("SCIP");
System.out.println("---- Integer programming example with SCIP (recommended) ----"); solve("CBC");
solve("SCIP_MIXED_INTEGER_PROGRAMMING"); solve("GLPK");
} catch (java.lang.IllegalArgumentException e) { solve("SAT");
System.err.println("Bad solver type: " + e);
}
try {
System.out.println("---- Integer programming example with CBC ----");
solve("CBC_MIXED_INTEGER_PROGRAMMING");
} catch (java.lang.IllegalArgumentException e) {
System.err.println("Bad solver type: " + e);
}
try {
System.out.println("---- Integer programming example with GLPK ----");
solve("GLPK_MIXED_INTEGER_PROGRAMMING");
} catch (java.lang.IllegalArgumentException e) {
System.err.println("Bad solver type: " + e);
}
} }
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package com.google.ortools.examples; package com.google.ortools.examples;
import com.google.ortools.linearsolver.MPConstraint; import com.google.ortools.linearsolver.MPConstraint;
...@@ -27,17 +28,8 @@ public class IntegerProgramming { ...@@ -27,17 +28,8 @@ public class IntegerProgramming {
System.loadLibrary("jniortools"); System.loadLibrary("jniortools");
} }
private static MPSolver createSolver(String solverType) {
try {
return new MPSolver(
"IntegerProgrammingExample", MPSolver.OptimizationProblemType.valueOf(solverType));
} catch (java.lang.IllegalArgumentException e) {
return null;
}
}
private static void runIntegerProgrammingExample(String solverType) { private static void runIntegerProgrammingExample(String solverType) {
MPSolver solver = createSolver(solverType); MPSolver solver = MPSolver.createSolver("IntegerProgramming", solverType);
if (solver == null) { if (solver == null) {
System.out.println("Could not create solver " + solverType); System.out.println("Could not create solver " + solverType);
return; return;
...@@ -88,10 +80,10 @@ public class IntegerProgramming { ...@@ -88,10 +80,10 @@ public class IntegerProgramming {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("---- Integer programming example with SCIP (recommended) ----"); System.out.println("---- Integer programming example with SCIP (recommended) ----");
runIntegerProgrammingExample("SCIP_MIXED_INTEGER_PROGRAMMING"); runIntegerProgrammingExample("SCIP");
System.out.println("---- Integer programming example with CBC ----"); System.out.println("---- Integer programming example with CBC ----");
runIntegerProgrammingExample("CBC_MIXED_INTEGER_PROGRAMMING"); runIntegerProgrammingExample("CBC");
System.out.println("---- Integer programming example with GLPK ----"); System.out.println("---- Integer programming example with CP-SAT ----");
runIntegerProgrammingExample("GLPK_MIXED_INTEGER_PROGRAMMING"); runIntegerProgrammingExample("SAT");
} }
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package com.google.ortools.examples; package com.google.ortools.examples;
import com.google.ortools.linearsolver.MPConstraint; import com.google.ortools.linearsolver.MPConstraint;
...@@ -27,17 +28,8 @@ public class LinearProgramming { ...@@ -27,17 +28,8 @@ public class LinearProgramming {
System.loadLibrary("jniortools"); System.loadLibrary("jniortools");
} }
private static MPSolver createSolver(String solverType) {
try {
return new MPSolver(
"LinearProgrammingExample", MPSolver.OptimizationProblemType.valueOf(solverType));
} catch (java.lang.IllegalArgumentException e) {
return null;
}
}
private static void runLinearProgrammingExample(String solverType, boolean printModel) { private static void runLinearProgrammingExample(String solverType, boolean printModel) {
MPSolver solver = createSolver(solverType); MPSolver solver = MPSolver.createSolver("IntegerProgramming", solverType);
if (solver == null) { if (solver == null) {
System.out.println("Could not create solver " + solverType); System.out.println("Could not create solver " + solverType);
return; return;
...@@ -124,10 +116,8 @@ public class LinearProgramming { ...@@ -124,10 +116,8 @@ public class LinearProgramming {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("---- Linear programming example with GLOP (recommended) ----"); System.out.println("---- Linear programming example with GLOP (recommended) ----");
runLinearProgrammingExample("GLOP_LINEAR_PROGRAMMING", true); runLinearProgrammingExample("GLOP", true);
System.out.println("---- Linear programming example with CLP ----"); System.out.println("---- Linear programming example with CLP ----");
runLinearProgrammingExample("CLP_LINEAR_PROGRAMMING", false); runLinearProgrammingExample("CLP", false);
System.out.println("---- Linear programming example with GLPK ----");
runLinearProgrammingExample("GLPK_LINEAR_PROGRAMMING", false);
} }
} }
...@@ -27,8 +27,7 @@ public class LinearProgrammingExample { ...@@ -27,8 +27,7 @@ public class LinearProgrammingExample {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// [START solver] // [START solver]
MPSolver solver = new MPSolver( MPSolver solver = MPSolver.createSolver("LinearProgrammingExample", "GLOP");
"LinearProgrammingExample", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);
// [END solver] // [END solver]
// [START variables] // [START variables]
......
...@@ -50,8 +50,7 @@ public class MipVarArray { ...@@ -50,8 +50,7 @@ public class MipVarArray {
// [START solver] // [START solver]
// Create the linear solver with the CBC backend. // Create the linear solver with the CBC backend.
MPSolver solver = new MPSolver( MPSolver solver = MPSolver.createSolver("MipVarArray", "CBC");
"SimpleMipProgram", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
// [END solver] // [END solver]
// [START program_part2] // [START program_part2]
......
...@@ -46,8 +46,7 @@ public class MultipleKnapsackMip { ...@@ -46,8 +46,7 @@ public class MultipleKnapsackMip {
// [START solver] // [START solver]
// Create the linear solver with the CBC backend. // Create the linear solver with the CBC backend.
MPSolver solver = new MPSolver( MPSolver solver = MPSolver.createSolver("MultipleKnapsackMip", "CBC");
"MultipleKnapsackMip", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
// [END solver] // [END solver]
// [START program_part2] // [START program_part2]
......
...@@ -30,8 +30,7 @@ public class SimpleLpProgram { ...@@ -30,8 +30,7 @@ public class SimpleLpProgram {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// [START solver] // [START solver]
// Create the linear solver with the GLOP backend. // Create the linear solver with the GLOP backend.
MPSolver solver = MPSolver solver = MPSolver.createSolver("SimpleLpProgram", "GLOP");
new MPSolver("SimpleLpProgram", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);
// [END solver] // [END solver]
// [START variables] // [START variables]
......