From 6f394abbe6e65aa814e39cfe0cd6593d97831cff Mon Sep 17 00:00:00 2001 From: Vincent Furnon Date: Thu, 16 Apr 2015 16:21:56 +0200 Subject: [PATCH] virtual to override change of the linear solver code. --- src/linear_solver/bop_interface.cc | 77 +++++++++++++------------- src/linear_solver/cbc_interface.cc | 74 ++++++++++++------------- src/linear_solver/clp_interface.cc | 74 ++++++++++++------------- src/linear_solver/glop_interface.cc | 76 ++++++++++++------------- src/linear_solver/glpk_interface.cc | 80 +++++++++++++-------------- src/linear_solver/gurobi_interface.cc | 80 +++++++++++++-------------- src/linear_solver/scip_interface.cc | 78 +++++++++++++------------- 7 files changed, 270 insertions(+), 269 deletions(-) diff --git a/src/linear_solver/bop_interface.cc b/src/linear_solver/bop_interface.cc index 2455a18f38..e7235d5d2a 100644 --- a/src/linear_solver/bop_interface.cc +++ b/src/linear_solver/bop_interface.cc @@ -53,55 +53,56 @@ MPSolver::ResultStatus TranslateProblemStatus(bop::BopSolveStatus status) { class BopInterface : public MPSolverInterface { public: explicit BopInterface(MPSolver* const solver); - virtual ~BopInterface(); + ~BopInterface() override; // ----- Solve ----- - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- - virtual void Reset(); - virtual void SetOptimizationDirection(bool maximize); - virtual void SetVariableBounds(int index, double lb, double ub); - virtual void SetVariableInteger(int index, bool integer); - virtual void SetConstraintBounds(int index, double lb, double ub); - virtual void AddRowConstraint(MPConstraint* const ct); - virtual void AddVariable(MPVariable* const var); - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); - virtual void ClearConstraint(MPConstraint* const constraint); - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); - virtual void SetObjectiveOffset(double value); - virtual void ClearObjective(); + void Reset() override; + void SetOptimizationDirection(bool maximize) override; + void SetVariableBounds(int index, double lb, double ub) override; + void SetVariableInteger(int index, bool integer) override; + void SetConstraintBounds(int index, double lb, double ub) override; + void AddRowConstraint(MPConstraint* const ct) override; + void AddVariable(MPVariable* const var) override; + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; + void ClearConstraint(MPConstraint* const constraint) override; + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; + void SetObjectiveOffset(double value) override; + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ - virtual int64 iterations() const; - virtual int64 nodes() const; - virtual double best_objective_bound() const; - virtual MPSolver::BasisStatus row_status(int constraint_index) const; - virtual MPSolver::BasisStatus column_status(int variable_index) const; + int64 iterations() const override; + int64 nodes() const override; + double best_objective_bound() const override; + MPSolver::BasisStatus row_status(int constraint_index) const override; + MPSolver::BasisStatus column_status(int variable_index) const override; // ----- Misc ----- - virtual bool IsContinuous() const; - virtual bool IsLP() const; - virtual bool IsMIP() const; + bool IsContinuous() const override; + bool IsLP() const override; + bool IsMIP() const override; - virtual std::string SolverVersion() const; - virtual void* underlying_solver(); + std::string SolverVersion() const override; + bool InterruptSolve() override; + void* underlying_solver() override; - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual void SetParameters(const MPSolverParameters& param); - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); - virtual bool ReadParameterFile(const std::string& filename); + void SetParameters(const MPSolverParameters& param) override; + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; + bool ReadParameterFile(const std::string& filename) override; private: void NonIncrementalChange(); diff --git a/src/linear_solver/cbc_interface.cc b/src/linear_solver/cbc_interface.cc index 86eae4b798..49f60a7344 100644 --- a/src/linear_solver/cbc_interface.cc +++ b/src/linear_solver/cbc_interface.cc @@ -49,84 +49,84 @@ class CBCInterface : public MPSolverInterface { public: // Constructor that takes a name for the underlying glpk solver. explicit CBCInterface(MPSolver* const solver); - virtual ~CBCInterface(); + ~CBCInterface() override; // ----- Reset ----- - virtual void Reset(); + void Reset() override; // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); + void SetOptimizationDirection(bool maximize) override; // ----- Solve ----- // Solve the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // TODO(user): separate the solve from the model extraction. virtual void ExtractModel() {} // Query problem type. - virtual bool IsContinuous() const { return false; } - virtual bool IsLP() const { return false; } - virtual bool IsMIP() const { return true; } + bool IsContinuous() const override { return false; } + bool IsLP() const override { return false; } + bool IsMIP() const override { return true; } // Modify bounds. - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); + void SetVariableBounds(int var_index, double lb, double ub) override; + void SetVariableInteger(int var_index, bool integer) override; + void SetConstraintBounds(int row_index, double lb, double ub) override; // Add constraint incrementally. - void AddRowConstraint(MPConstraint* const ct); + void AddRowConstraint(MPConstraint* const ct) override; // Add variable incrementally. - void AddVariable(MPVariable* const var); + void AddVariable(MPVariable* const var) override; // Change a coefficient in a constraint. - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value) { + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override { sync_status_ = MUST_RELOAD; } // Clear a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint) { + void ClearConstraint(MPConstraint* const constraint) override { sync_status_ = MUST_RELOAD; } // Change a coefficient in the linear objective. - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient) { + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override { sync_status_ = MUST_RELOAD; } // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value) { sync_status_ = MUST_RELOAD; } + void SetObjectiveOffset(double value) override { sync_status_ = MUST_RELOAD; } // Clear the objective from all its terms. - virtual void ClearObjective() { sync_status_ = MUST_RELOAD; } + void ClearObjective() override { sync_status_ = MUST_RELOAD; } // Number of simplex iterations - virtual int64 iterations() const; + int64 iterations() const override; // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; + int64 nodes() const override; // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; + double best_objective_bound() const override; // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const { + MPSolver::BasisStatus row_status(int constraint_index) const override { LOG(FATAL) << "Basis status only available for continuous problems"; return MPSolver::FREE; } // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const { + MPSolver::BasisStatus column_status(int variable_index) const override { LOG(FATAL) << "Basis status only available for continuous problems"; return MPSolver::FREE; } - virtual void ExtractNewVariables() {} - virtual void ExtractNewConstraints() {} - virtual void ExtractObjective() {} + void ExtractNewVariables() override {} + void ExtractNewConstraints() override {} + void ExtractObjective() override {} - virtual std::string SolverVersion() const { return "Cbc " CBC_VERSION; } + std::string SolverVersion() const override { return "Cbc " CBC_VERSION; } // TODO(user): Maybe we should expose the CbcModel build from osi_ // instead, but a new CbcModel is built every time Solve is called, // so it is not possible right now. - virtual void* underlying_solver() { return reinterpret_cast(&osi_); } + void* underlying_solver() override { return reinterpret_cast(&osi_); } private: // Reset best objective bound to +/- infinity depending on the @@ -134,14 +134,14 @@ class CBCInterface : public MPSolverInterface { void ResetBestObjectiveBound(); // Set all parameters in the underlying solver. - virtual void SetParameters(const MPSolverParameters& param); + void SetParameters(const MPSolverParameters& param) override; // Set each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; OsiClpSolverInterface osi_; // TODO(user): remove and query number of iterations directly from CbcModel diff --git a/src/linear_solver/clp_interface.cc b/src/linear_solver/clp_interface.cc index e646dd0742..950a90944a 100644 --- a/src/linear_solver/clp_interface.cc +++ b/src/linear_solver/clp_interface.cc @@ -46,69 +46,69 @@ class CLPInterface : public MPSolverInterface { public: // Constructor that takes a name for the underlying CLP solver. explicit CLPInterface(MPSolver* const solver); - ~CLPInterface(); + ~CLPInterface() override; // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); + void SetOptimizationDirection(bool maximize) override; // ----- Solve ----- // Solve the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- // Resets extracted model - virtual void Reset(); + void Reset() override; // Modify bounds. - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); + void SetVariableBounds(int var_index, double lb, double ub) override; + void SetVariableInteger(int var_index, bool integer) override; + void SetConstraintBounds(int row_index, double lb, double ub) override; // Add constraint incrementally. - void AddRowConstraint(MPConstraint* const ct); + void AddRowConstraint(MPConstraint* const ct) override; // Add variable incrementally. - void AddVariable(MPVariable* const var); + void AddVariable(MPVariable* const var) override; // Change a coefficient in a constraint. - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; // Clear a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint); + void ClearConstraint(MPConstraint* const constraint) override; // Change a coefficient in the linear objective. - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value); + void SetObjectiveOffset(double value) override; // Clear the objective from all its terms. - virtual void ClearObjective(); + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ // Number of simplex iterations - virtual int64 iterations() const; + int64 iterations() const override; // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; + int64 nodes() const override; // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; + double best_objective_bound() const override; // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const; + MPSolver::BasisStatus row_status(int constraint_index) const override; // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const; + MPSolver::BasisStatus column_status(int variable_index) const override; // ----- Misc ----- // Query problem type. - virtual bool IsContinuous() const { return true; } - virtual bool IsLP() const { return true; } - virtual bool IsMIP() const { return false; } + bool IsContinuous() const override { return true; } + bool IsLP() const override { return true; } + bool IsMIP() const override { return false; } - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual std::string SolverVersion() const { return "Clp " CLP_VERSION; } + std::string SolverVersion() const override { return "Clp " CLP_VERSION; } - virtual void* underlying_solver() { + void* underlying_solver() override { return reinterpret_cast(clp_.get()); } @@ -117,18 +117,18 @@ class CLPInterface : public MPSolverInterface { void CreateDummyVariableForEmptyConstraints(); // Set all parameters in the underlying solver. - virtual void SetParameters(const MPSolverParameters& param); + void SetParameters(const MPSolverParameters& param) override; // Reset to their default value the parameters for which CLP has a // stateful API. To be called after the solve so that the next solve // starts from a clean parameter state. void ResetParameters(); // Set each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; // Transforms basis status from CLP enum to MPSolver::BasisStatus. MPSolver::BasisStatus TransformCLPBasisStatus( diff --git a/src/linear_solver/glop_interface.cc b/src/linear_solver/glop_interface.cc index beffb2a02c..7df55eeedf 100644 --- a/src/linear_solver/glop_interface.cc +++ b/src/linear_solver/glop_interface.cc @@ -106,55 +106,55 @@ MPSolver::BasisStatus TranslateConstraintStatus(glop::ConstraintStatus status) { class GLOPInterface : public MPSolverInterface { public: explicit GLOPInterface(MPSolver* const solver); - virtual ~GLOPInterface(); + ~GLOPInterface() override; // ----- Solve ----- - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- - virtual void Reset(); - virtual void SetOptimizationDirection(bool maximize); - virtual void SetVariableBounds(int index, double lb, double ub); - virtual void SetVariableInteger(int index, bool integer); - virtual void SetConstraintBounds(int index, double lb, double ub); - virtual void AddRowConstraint(MPConstraint* const ct); - virtual void AddVariable(MPVariable* const var); - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); - virtual void ClearConstraint(MPConstraint* const constraint); - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); - virtual void SetObjectiveOffset(double value); - virtual void ClearObjective(); + void Reset() override; + void SetOptimizationDirection(bool maximize) override; + void SetVariableBounds(int index, double lb, double ub) override; + void SetVariableInteger(int index, bool integer) override; + void SetConstraintBounds(int index, double lb, double ub) override; + void AddRowConstraint(MPConstraint* const ct) override; + void AddVariable(MPVariable* const var) override; + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; + void ClearConstraint(MPConstraint* const constraint) override; + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; + void SetObjectiveOffset(double value) override; + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ - virtual int64 iterations() const; - virtual int64 nodes() const; - virtual double best_objective_bound() const; - virtual MPSolver::BasisStatus row_status(int constraint_index) const; - virtual MPSolver::BasisStatus column_status(int variable_index) const; + int64 iterations() const override; + int64 nodes() const override; + double best_objective_bound() const override; + MPSolver::BasisStatus row_status(int constraint_index) const override; + MPSolver::BasisStatus column_status(int variable_index) const override; // ----- Misc ----- - virtual bool IsContinuous() const; - virtual bool IsLP() const; - virtual bool IsMIP() const; + bool IsContinuous() const override; + bool IsLP() const override; + bool IsMIP() const override; - virtual std::string SolverVersion() const; - virtual void* underlying_solver(); + std::string SolverVersion() const override; + void* underlying_solver() override; - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual void SetParameters(const MPSolverParameters& param); - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); - virtual bool ReadParameterFile(const std::string& filename); + void SetParameters(const MPSolverParameters& param) override; + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; + bool ReadParameterFile(const std::string& filename) override; private: void NonIncrementalChange(); diff --git a/src/linear_solver/glpk_interface.cc b/src/linear_solver/glpk_interface.cc index 751044220a..160395d738 100644 --- a/src/linear_solver/glpk_interface.cc +++ b/src/linear_solver/glpk_interface.cc @@ -93,91 +93,91 @@ class GLPKInterface : public MPSolverInterface { public: // Constructor that takes a name for the underlying glpk solver. GLPKInterface(MPSolver* const solver, bool mip); - ~GLPKInterface(); + ~GLPKInterface() override; // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); + void SetOptimizationDirection(bool maximize) override; // ----- Solve ----- // Solve the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- // Resets extracted model - virtual void Reset(); + void Reset() override; // Modify bounds. - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); + void SetVariableBounds(int var_index, double lb, double ub) override; + void SetVariableInteger(int var_index, bool integer) override; + void SetConstraintBounds(int row_index, double lb, double ub) override; // Add Constraint incrementally. - void AddRowConstraint(MPConstraint* const ct); + void AddRowConstraint(MPConstraint* const ct) override; // Add variable incrementally. - void AddVariable(MPVariable* const var); + void AddVariable(MPVariable* const var) override; // Change a coefficient in a constraint. - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; // Clear a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint); + void ClearConstraint(MPConstraint* const constraint) override; // Change a coefficient in the linear objective - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value); + void SetObjectiveOffset(double value) override; // Clear the objective from all its terms. - virtual void ClearObjective(); + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ // Number of simplex iterations - virtual int64 iterations() const; + int64 iterations() const override; // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; + int64 nodes() const override; // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; + double best_objective_bound() const override; // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const; + MPSolver::BasisStatus row_status(int constraint_index) const override; // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const; + MPSolver::BasisStatus column_status(int variable_index) const override; // Checks whether a feasible solution exists. - virtual bool CheckSolutionExists() const; + bool CheckSolutionExists() const override; // Checks whether information on the best objective bound exists. - virtual bool CheckBestObjectiveBoundExists() const; + bool CheckBestObjectiveBoundExists() const override; // ----- Misc ----- // Query problem type. - virtual bool IsContinuous() const { return IsLP(); } - virtual bool IsLP() const { return !mip_; } - virtual bool IsMIP() const { return mip_; } + bool IsContinuous() const override { return IsLP(); } + bool IsLP() const override { return !mip_; } + bool IsMIP() const override { return mip_; } - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual std::string SolverVersion() const { + std::string SolverVersion() const override { return StringPrintf("GLPK %s", glp_version()); } - virtual void* underlying_solver() { return reinterpret_cast(lp_); } + void* underlying_solver() override { return reinterpret_cast(lp_); } - virtual double ComputeExactConditionNumber() const; + double ComputeExactConditionNumber() const override; private: // Configure the solver's parameters. void ConfigureGLPKParameters(const MPSolverParameters& param); // Set all parameters in the underlying solver. - virtual void SetParameters(const MPSolverParameters& param); + void SetParameters(const MPSolverParameters& param) override; // Set each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; void ExtractOldConstraints(); void ExtractOneConstraint(MPConstraint* const constraint, int* const indices, diff --git a/src/linear_solver/gurobi_interface.cc b/src/linear_solver/gurobi_interface.cc index 6feb39fee0..41ccb47287 100644 --- a/src/linear_solver/gurobi_interface.cc +++ b/src/linear_solver/gurobi_interface.cc @@ -44,75 +44,75 @@ class GurobiInterface : public MPSolverInterface { public: // Constructor that takes a name for the underlying GRB solver. explicit GurobiInterface(MPSolver* const solver, bool mip); - ~GurobiInterface(); + ~GurobiInterface() override; // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); + void SetOptimizationDirection(bool maximize) override; // ----- Solve ----- // Solves the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- // Resets extracted model - virtual void Reset(); + void Reset() override; // Modifies bounds. - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); + void SetVariableBounds(int var_index, double lb, double ub) override; + void SetVariableInteger(int var_index, bool integer) override; + void SetConstraintBounds(int row_index, double lb, double ub) override; // Adds Constraint incrementally. - void AddRowConstraint(MPConstraint* const ct); + void AddRowConstraint(MPConstraint* const ct) override; // Adds variable incrementally. - void AddVariable(MPVariable* const var); + void AddVariable(MPVariable* const var) override; // Changes a coefficient in a constraint. - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; // Clears a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint); + void ClearConstraint(MPConstraint* const constraint) override; // Changes a coefficient in the linear objective - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; // Changes the constant term in the linear objective. - virtual void SetObjectiveOffset(double value); + void SetObjectiveOffset(double value) override; // Clears the objective from all its terms. - virtual void ClearObjective(); + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ // Number of simplex or interior-point iterations - virtual int64 iterations() const; + int64 iterations() const override; // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; + int64 nodes() const override; // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; + double best_objective_bound() const override; // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const; + MPSolver::BasisStatus row_status(int constraint_index) const override; // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const; + MPSolver::BasisStatus column_status(int variable_index) const override; // ----- Misc ----- // Queries problem type. - virtual bool IsContinuous() const { return IsLP(); } - virtual bool IsLP() const { return !mip_; } - virtual bool IsMIP() const { return mip_; } + bool IsContinuous() const override { return IsLP(); } + bool IsLP() const override { return !mip_; } + bool IsMIP() const override { return mip_; } - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual std::string SolverVersion() const { + std::string SolverVersion() const override { int major, minor, technical; GRBversion(&major, &minor, &technical); return StringPrintf("Gurobi library version %d.%d.%d\n", major, minor, technical); } - virtual void* underlying_solver() { return reinterpret_cast(model_); } + void* underlying_solver() override { return reinterpret_cast(model_); } - virtual double ComputeExactConditionNumber() const { + double ComputeExactConditionNumber() const override { if (!IsContinuous()) { LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" << " GUROBI_MIXED_INTEGER_PROGRAMMING"; @@ -137,17 +137,17 @@ class GurobiInterface : public MPSolverInterface { private: // Sets all parameters in the underlying solver. - virtual void SetParameters(const MPSolverParameters& param); + void SetParameters(const MPSolverParameters& param) override; // Sets each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; - virtual bool ReadParameterFile(const std::string& filename); - virtual std::string ValidFileExtensionForParameterFile() const; + bool ReadParameterFile(const std::string& filename) override; + std::string ValidFileExtensionForParameterFile() const override; MPSolver::BasisStatus TransformGRBVarBasisStatus(int gurobi_basis_status) const; diff --git a/src/linear_solver/scip_interface.cc b/src/linear_solver/scip_interface.cc index d4a8fbaa62..43cc7a8a1b 100644 --- a/src/linear_solver/scip_interface.cc +++ b/src/linear_solver/scip_interface.cc @@ -53,72 +53,72 @@ class SCIPInterface : public MPSolverInterface { public: // Constructor that takes a name for the underlying SCIP solver. explicit SCIPInterface(MPSolver* const solver); - ~SCIPInterface(); + ~SCIPInterface() override; // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); + void SetOptimizationDirection(bool maximize) override; // ----- Solve ----- // Solve the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(const MPSolverParameters& param); + MPSolver::ResultStatus Solve(const MPSolverParameters& param) override; // ----- Model modifications and extraction ----- // Resets extracted model - virtual void Reset(); + void Reset() override; // Modify bounds. - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); + void SetVariableBounds(int var_index, double lb, double ub) override; + void SetVariableInteger(int var_index, bool integer) override; + void SetConstraintBounds(int row_index, double lb, double ub) override; // Add Constraint incrementally. - void AddRowConstraint(MPConstraint* const ct); + void AddRowConstraint(MPConstraint* const ct) override; // Add variable incrementally. - void AddVariable(MPVariable* const var); + void AddVariable(MPVariable* const var) override; // Change a coefficient in a constraint. - virtual void SetCoefficient(MPConstraint* const constraint, - const MPVariable* const variable, - double new_value, double old_value); + void SetCoefficient(MPConstraint* const constraint, + const MPVariable* const variable, double new_value, + double old_value) override; // Clear a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint); + void ClearConstraint(MPConstraint* const constraint) override; // Change a coefficient in the linear objective - virtual void SetObjectiveCoefficient(const MPVariable* const variable, - double coefficient); + void SetObjectiveCoefficient(const MPVariable* const variable, + double coefficient) override; // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value); + void SetObjectiveOffset(double value) override; // Clear the objective from all its terms. - virtual void ClearObjective(); + void ClearObjective() override; // ------ Query statistics on the solution and the solve ------ // Number of simplex iterations - virtual int64 iterations() const; + int64 iterations() const override; // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; + int64 nodes() const override; // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; + double best_objective_bound() const override; // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const { + MPSolver::BasisStatus row_status(int constraint_index) const override { LOG(FATAL) << "Basis status only available for continuous problems"; return MPSolver::FREE; } // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const { + MPSolver::BasisStatus column_status(int variable_index) const override { LOG(FATAL) << "Basis status only available for continuous problems"; return MPSolver::FREE; } // ----- Misc ----- // Query problem type. - virtual bool IsContinuous() const { return false; } - virtual bool IsLP() const { return false; } - virtual bool IsMIP() const { return true; } + bool IsContinuous() const override { return false; } + bool IsLP() const override { return false; } + bool IsMIP() const override { return true; } - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); + void ExtractNewVariables() override; + void ExtractNewConstraints() override; + void ExtractObjective() override; - virtual std::string SolverVersion() const { + std::string SolverVersion() const override { return StringPrintf("SCIP %d.%d.%d [LP solver: %s]", SCIPmajorVersion(), SCIPminorVersion(), SCIPtechVersion(), SCIPlpiGetSolverName()); @@ -129,21 +129,21 @@ class SCIPInterface : public MPSolverInterface { return true; } - virtual void* underlying_solver() { return reinterpret_cast(scip_); } + void* underlying_solver() override { return reinterpret_cast(scip_); } private: // Set all parameters in the underlying solver. - virtual void SetParameters(const MPSolverParameters& param); + void SetParameters(const MPSolverParameters& param) override; // Set each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); + void SetRelativeMipGap(double value) override; + void SetPrimalTolerance(double value) override; + void SetDualTolerance(double value) override; + void SetPresolveMode(int value) override; + void SetScalingMode(int value) override; + void SetLpAlgorithm(int value) override; - virtual bool ReadParameterFile(const std::string& filename); - virtual std::string ValidFileExtensionForParameterFile() const; + bool ReadParameterFile(const std::string& filename) override; + std::string ValidFileExtensionForParameterFile() const override; void CreateSCIP(); void DeleteSCIP();