From 2b3a7a3d4da484423ac19f019ac5e74454485267 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 1 Nov 2023 09:33:02 +0100 Subject: [PATCH] Update --- ortools/linear_solver/csharp/ModelBuilder.cs | 2 +- ortools/linear_solver/csharp/ModelSolver.cs | 110 ++++++++++++------- 2 files changed, 73 insertions(+), 39 deletions(-) diff --git a/ortools/linear_solver/csharp/ModelBuilder.cs b/ortools/linear_solver/csharp/ModelBuilder.cs index 9071af3585..ff119eb12d 100644 --- a/ortools/linear_solver/csharp/ModelBuilder.cs +++ b/ortools/linear_solver/csharp/ModelBuilder.cs @@ -37,6 +37,7 @@ public class ModelBuilder helper_ = new ModelBuilderHelper(); constantMap_ = new Dictionary(); var_value_map_ = new SortedDictionary(); + terms_ = new Queue(); } /// @@ -148,7 +149,6 @@ public class ModelBuilder throw new ArgumentException("Cannot use '" + lin.ToString() + "' as a linear constraint."); } } - return null; } /// diff --git a/ortools/linear_solver/csharp/ModelSolver.cs b/ortools/linear_solver/csharp/ModelSolver.cs index 4151f1c6a0..cda7cc9e5d 100644 --- a/ortools/linear_solver/csharp/ModelSolver.cs +++ b/ortools/linear_solver/csharp/ModelSolver.cs @@ -22,7 +22,9 @@ using System.Linq; using System.Runtime.CompilerServices; using Google.Protobuf.Collections; -/** Model solver class */ +/// +/// Model solver class +/// public class ModelSolver { class ModelSolverException : Exception @@ -32,15 +34,22 @@ public class ModelSolver } } - /** Creates the solver with the supplied solver backend. */ + /// + /// Creates the solver with the supplied solver backend. + /// + /// the name of the solver backend public ModelSolver(String solverName) { this.helper_ = new ModelSolverHelper(solverName); this.logCallback_ = null; } - /** Solves given model, and returns the status of the response. */ - public SolveStatus solve(ModelBuilder model) + /// + /// Solves given model, and returns the status of the response. + /// + /// the model to solve + /// the status of the solve + public SolveStatus Solve(ModelBuilder model) { if (logCallback_ == null) { @@ -58,7 +67,10 @@ public class ModelSolver return helper_.Status(); } - /** Enables or disables the underlying solver output. */ + /// + /// Enables or disables the underlying solver output. + /// + /// the Boolean that controls the output public void EnableOutput(bool enable) { helper_.EnableOutput(enable); @@ -76,108 +88,126 @@ public class ModelSolver helper_.SetSolverSpecificParameters(parameters); } - /** Returns whether solver specified during the ctor was found and correctly installed. */ + /// + /// Returns whether solver specified during the ctor was found and correctly installed. + /// + /// whether the solver is supported or not public bool SolverIsSupported() { return helper_.SolverIsSupported(); } - /** Tries to interrupt the solve. Returns true if the feature is supported. */ + /// + /// Tries to interrupt the solve. Returns true if the feature is supported. + /// + /// whether the solver supports interruption public bool InterruptSolve() { return helper_.InterruptSolve(); } - /** Returns true if solve() was called, and a response was returned. */ + /// + /// Returns true if solve() was called, and a response was returned. + /// + /// whether solve did happen public bool HasResponse() { return helper_.HasResponse(); } - /** Returns true if solve() was called, and a solution was returned. */ + /// + /// Returns true if solve() was called, and a solution was returned. + /// + /// whether a solution was found public bool HasSolution() { return helper_.HasSolution(); } - /** Checks that the solver has found a solution, and returns the objective value. */ + /// + /// The best objective value found during search. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double ObjectiveValue { get { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getObjectiveValue()", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.ObjectiveValue", + "Solve() was not called or no solution was found"); } return helper_.ObjectiveValue(); } } - /** Checks that the solver has found a solution, and returns the objective value. */ + /// + /// The best objective bound found during search. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double BestObjectiveBound { get { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getBestObjectiveBound()", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.BestObjectiveBound", + "Solve() was not called or no solution was found"); } return helper_.BestObjectiveBound(); } } - /** Checks that the solver has found a solution, and returns the value of the given variable. */ + /// + /// The value of a variable in the current solution. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double Value(Variable var) { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getValue())", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.Value())", + "Solve() was not called or no solution was found"); } return helper_.VariableValue(var.Index); } - /** - * Checks that the solver has found a solution, and returns the reduced cost of the given - * variable. - */ + /// + /// The reduced cost of a variable in the current solution. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double ReducedCost(Variable var) { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getReducedCost())", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.ReducedCost())", + "Solve() was not called or no solution was found"); } return helper_.ReducedCost(var.Index); } - /** - * Checks that the solver has found a solution, and returns the dual value of the given - * constraint. - */ + /// + /// The dual value of a linear constraint in the current solution. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double DualValue(LinearConstraint ct) { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getDualValue())", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.DualValue())", + "Solve() was not called or no solution was found"); } return helper_.DualValue(ct.Index); } - /** - * Checks that the solver has found a solution, and returns the activity of the given constraint. - */ + /// + /// The activity of a constraint in the current solution. This raises a ModelSolverException is no solution has been found, or if Solve() has not been called. + /// public double Activity(LinearConstraint ct) { if (!helper_.HasSolution()) { - throw new ModelSolverException("ModelSolver.getActivity())", - "solve() was not called or no solution was found"); + throw new ModelSolverException("ModelSolver.Activity())", + "Solve() was not called or no solution was found"); } return helper_.Activity(ct.Index); } - /** Sets the log callback for the solver. */ + /// + /// Sets the log callback for the solver. + /// public LogCallback LogCallback { get { @@ -188,7 +218,9 @@ public class ModelSolver } } - /** Returns the elapsed time since the creation of the solver. */ + /// + /// Returns the elapsed time since the creation of the solver. + /// public double WallTime { get { @@ -196,7 +228,9 @@ public class ModelSolver } } - /** Returns the user time since the creation of the solver. */ + /// + /// Returns the user time since the creation of the solver. + /// public double UserTime { get {