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