diff --git a/examples/contrib/volsay.cs b/examples/contrib/volsay.cs index b6f13432d8..cfd17c5118 100644 --- a/examples/contrib/volsay.cs +++ b/examples/contrib/volsay.cs @@ -29,7 +29,11 @@ public class Volsay */ private static void Solve() { - Solver solver = new Solver("Volsay", Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING); + Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } // // Variables diff --git a/examples/contrib/volsay2.cs b/examples/contrib/volsay2.cs index 60c89f73cf..5e63922e02 100644 --- a/examples/contrib/volsay2.cs +++ b/examples/contrib/volsay2.cs @@ -31,7 +31,11 @@ public class Volsay2 */ private static void Solve() { - Solver solver = new Solver("Volsay2", Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING); + Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } int num_products = 2; IEnumerable PRODUCTS = Enumerable.Range(0, num_products); diff --git a/examples/contrib/volsay3.cs b/examples/contrib/volsay3.cs index 180dfe1d22..d0481d9b0f 100644 --- a/examples/contrib/volsay3.cs +++ b/examples/contrib/volsay3.cs @@ -32,7 +32,11 @@ public class Volsay3 */ private static void Solve() { - Solver solver = new Solver("Volsay3", Solver.OptimizationProblemType.CLP_LINEAR_PROGRAMMING); + Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } int num_products = 2; IEnumerable PRODUCTS = Enumerable.Range(0, num_products); diff --git a/examples/tests/LinearSolverTests.cs b/examples/tests/LinearSolverTests.cs index 1ea51350dc..515143e177 100644 --- a/examples/tests/LinearSolverTests.cs +++ b/examples/tests/LinearSolverTests.cs @@ -23,6 +23,10 @@ public class LinearSolverTest public void VarOperator() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -62,6 +66,10 @@ public class LinearSolverTest public void VarAddition() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -92,6 +100,10 @@ public class LinearSolverTest public void VarMultiplication() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -127,6 +139,10 @@ public class LinearSolverTest public void BinaryOperator() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -161,6 +177,10 @@ public class LinearSolverTest public void Inequalities() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -198,6 +218,10 @@ public class LinearSolverTest public void SumArray() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable[] x = solver.MakeBoolVarArray(10, "x"); Constraint ct1 = solver.Add(x.Sum() == 3); @@ -217,6 +241,10 @@ public class LinearSolverTest public void Objective() { Solver solver = Solver.CreateSolver("CLP"); + if (solver is null) + { + return; + } Variable x = solver.MakeNumVar(0.0, 100.0, "x"); Assert.Equal(0.0, x.Lb()); Assert.Equal(100.0, x.Ub()); @@ -279,7 +307,7 @@ public class LinearSolverTest Console.WriteLine($"------ Linear programming example with {problemType} ------"); Solver solver = Solver.CreateSolver(problemType); - if (solver == null) + if (solver is null) return; // x and y are continuous non-negative variables. diff --git a/ortools/linear_solver/samples/AssignmentGroupsMip.cs b/ortools/linear_solver/samples/AssignmentGroupsMip.cs index ae9b8d8011..c833c95a47 100644 --- a/ortools/linear_solver/samples/AssignmentGroupsMip.cs +++ b/ortools/linear_solver/samples/AssignmentGroupsMip.cs @@ -59,6 +59,10 @@ public class AssignmentGroupsMip // Solver. // [START solver] Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // Variables. diff --git a/ortools/linear_solver/samples/AssignmentMip.cs b/ortools/linear_solver/samples/AssignmentMip.cs index 1c8ea33a48..0fea30ad05 100644 --- a/ortools/linear_solver/samples/AssignmentMip.cs +++ b/ortools/linear_solver/samples/AssignmentMip.cs @@ -33,6 +33,10 @@ public class AssignmentMip // Solver. // [START solver] Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // Variables. diff --git a/ortools/linear_solver/samples/AssignmentTaskSizesMip.cs b/ortools/linear_solver/samples/AssignmentTaskSizesMip.cs index 06304726d5..0bba6ab154 100644 --- a/ortools/linear_solver/samples/AssignmentTaskSizesMip.cs +++ b/ortools/linear_solver/samples/AssignmentTaskSizesMip.cs @@ -46,6 +46,10 @@ public class AssignmentTaskSizesMip // Solver. // [START solver] Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // Variables. diff --git a/ortools/linear_solver/samples/AssignmentTeamsMip.cs b/ortools/linear_solver/samples/AssignmentTeamsMip.cs index 677683c08a..69870c3c1c 100644 --- a/ortools/linear_solver/samples/AssignmentTeamsMip.cs +++ b/ortools/linear_solver/samples/AssignmentTeamsMip.cs @@ -44,6 +44,10 @@ public class AssignmentTeamsMip // Solver. // [START solver] Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // Variables. diff --git a/ortools/linear_solver/samples/BasicExample.cs b/ortools/linear_solver/samples/BasicExample.cs index 549816aa5d..e41192f646 100644 --- a/ortools/linear_solver/samples/BasicExample.cs +++ b/ortools/linear_solver/samples/BasicExample.cs @@ -23,6 +23,10 @@ public class BasicExample // [START solver] // Create the linear solver with the GLOP backend. Solver solver = Solver.CreateSolver("GLOP"); + if (solver is null) + { + return; + } // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/BinPackingMip.cs b/ortools/linear_solver/samples/BinPackingMip.cs index 4668b1c030..4e7e4af610 100644 --- a/ortools/linear_solver/samples/BinPackingMip.cs +++ b/ortools/linear_solver/samples/BinPackingMip.cs @@ -39,6 +39,10 @@ public class BinPackingMip // [START solver] // Create the linear solver with the SCIP backend. Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/LinearProgrammingExample.cs b/ortools/linear_solver/samples/LinearProgrammingExample.cs index 98495bf44a..b2dbefd772 100644 --- a/ortools/linear_solver/samples/LinearProgrammingExample.cs +++ b/ortools/linear_solver/samples/LinearProgrammingExample.cs @@ -23,6 +23,10 @@ public class LinearProgrammingExample { // [START solver] Solver solver = Solver.CreateSolver("GLOP"); + if (solver is null) + { + return; + } // [END solver] // x and y are continuous non-negative variables. // [START variables] diff --git a/ortools/linear_solver/samples/MipVarArray.cs b/ortools/linear_solver/samples/MipVarArray.cs index a68f1df0ab..2646708bc0 100644 --- a/ortools/linear_solver/samples/MipVarArray.cs +++ b/ortools/linear_solver/samples/MipVarArray.cs @@ -45,6 +45,10 @@ public class MipVarArray // [START solver] // Create the linear solver with the SCIP backend. Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/MultipleKnapsackMip.cs b/ortools/linear_solver/samples/MultipleKnapsackMip.cs index 3f1f76b202..10d48165d5 100644 --- a/ortools/linear_solver/samples/MultipleKnapsackMip.cs +++ b/ortools/linear_solver/samples/MultipleKnapsackMip.cs @@ -39,6 +39,10 @@ public class MultipleKnapsackMip // [START solver] // Create the linear solver with the SCIP backend. Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // Variables. diff --git a/ortools/linear_solver/samples/SimpleLpProgram.cs b/ortools/linear_solver/samples/SimpleLpProgram.cs index 62e4712db9..59e070d79d 100644 --- a/ortools/linear_solver/samples/SimpleLpProgram.cs +++ b/ortools/linear_solver/samples/SimpleLpProgram.cs @@ -25,6 +25,10 @@ public class SimpleLpProgram // [START solver] // Create the linear solver with the GLOP backend. Solver solver = Solver.CreateSolver("GLOP"); + if (solver is null) + { + return; + } // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/SimpleMipProgram.cs b/ortools/linear_solver/samples/SimpleMipProgram.cs index 14a5beb6a2..c4f6c3c7c4 100644 --- a/ortools/linear_solver/samples/SimpleMipProgram.cs +++ b/ortools/linear_solver/samples/SimpleMipProgram.cs @@ -24,6 +24,10 @@ public class SimpleMipProgram // [START solver] // Create the linear solver with the SCIP backend. Solver solver = Solver.CreateSolver("SCIP"); + if (solver is null) + { + return; + } // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/StiglerDiet.cs b/ortools/linear_solver/samples/StiglerDiet.cs index 72e0268664..8f708d62fb 100644 --- a/ortools/linear_solver/samples/StiglerDiet.cs +++ b/ortools/linear_solver/samples/StiglerDiet.cs @@ -114,6 +114,10 @@ public class StiglerDiet // [START solver] // Create the linear solver with the GLOP backend. Solver solver = Solver.CreateSolver("GLOP"); + if (solver is null) + { + return; + } // [END solver] // [START variables]