OR-Tools  8.1
linear_solver.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
134 #ifndef OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
135 #define OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
136 
137 #include <functional>
138 #include <limits>
139 #include <map>
140 #include <memory>
141 #include <string>
142 #include <utility>
143 #include <vector>
144 
145 #include "absl/container/flat_hash_map.h"
146 #include "absl/status/status.h"
147 #include "absl/strings/match.h"
148 #include "absl/strings/str_format.h"
149 #include "absl/types/optional.h"
152 #include "ortools/base/logging.h"
153 #include "ortools/base/macros.h"
154 #include "ortools/base/timer.h"
159 
160 ABSL_DECLARE_FLAG(bool, linear_solver_enable_verbose_output);
161 
162 namespace operations_research {
163 
164 constexpr double kDefaultPrimalTolerance = 1e-07;
165 
166 class MPConstraint;
167 class MPObjective;
168 class MPSolverInterface;
169 class MPSolverParameters;
170 class MPVariable;
171 
172 // There is a homonymous version taking a MPSolver::OptimizationProblemType.
173 bool SolverTypeIsMip(MPModelRequest::SolverType solver_type);
174 
179 class MPSolver {
180  public:
188  // Linear programming problems.
189  // ----------------------------
192  GLOP_LINEAR_PROGRAMMING = 2, // Recommended default value. Made in Google.
193 
194  // Integer programming problems.
195  // -----------------------------
196  SCIP_MIXED_INTEGER_PROGRAMMING = 3, // Recommended default value.
199 
200  // Commercial software (need license).
207 
208  // Boolean optimization problem (requires only integer variables and works
209  // best with only Boolean variables).
211 
212  // SAT based solver (requires only integer and Boolean variables).
213  // If you pass it mixed integer problems, it will scale coefficients to
214  // integer values, and solver continuous variables as integral variables.
216 
217  // Dedicated knapsack solvers.
219  };
220 
222  MPSolver(const std::string& name, OptimizationProblemType problem_type);
223  virtual ~MPSolver();
224 
253  static MPSolver* CreateSolver(const std::string& solver_id);
254 
260 
266  static bool ParseSolverType(absl::string_view solver_id,
268 
274  const std::string& solver_id);
275 
276  bool IsMIP() const;
277 
279  const std::string& Name() const {
280  return name_; // Set at construction.
281  }
282 
285  return problem_type_; // Set at construction.
286  }
287 
293  void Clear();
294 
296  int NumVariables() const { return variables_.size(); }
297 
302  const std::vector<MPVariable*>& variables() const { return variables_; }
303 
309  MPVariable* LookupVariableOrNull(const std::string& var_name) const;
310 
318  MPVariable* MakeVar(double lb, double ub, bool integer,
319  const std::string& name);
320 
322  MPVariable* MakeNumVar(double lb, double ub, const std::string& name);
323 
325  MPVariable* MakeIntVar(double lb, double ub, const std::string& name);
326 
328  MPVariable* MakeBoolVar(const std::string& name);
329 
344  void MakeVarArray(int nb, double lb, double ub, bool integer,
345  const std::string& name_prefix,
346  std::vector<MPVariable*>* vars);
347 
349  void MakeNumVarArray(int nb, double lb, double ub, const std::string& name,
350  std::vector<MPVariable*>* vars);
351 
353  void MakeIntVarArray(int nb, double lb, double ub, const std::string& name,
354  std::vector<MPVariable*>* vars);
355 
357  void MakeBoolVarArray(int nb, const std::string& name,
358  std::vector<MPVariable*>* vars);
359 
361  int NumConstraints() const { return constraints_.size(); }
362 
368  const std::vector<MPConstraint*>& constraints() const { return constraints_; }
369 
378  const std::string& constraint_name) const;
379 
388  MPConstraint* MakeRowConstraint(double lb, double ub);
389 
392 
394  MPConstraint* MakeRowConstraint(double lb, double ub,
395  const std::string& name);
396 
398  MPConstraint* MakeRowConstraint(const std::string& name);
399 
405 
408  const std::string& name);
409 
416  const MPObjective& Objective() const { return *objective_; }
417 
419  MPObjective* MutableObjective() { return objective_.get(); }
420 
441  NOT_SOLVED = 6
442  };
443 
446 
448  ResultStatus Solve(const MPSolverParameters& param);
449 
454  void Write(const std::string& file_name);
455 
462  std::vector<double> ComputeConstraintActivities() const;
463 
482  bool VerifySolution(double tolerance, bool log_errors) const;
483 
492  void Reset();
493 
501  bool InterruptSolve();
502 
510  MPSolverResponseStatus LoadModelFromProto(const MPModelProto& input_model,
511  std::string* error_message);
520  const MPModelProto& input_model, std::string* error_message);
521 
523  void FillSolutionResponseProto(MPSolutionResponse* response) const;
524 
540  static void SolveWithProto(const MPModelRequest& model_request,
541  MPSolutionResponse* response);
542 
544  void ExportModelToProto(MPModelProto* output_model) const;
545 
577  absl::Status LoadSolutionFromProto(
578  const MPSolutionResponse& response,
579  double tolerance = kDefaultPrimalTolerance);
580 
585  absl::Status ClampSolutionWithinBounds();
586 
593  bool ExportModelAsLpFormat(bool obfuscate, std::string* model_str) const;
594  bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscate,
595  std::string* model_str) const;
596 
607  absl::Status SetNumThreads(int num_threads);
608 
610  int GetNumThreads() const { return num_threads_; }
611 
618  bool SetSolverSpecificParametersAsString(const std::string& parameters);
620  return solver_specific_parameter_string_;
621  }
622 
636  void SetHint(std::vector<std::pair<const MPVariable*, double> > hint);
637 
642  enum BasisStatus {
643  FREE = 0,
647  BASIC
648  };
649 
661  void SetStartingLpBasis(
662  const std::vector<MPSolver::BasisStatus>& variable_statuses,
663  const std::vector<MPSolver::BasisStatus>& constraint_statuses);
664 
670  static double infinity() { return std::numeric_limits<double>::infinity(); }
671 
680  bool OutputIsEnabled() const;
681 
683  void EnableOutput();
684 
686  void SuppressOutput();
687 
688  absl::Duration TimeLimit() const { return time_limit_; }
689  void SetTimeLimit(absl::Duration time_limit) {
690  DCHECK_GE(time_limit, absl::ZeroDuration());
691  time_limit_ = time_limit;
692  }
693 
694  absl::Duration DurationSinceConstruction() const {
695  return absl::Now() - construction_time_;
696  }
697 
699  int64 iterations() const;
700 
706  int64 nodes() const;
707 
709  std::string SolverVersion() const;
710 
724  void* underlying_solver();
725 
749  double ComputeExactConditionNumber() const;
750 
765  ABSL_MUST_USE_RESULT bool NextSolution();
766 
767  // Does not take ownership of "mp_callback".
768  //
769  // As of 2019-10-22, only SCIP and Gurobi support Callbacks.
770  // SCIP does not support suggesting a heuristic solution in the callback.
771  //
772  // See go/mpsolver-callbacks for additional documentation.
773  void SetCallback(MPCallback* mp_callback);
774  bool SupportsCallbacks() const;
775 
776  // DEPRECATED: Use TimeLimit() and SetTimeLimit(absl::Duration) instead.
777  // NOTE: These deprecated functions used the convention time_limit = 0 to mean
778  // "no limit", which now corresponds to time_limit_ = InfiniteDuration().
779  int64 time_limit() const {
780  return time_limit_ == absl::InfiniteDuration()
781  ? 0
782  : absl::ToInt64Milliseconds(time_limit_);
783  }
784  void set_time_limit(int64 time_limit_milliseconds) {
785  SetTimeLimit(time_limit_milliseconds == 0
786  ? absl::InfiniteDuration()
787  : absl::Milliseconds(time_limit_milliseconds));
788  }
789  double time_limit_in_secs() const {
790  return static_cast<double>(time_limit()) / 1000.0;
791  }
792 
793  // DEPRECATED: Use DurationSinceConstruction() instead.
794  int64 wall_time() const {
795  return absl::ToInt64Milliseconds(DurationSinceConstruction());
796  }
797 
798  // Supports search and loading Gurobi shared library.
799  static bool LoadGurobiSharedLibrary();
800  static void SetGurobiLibraryPath(const std::string& full_library_path);
801 
802  friend class GLPKInterface;
803  friend class CLPInterface;
804  friend class CBCInterface;
805  friend class SCIPInterface;
806  friend class GurobiInterface;
807  friend class CplexInterface;
808  friend class XpressInterface;
809  friend class SLMInterface;
810  friend class MPSolverInterface;
811  friend class GLOPInterface;
812  friend class BopInterface;
813  friend class SatInterface;
814  friend class KnapsackInterface;
815 
816  // Debugging: verify that the given MPVariable* belongs to this solver.
817  bool OwnsVariable(const MPVariable* var) const;
818 
819  private:
820  // Computes the size of the constraint with the largest number of
821  // coefficients with index in [min_constraint_index,
822  // max_constraint_index)
823  int ComputeMaxConstraintSize(int min_constraint_index,
824  int max_constraint_index) const;
825 
826  // Returns true if the model has constraints with lower bound > upper bound.
827  bool HasInfeasibleConstraints() const;
828 
829  // Returns true if the model has at least 1 integer variable.
830  bool HasIntegerVariables() const;
831 
832  // Generates the map from variable names to their indices.
833  void GenerateVariableNameIndex() const;
834 
835  // Generates the map from constraint names to their indices.
836  void GenerateConstraintNameIndex() const;
837 
838  // Checks licenses for commercial solver, and checks shared library loading
839  // for or-tools.
840  static bool GurobiIsCorrectlyInstalled();
841 
842  // The name of the linear programming problem.
843  const std::string name_;
844 
845  // The type of the linear programming problem.
846  const OptimizationProblemType problem_type_;
847 
848  // The solver interface.
849  std::unique_ptr<MPSolverInterface> interface_;
850 
851  // The vector of variables in the problem.
852  std::vector<MPVariable*> variables_;
853  // A map from a variable's name to its index in variables_.
854  mutable absl::optional<absl::flat_hash_map<std::string, int> >
855  variable_name_to_index_;
856  // Whether variables have been extracted to the underlying interface.
857  std::vector<bool> variable_is_extracted_;
858 
859  // The vector of constraints in the problem.
860  std::vector<MPConstraint*> constraints_;
861  // A map from a constraint's name to its index in constraints_.
862  mutable absl::optional<absl::flat_hash_map<std::string, int> >
863  constraint_name_to_index_;
864  // Whether constraints have been extracted to the underlying interface.
865  std::vector<bool> constraint_is_extracted_;
866 
867  // The linear objective function.
868  std::unique_ptr<MPObjective> objective_;
869 
870  // Initial values for all or some of the problem variables that can be
871  // exploited as a starting hint by a solver.
872  //
873  // Note(user): as of 05/05/2015, we can't use >> because of some SWIG errors.
874  //
875  // TODO(user): replace by two vectors, a std::vector<bool> to indicate if a
876  // hint is provided and a std::vector<double> for the hint value.
877  std::vector<std::pair<const MPVariable*, double> > solution_hint_;
878 
879  absl::Duration time_limit_ = absl::InfiniteDuration(); // Default = No limit.
880 
881  const absl::Time construction_time_;
882 
883  // Permanent storage for the number of threads.
884  int num_threads_ = 1;
885 
886  // Permanent storage for SetSolverSpecificParametersAsString().
887  std::string solver_specific_parameter_string_;
888 
889  MPSolverResponseStatus LoadModelFromProtoInternal(
890  const MPModelProto& input_model, bool clear_names,
891  bool check_model_validity, std::string* error_message);
892 
894 };
895 
897  return SolverTypeIsMip(static_cast<MPModelRequest::SolverType>(solver_type));
898 }
899 
900 const absl::string_view ToString(
901  MPSolver::OptimizationProblemType optimization_problem_type);
902 
903 inline std::ostream& operator<<(
904  std::ostream& os,
905  MPSolver::OptimizationProblemType optimization_problem_type) {
906  return os << ToString(optimization_problem_type);
907 }
908 
909 inline std::ostream& operator<<(std::ostream& os,
910  MPSolver::ResultStatus status) {
911  return os << ProtoEnumToString<MPSolverResponseStatus>(
912  static_cast<MPSolverResponseStatus>(status));
913 }
914 
915 bool AbslParseFlag(absl::string_view text,
917  std::string* error);
918 
919 inline std::string AbslUnparseFlag(
920  MPSolver::OptimizationProblemType solver_type) {
921  return std::string(ToString(solver_type));
922 }
923 
925 class MPObjective {
926  public:
931  void Clear();
932 
939  void SetCoefficient(const MPVariable* const var, double coeff);
940 
946  double GetCoefficient(const MPVariable* const var) const;
947 
953  const absl::flat_hash_map<const MPVariable*, double>& terms() const {
954  return coefficients_;
955  }
956 
958  void SetOffset(double value);
959 
961  double offset() const { return offset_; }
962 
967  void OptimizeLinearExpr(const LinearExpr& linear_expr, bool is_maximization);
968 
970  void MaximizeLinearExpr(const LinearExpr& linear_expr) {
971  OptimizeLinearExpr(linear_expr, true);
972  }
974  void MinimizeLinearExpr(const LinearExpr& linear_expr) {
975  OptimizeLinearExpr(linear_expr, false);
976  }
977 
979  void AddLinearExpr(const LinearExpr& linear_expr);
980 
982  void SetOptimizationDirection(bool maximize);
983 
986 
989 
991  bool maximization() const;
992 
994  bool minimization() const;
995 
1007  double Value() const;
1008 
1015  double BestBound() const;
1016 
1017  private:
1018  friend class MPSolver;
1019  friend class MPSolverInterface;
1020  friend class CBCInterface;
1021  friend class CLPInterface;
1022  friend class GLPKInterface;
1023  friend class SCIPInterface;
1024  friend class SLMInterface;
1025  friend class GurobiInterface;
1026  friend class CplexInterface;
1027  friend class XpressInterface;
1028  friend class GLOPInterface;
1029  friend class BopInterface;
1030  friend class SatInterface;
1031  friend class KnapsackInterface;
1032 
1033  // Constructor. An objective points to a single MPSolverInterface
1034  // that is specified in the constructor. An objective cannot belong
1035  // to several models.
1036  // At construction, an MPObjective has no terms (which is equivalent
1037  // on having a coefficient of 0 for all variables), and an offset of 0.
1038  explicit MPObjective(MPSolverInterface* const interface_in)
1039  : interface_(interface_in), coefficients_(1), offset_(0.0) {}
1040 
1041  MPSolverInterface* const interface_;
1042 
1043  // Mapping var -> coefficient.
1044  absl::flat_hash_map<const MPVariable*, double> coefficients_;
1045  // Constant term.
1046  double offset_;
1047 
1049 };
1050 
1052 class MPVariable {
1053  public:
1055  const std::string& name() const { return name_; }
1056 
1058  void SetInteger(bool integer);
1059 
1061  bool integer() const { return integer_; }
1062 
1070  double solution_value() const;
1071 
1073  int index() const { return index_; }
1074 
1076  double lb() const { return lb_; }
1077 
1079  double ub() const { return ub_; }
1080 
1082  void SetLB(double lb) { SetBounds(lb, ub_); }
1083 
1085  void SetUB(double ub) { SetBounds(lb_, ub); }
1086 
1088  void SetBounds(double lb, double ub);
1089 
1096  double unrounded_solution_value() const;
1097 
1102  double reduced_cost() const;
1103 
1111 
1122  int branching_priority() const { return branching_priority_; }
1123  void SetBranchingPriority(int priority);
1124 
1125  protected:
1126  friend class MPSolver;
1127  friend class MPSolverInterface;
1128  friend class CBCInterface;
1129  friend class CLPInterface;
1130  friend class GLPKInterface;
1131  friend class SCIPInterface;
1132  friend class SLMInterface;
1133  friend class GurobiInterface;
1134  friend class CplexInterface;
1135  friend class XpressInterface;
1136  friend class GLOPInterface;
1138  friend class BopInterface;
1139  friend class SatInterface;
1140  friend class KnapsackInterface;
1141 
1142  // Constructor. A variable points to a single MPSolverInterface that
1143  // is specified in the constructor. A variable cannot belong to
1144  // several models.
1145  MPVariable(int index, double lb, double ub, bool integer,
1146  const std::string& name, MPSolverInterface* const interface_in)
1147  : index_(index),
1148  lb_(lb),
1149  ub_(ub),
1150  integer_(integer),
1151  name_(name.empty() ? absl::StrFormat("auto_v_%09d", index) : name),
1152  solution_value_(0.0),
1153  reduced_cost_(0.0),
1154  interface_(interface_in) {}
1155 
1156  void set_solution_value(double value) { solution_value_ = value; }
1157  void set_reduced_cost(double reduced_cost) { reduced_cost_ = reduced_cost; }
1158 
1159  private:
1160  const int index_;
1161  double lb_;
1162  double ub_;
1163  bool integer_;
1164  const std::string name_;
1165  double solution_value_;
1166  double reduced_cost_;
1167  int branching_priority_ = 0;
1168  MPSolverInterface* const interface_;
1170 };
1171 
1178  public:
1180  const std::string& name() const { return name_; }
1181 
1183  void Clear();
1184 
1191  void SetCoefficient(const MPVariable* const var, double coeff);
1192 
1197  double GetCoefficient(const MPVariable* const var) const;
1198 
1204  const absl::flat_hash_map<const MPVariable*, double>& terms() const {
1205  return coefficients_;
1206  }
1207 
1209  double lb() const { return lb_; }
1210 
1212  double ub() const { return ub_; }
1213 
1215  void SetLB(double lb) { SetBounds(lb, ub_); }
1216 
1218  void SetUB(double ub) { SetBounds(lb_, ub); }
1219 
1221  void SetBounds(double lb, double ub);
1222 
1224  bool is_lazy() const { return is_lazy_; }
1225 
1239  void set_is_lazy(bool laziness) { is_lazy_ = laziness; }
1240 
1241  const MPVariable* indicator_variable() const { return indicator_variable_; }
1242  bool indicator_value() const { return indicator_value_; }
1243 
1245  int index() const { return index_; }
1246 
1251  double dual_value() const;
1252 
1266 
1267  protected:
1268  friend class MPSolver;
1269  friend class MPSolverInterface;
1270  friend class CBCInterface;
1271  friend class CLPInterface;
1272  friend class GLPKInterface;
1273  friend class SCIPInterface;
1274  friend class SLMInterface;
1275  friend class GurobiInterface;
1276  friend class CplexInterface;
1277  friend class XpressInterface;
1278  friend class GLOPInterface;
1279  friend class BopInterface;
1280  friend class SatInterface;
1281  friend class KnapsackInterface;
1282 
1283  // Constructor. A constraint points to a single MPSolverInterface
1284  // that is specified in the constructor. A constraint cannot belong
1285  // to several models.
1286  MPConstraint(int index, double lb, double ub, const std::string& name,
1287  MPSolverInterface* const interface_in)
1288  : coefficients_(1),
1289  index_(index),
1290  lb_(lb),
1291  ub_(ub),
1292  name_(name.empty() ? absl::StrFormat("auto_c_%09d", index) : name),
1293  is_lazy_(false),
1294  indicator_variable_(nullptr),
1295  dual_value_(0.0),
1296  interface_(interface_in) {}
1297 
1298  void set_dual_value(double dual_value) { dual_value_ = dual_value; }
1299 
1300  private:
1301  // Returns true if the constraint contains variables that have not
1302  // been extracted yet.
1303  bool ContainsNewVariables();
1304 
1305  // Mapping var -> coefficient.
1306  absl::flat_hash_map<const MPVariable*, double> coefficients_;
1307 
1308  const int index_; // See index().
1309 
1310  // The lower bound for the linear constraint.
1311  double lb_;
1312 
1313  // The upper bound for the linear constraint.
1314  double ub_;
1315 
1316  // Name.
1317  const std::string name_;
1318 
1319  // True if the constraint is "lazy", i.e. the constraint is added to the
1320  // underlying Linear Programming solver only if it is violated.
1321  // By default this parameter is 'false'.
1322  bool is_lazy_;
1323 
1324  // If given, this constraint is only active if `indicator_variable_`'s value
1325  // is equal to `indicator_value_`.
1326  const MPVariable* indicator_variable_;
1327  bool indicator_value_;
1328 
1329  double dual_value_;
1330  MPSolverInterface* const interface_;
1332 };
1333 
1361  public:
1366 
1375  DUAL_TOLERANCE = 2
1376  };
1377 
1381  PRESOLVE = 1000,
1387  SCALING = 1003
1388  };
1389 
1395  PRESOLVE_ON = 1
1396  };
1397 
1401  DUAL = 10,
1403  PRIMAL = 11,
1405  BARRIER = 12
1406  };
1407 
1412 
1417  INCREMENTALITY_ON = 1
1418  };
1419 
1425  SCALING_ON = 1
1426  };
1427 
1428  // Placeholder value to indicate that a parameter is set to
1429  // the default value defined in the wrapper.
1430  static const double kDefaultDoubleParamValue;
1431  static const int kDefaultIntegerParamValue;
1432 
1433  // Placeholder value to indicate that a parameter is unknown.
1434  static const double kUnknownDoubleParamValue;
1435  static const int kUnknownIntegerParamValue;
1436 
1437  // Default values for parameters. Only parameters that define the
1438  // properties of the solution returned need to have a default value
1439  // (that is the same for all solvers). You can also define a default
1440  // value for performance parameters when you are confident it is a
1441  // good choice (example: always turn presolve on).
1442  static const double kDefaultRelativeMipGap;
1443  static const double kDefaultPrimalTolerance;
1444  static const double kDefaultDualTolerance;
1447 
1450 
1453 
1456 
1463 
1470 
1472  void Reset();
1473 
1475  double GetDoubleParam(MPSolverParameters::DoubleParam param) const;
1476 
1479 
1480  private:
1481  // Parameter value for each parameter.
1482  // @see DoubleParam
1483  // @see IntegerParam
1484  double relative_mip_gap_value_;
1485  double primal_tolerance_value_;
1486  double dual_tolerance_value_;
1487  int presolve_value_;
1488  int scaling_value_;
1489  int lp_algorithm_value_;
1490  int incrementality_value_;
1491 
1492  // Boolean value indicating whether each parameter is set to the
1493  // solver's default value. Only parameters for which the wrapper
1494  // does not define a default value need such an indicator.
1495  bool lp_algorithm_is_default_;
1496 
1497  DISALLOW_COPY_AND_ASSIGN(MPSolverParameters);
1498 };
1499 
1500 // Whether the given MPSolverResponseStatus (of a solve) would yield an RPC
1501 // error when happening on the linear solver stubby server, see
1502 // ./linear_solver_service.proto.
1503 // Note that RPC errors forbid to carry a response to the client, who can only
1504 // see the RPC error itself (error code + error message).
1506 
1507 // This class wraps the actual mathematical programming solvers. Each
1508 // solver (GLOP, CLP, CBC, GLPK, SCIP) has its own interface class that
1509 // derives from this abstract class. This class is never directly
1510 // accessed by the user.
1511 // @see glop_interface.cc
1512 // @see cbc_interface.cc
1513 // @see clp_interface.cc
1514 // @see glpk_interface.cc
1515 // @see scip_interface.cc
1517  public:
1519  // The underlying solver (CLP, GLPK, ...) and MPSolver are not in
1520  // sync for the model nor for the solution.
1522  // The underlying solver and MPSolver are in sync for the model
1523  // but not for the solution: the model has changed since the
1524  // solution was computed last.
1526  // The underlying solver and MPSolver are in sync for the model and
1527  // the solution.
1529  };
1530 
1531  // When the underlying solver does not provide the number of simplex
1532  // iterations.
1533  static constexpr int64 kUnknownNumberOfIterations = -1;
1534  // When the underlying solver does not provide the number of
1535  // branch-and-bound nodes.
1536  static constexpr int64 kUnknownNumberOfNodes = -1;
1537 
1538  // Constructor. The user will access the MPSolverInterface through the
1539  // MPSolver passed as argument.
1540  explicit MPSolverInterface(MPSolver* const solver);
1541  virtual ~MPSolverInterface();
1542 
1543  // ----- Solve -----
1544  // Solves problem with specified parameter values. Returns true if the
1545  // solution is optimal.
1547 
1548  // Directly solves a MPModelRequest, bypassing the MPSolver data structures
1549  // entirely. Returns {} (eg. absl::nullopt) if the feature is not supported by
1550  // the underlying solver.
1551  virtual absl::optional<MPSolutionResponse> DirectlySolveProto(
1552  const MPModelRequest& request) {
1553  return absl::nullopt;
1554  }
1555 
1556  // Writes the model using the solver internal write function. Currently only
1557  // available for GurobiInterface.
1558  virtual void Write(const std::string& filename);
1559 
1560  // ----- Model modifications and extraction -----
1561  // Resets extracted model.
1562  virtual void Reset() = 0;
1563 
1564  // Sets the optimization direction (min/max).
1565  virtual void SetOptimizationDirection(bool maximize) = 0;
1566 
1567  // Modifies bounds of an extracted variable.
1568  virtual void SetVariableBounds(int index, double lb, double ub) = 0;
1569 
1570  // Modifies integrality of an extracted variable.
1571  virtual void SetVariableInteger(int index, bool integer) = 0;
1572 
1573  // Modify bounds of an extracted variable.
1574  virtual void SetConstraintBounds(int index, double lb, double ub) = 0;
1575 
1576  // Adds a linear constraint.
1577  virtual void AddRowConstraint(MPConstraint* const ct) = 0;
1578 
1579  // Adds an indicator constraint. Returns true if the feature is supported by
1580  // the underlying solver.
1581  virtual bool AddIndicatorConstraint(MPConstraint* const ct) {
1582  LOG(ERROR) << "Solver doesn't support indicator constraints.";
1583  return false;
1584  }
1585 
1586  // Add a variable.
1587  virtual void AddVariable(MPVariable* const var) = 0;
1588 
1589  // Changes a coefficient in a constraint.
1590  virtual void SetCoefficient(MPConstraint* const constraint,
1591  const MPVariable* const variable,
1592  double new_value, double old_value) = 0;
1593 
1594  // Clears a constraint from all its terms.
1595  virtual void ClearConstraint(MPConstraint* const constraint) = 0;
1596 
1597  // Changes a coefficient in the linear objective.
1598  virtual void SetObjectiveCoefficient(const MPVariable* const variable,
1599  double coefficient) = 0;
1600 
1601  // Changes the constant term in the linear objective.
1602  virtual void SetObjectiveOffset(double value) = 0;
1603 
1604  // Clears the objective from all its terms.
1605  virtual void ClearObjective() = 0;
1606 
1607  virtual void BranchingPriorityChangedForVariable(int var_index) {}
1608  // ------ Query statistics on the solution and the solve ------
1609  // Returns the number of simplex iterations. The problem must be discrete,
1610  // otherwise it crashes, or returns kUnknownNumberOfIterations in NDEBUG mode.
1611  virtual int64 iterations() const = 0;
1612  // Returns the number of branch-and-bound nodes. The problem must be discrete,
1613  // otherwise it crashes, or returns kUnknownNumberOfNodes in NDEBUG mode.
1614  virtual int64 nodes() const = 0;
1615  // Returns the best objective bound. The problem must be discrete, otherwise
1616  // it crashes, or returns trivial bound (+/- inf) in NDEBUG mode.
1617  double best_objective_bound() const;
1618  // Returns the objective value of the best solution found so far.
1619  double objective_value() const;
1620 
1621  // Returns the basis status of a row.
1622  virtual MPSolver::BasisStatus row_status(int constraint_index) const = 0;
1623  // Returns the basis status of a constraint.
1624  virtual MPSolver::BasisStatus column_status(int variable_index) const = 0;
1625 
1626  // Checks whether the solution is synchronized with the model, i.e. whether
1627  // the model has changed since the solution was computed last.
1628  // If it isn't, it crashes in NDEBUG, and returns false othwerwise.
1629  bool CheckSolutionIsSynchronized() const;
1630  // Checks whether a feasible solution exists. The behavior is similar to
1631  // CheckSolutionIsSynchronized() above.
1632  virtual bool CheckSolutionExists() const;
1633  // Handy shortcut to do both checks above (it is often used).
1636  }
1637 
1638  // ----- Misc -----
1639  // Queries problem type. For simplicity, the distinction between
1640  // continuous and discrete is based on the declaration of the user
1641  // when the solver is created (example: GLPK_LINEAR_PROGRAMMING
1642  // vs. GLPK_MIXED_INTEGER_PROGRAMMING), not on the actual content of
1643  // the model.
1644  // Returns true if the problem is continuous.
1645  virtual bool IsContinuous() const = 0;
1646  // Returns true if the problem is continuous and linear.
1647  virtual bool IsLP() const = 0;
1648  // Returns true if the problem is discrete and linear.
1649  virtual bool IsMIP() const = 0;
1650 
1651  // Returns the index of the last variable extracted.
1653 
1654  bool variable_is_extracted(int var_index) const {
1655  return solver_->variable_is_extracted_[var_index];
1656  }
1657  void set_variable_as_extracted(int var_index, bool extracted) {
1658  solver_->variable_is_extracted_[var_index] = extracted;
1659  }
1660  bool constraint_is_extracted(int ct_index) const {
1661  return solver_->constraint_is_extracted_[ct_index];
1662  }
1663  void set_constraint_as_extracted(int ct_index, bool extracted) {
1664  solver_->constraint_is_extracted_[ct_index] = extracted;
1665  }
1666 
1667  // Returns the boolean indicating the verbosity of the solver output.
1668  bool quiet() const { return quiet_; }
1669  // Sets the boolean indicating the verbosity of the solver output.
1670  void set_quiet(bool quiet_value) { quiet_ = quiet_value; }
1671 
1672  // Returns the result status of the last solve.
1675  return result_status_;
1676  }
1677 
1678  // Returns a string describing the underlying solver and its version.
1679  virtual std::string SolverVersion() const = 0;
1680 
1681  // Returns the underlying solver.
1682  virtual void* underlying_solver() = 0;
1683 
1684  // Computes exact condition number. Only available for continuous
1685  // problems and only implemented in GLPK.
1686  virtual double ComputeExactConditionNumber() const;
1687 
1688  // See MPSolver::SetStartingLpBasis().
1689  virtual void SetStartingLpBasis(
1690  const std::vector<MPSolver::BasisStatus>& variable_statuses,
1691  const std::vector<MPSolver::BasisStatus>& constraint_statuses) {
1692  LOG(FATAL) << "Not supported by this solver.";
1693  }
1694 
1695  virtual bool InterruptSolve() { return false; }
1696 
1697  // See MPSolver::NextSolution() for contract.
1698  virtual bool NextSolution() { return false; }
1699 
1700  // See MPSolver::SetCallback() for details.
1701  virtual void SetCallback(MPCallback* mp_callback) {
1702  LOG(FATAL) << "Callbacks not supported for this solver.";
1703  }
1704 
1705  virtual bool SupportsCallbacks() const { return false; }
1706 
1707  friend class MPSolver;
1708 
1709  // To access the maximize_ bool and the MPSolver.
1710  friend class MPConstraint;
1711  friend class MPObjective;
1712 
1713  protected:
1715  // Indicates whether the model and the solution are synchronized.
1717  // Indicates whether the solve has reached optimality,
1718  // infeasibility, a limit, etc.
1720  // Optimization direction.
1722 
1723  // Index in MPSolver::variables_ of last constraint extracted.
1725  // Index in MPSolver::constraints_ of last variable extracted.
1727 
1728  // The value of the objective function.
1730 
1731  // The value of the best objective bound. Used only for MIP solvers.
1733 
1734  // Boolean indicator for the verbosity of the solver output.
1735  bool quiet_;
1736 
1737  // Index of dummy variable created for empty constraints or the
1738  // objective offset.
1739  static const int kDummyVariableIndex;
1740 
1741  // Extracts model stored in MPSolver.
1742  void ExtractModel();
1743  // Extracts the variables that have not been extracted yet.
1744  virtual void ExtractNewVariables() = 0;
1745  // Extracts the constraints that have not been extracted yet.
1746  virtual void ExtractNewConstraints() = 0;
1747  // Extracts the objective.
1748  virtual void ExtractObjective() = 0;
1749  // Resets the extraction information.
1751  // Change synchronization status from SOLUTION_SYNCHRONIZED to
1752  // MODEL_SYNCHRONIZED. To be used for model changes.
1754 
1755  // Sets parameters common to LP and MIP in the underlying solver.
1756  void SetCommonParameters(const MPSolverParameters& param);
1757  // Sets MIP specific parameters in the underlying solver.
1758  void SetMIPParameters(const MPSolverParameters& param);
1759  // Sets all parameters in the underlying solver.
1760  virtual void SetParameters(const MPSolverParameters& param) = 0;
1761  // Sets an unsupported double parameter.
1763  // Sets an unsupported integer parameter.
1764  virtual void SetUnsupportedIntegerParam(
1766  // Sets a supported double parameter to an unsupported value.
1768  double value);
1769  // Sets a supported integer parameter to an unsupported value.
1770  virtual void SetIntegerParamToUnsupportedValue(
1772  // Sets each parameter in the underlying solver.
1773  virtual void SetRelativeMipGap(double value) = 0;
1774  virtual void SetPrimalTolerance(double value) = 0;
1775  virtual void SetDualTolerance(double value) = 0;
1776  virtual void SetPresolveMode(int value) = 0;
1777 
1778  // Sets the number of threads to be used by the solver.
1779  virtual absl::Status SetNumThreads(int num_threads);
1780 
1781  // Pass solver specific parameters in text format. The format is
1782  // solver-specific and is the same as the corresponding solver configuration
1783  // file format. Returns true if the operation was successful.
1784  //
1785  // The default implementation of this method stores the parameters in a
1786  // temporary file and calls ReadParameterFile to import the parameter file
1787  // into the solver. Solvers that support passing the parameters directly can
1788  // override this method to skip the temporary file logic.
1790  const std::string& parameters);
1791 
1792  // Reads a solver-specific file of parameters and set them.
1793  // Returns true if there was no errors.
1794  virtual bool ReadParameterFile(const std::string& filename);
1795 
1796  // Returns a file extension like ".tmp", this is needed because some solvers
1797  // require a given extension for the ReadParameterFile() filename and we need
1798  // to know it to generate a temporary parameter file.
1799  virtual std::string ValidFileExtensionForParameterFile() const;
1800 
1801  // Sets the scaling mode.
1802  virtual void SetScalingMode(int value) = 0;
1803  virtual void SetLpAlgorithm(int value) = 0;
1804 };
1805 
1806 } // namespace operations_research
1807 
1808 #endif // OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
operations_research::MPSolverInterface::ExtractObjective
virtual void ExtractObjective()=0
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::MPSolverInterface::SetDoubleParamToUnsupportedValue
void SetDoubleParamToUnsupportedValue(MPSolverParameters::DoubleParam param, double value)
Definition: linear_solver.cc:1769
operations_research::MPSolver::SuppressOutput
void SuppressOutput()
Suppresses solver logging.
Definition: linear_solver.cc:1504
operations_research::MPCallback
Definition: linear_solver_callback.h:140
operations_research::MPSolver::MakeIntVar
MPVariable * MakeIntVar(double lb, double ub, const std::string &name)
Creates an integer variable.
Definition: linear_solver.cc:1105
operations_research::SolverTypeIsMip
bool SolverTypeIsMip(MPModelRequest::SolverType solver_type)
Definition: linear_solver.cc:65
response
SharedResponseManager * response
Definition: cp_model_solver.cc:2105
operations_research::MPConstraint::SetLB
void SetLB(double lb)
Sets the lower bound.
Definition: linear_solver.h:1215
problem_type
MPSolver::OptimizationProblemType problem_type
Definition: linear_solver.cc:503
integral_types.h
operations_research::MPSolverParameters::kDefaultIntegerParamValue
static const int kDefaultIntegerParamValue
Definition: linear_solver.h:1431
operations_research::LinearExpr
LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization...
Definition: linear_expr.h:114
operations_research::MPSolver::ExportModelAsLpFormat
bool ExportModelAsLpFormat(bool obfuscate, std::string *model_str) const
Shortcuts to the homonymous MPModelProtoExporter methods, via exporting to a MPModelProto with Export...
Definition: linear_solver.cc:1523
operations_research::MPSolver::CBC_MIXED_INTEGER_PROGRAMMING
@ CBC_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:198
operations_research::MPVariable::SetBounds
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
Definition: linear_solver.cc:299
operations_research::MPSolverInterface::SetParameters
virtual void SetParameters(const MPSolverParameters &param)=0
operations_research::MPObjective::BestBound
double BestBound() const
Returns the best objective bound.
Definition: linear_solver.cc:256
operations_research::MPObjective::Value
double Value() const
Returns the objective value of the best solution found so far.
Definition: linear_solver.cc:249
operations_research::MPVariable::SetInteger
void SetInteger(bool integer)
Sets the integrality requirement of the variable.
Definition: linear_solver.cc:308
operations_research::MPSolverInterface::column_status
virtual MPSolver::BasisStatus column_status(int variable_index) const =0
operations_research::MPConstraint::basis_status
MPSolver::BasisStatus basis_status() const
Advanced usage: returns the basis status of the constraint.
Definition: linear_solver.cc:145
operations_research::MPConstraint::XpressInterface
friend class XpressInterface
Definition: linear_solver.h:1277
operations_research::MPSolver::GLOP_LINEAR_PROGRAMMING
@ GLOP_LINEAR_PROGRAMMING
Definition: linear_solver.h:192
operations_research::MPSolverResponseStatus
MPSolverResponseStatus
Definition: linear_solver.pb.h:227
operations_research::MPSolver::NumVariables
int NumVariables() const
Returns the number of variables.
Definition: linear_solver.h:296
operations_research::MPSolverInterface::AddRowConstraint
virtual void AddRowConstraint(MPConstraint *const ct)=0
operations_research::MPSolverInterface::SetObjectiveOffset
virtual void SetObjectiveOffset(double value)=0
operations_research::MPSolver::SupportsCallbacks
bool SupportsCallbacks() const
Definition: linear_solver.cc:1582
operations_research::MPSolverInterface::SetScalingMode
virtual void SetScalingMode(int value)=0
operations_research::MPSolverInterface::MPSolverInterface
MPSolverInterface(MPSolver *const solver)
Definition: linear_solver.cc:1620
operations_research::MPSolver::GLPKInterface
friend class GLPKInterface
Definition: linear_solver.h:802
operations_research::MPSolver::XPRESS_LINEAR_PROGRAMMING
@ XPRESS_LINEAR_PROGRAMMING
Definition: linear_solver.h:205
LOG
#define LOG(severity)
Definition: base/logging.h:420
ERROR
const int ERROR
Definition: log_severity.h:32
operations_research::MPConstraint::set_dual_value
void set_dual_value(double dual_value)
Definition: linear_solver.h:1298
operations_research::MPSolverParameters::DUAL_TOLERANCE
@ DUAL_TOLERANCE
Advanced usage: tolerance for dual feasibility of basic solutions.
Definition: linear_solver.h:1375
linear_solver.pb.h
operations_research::MPSolver::ProblemType
virtual OptimizationProblemType ProblemType() const
Returns the optimization problem type set at construction.
Definition: linear_solver.h:284
operations_research::MPSolver::OPTIMAL
@ OPTIMAL
optimal.
Definition: linear_solver.h:429
operations_research::MPSolverParameters::ScalingValues
ScalingValues
Advanced usage: Scaling options.
Definition: linear_solver.h:1421
operations_research::MPVariable::set_solution_value
void set_solution_value(double value)
Definition: linear_solver.h:1156
operations_research::MPVariable::integer
bool integer() const
Returns the integrality requirement of the variable.
Definition: linear_solver.h:1061
operations_research::MPSolverParameters::LP_ALGORITHM
@ LP_ALGORITHM
Algorithm to solve linear programs.
Definition: linear_solver.h:1383
operations_research::MPConstraint::SetBounds
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
Definition: linear_solver.cc:127
FATAL
const int FATAL
Definition: log_severity.h:32
operations_research::MPVariable::index
int index() const
Returns the index of the variable in the MPSolver::variables_.
Definition: linear_solver.h:1073
operations_research::MPObjective::SetMinimization
void SetMinimization()
Sets the optimization direction to minimize.
Definition: linear_solver.h:985
operations_research::MPSolver::Objective
const MPObjective & Objective() const
Returns the objective object.
Definition: linear_solver.h:416
operations_research::MPSolver::UNBOUNDED
@ UNBOUNDED
proven unbounded.
Definition: linear_solver.h:435
operations_research::MPObjective::GetCoefficient
double GetCoefficient(const MPVariable *const var) const
Gets the coefficient of a given variable in the objective.
Definition: linear_solver.cc:171
operations_research::MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING
@ CPLEX_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:204
operations_research::MPSolverInterface::BranchingPriorityChangedForVariable
virtual void BranchingPriorityChangedForVariable(int var_index)
Definition: linear_solver.h:1607
operations_research::MPSolverParameters::MPSolverParameters
MPSolverParameters()
The constructor sets all parameters to their default value.
Definition: linear_solver.cc:1851
proto_utils.h
operations_research::MPSolver::ExportModelAsMpsFormat
bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscate, std::string *model_str) const
Definition: linear_solver.cc:1535
logging.h
operations_research::MPObjective::OptimizeLinearExpr
void OptimizeLinearExpr(const LinearExpr &linear_expr, bool is_maximization)
Resets the current objective to take the value of linear_expr, and sets the objective direction to ma...
Definition: linear_solver.cc:207
operations_research::MPSolverInterface::quiet_
bool quiet_
Definition: linear_solver.h:1735
operations_research::MPSolverInterface::last_constraint_index_
int last_constraint_index_
Definition: linear_solver.h:1724
operations_research::MPSolver
This mathematical programming (MP) solver class is the main class though which users build and solve ...
Definition: linear_solver.h:179
operations_research::MPSolver::XpressInterface
friend class XpressInterface
Definition: linear_solver.h:808
operations_research::MPSolver::Reset
void Reset()
Advanced usage: resets extracted model to solve from scratch.
Definition: linear_solver.cc:1076
operations_research::MPObjective::KnapsackInterface
friend class KnapsackInterface
Definition: linear_solver.h:1031
operations_research::MPSolverInterface::Solve
virtual MPSolver::ResultStatus Solve(const MPSolverParameters &param)=0
operations_research::MPConstraint::terms
const absl::flat_hash_map< const MPVariable *, double > & terms() const
Returns a map from variables to their coefficients in the constraint.
Definition: linear_solver.h:1204
value
int64 value
Definition: demon_profiler.cc:43
operations_research::MPSolverInterface::AddIndicatorConstraint
virtual bool AddIndicatorConstraint(MPConstraint *const ct)
Definition: linear_solver.h:1581
operations_research::MPSolver::SolverVersion
std::string SolverVersion() const
Returns a string describing the underlying solver and its version.
Definition: linear_solver.cc:327
operations_research::MPSolverInterface::MODEL_SYNCHRONIZED
@ MODEL_SYNCHRONIZED
Definition: linear_solver.h:1525
operations_research::MPObjective::AddLinearExpr
void AddLinearExpr(const LinearExpr &linear_expr)
Adds linear_expr to the current objective, does not change the direction.
Definition: linear_solver.cc:219
operations_research::MPSolver::set_time_limit
void set_time_limit(int64 time_limit_milliseconds)
Definition: linear_solver.h:784
operations_research::MPSolver::MutableObjective
MPObjective * MutableObjective()
Returns the mutable objective object.
Definition: linear_solver.h:419
linear_expr.h
This file allows you to write natural code (like a mathematical equation) to model optimization probl...
operations_research::MPSolverInterface::IsLP
virtual bool IsLP() const =0
operations_research::MPVariable::name
const std::string & name() const
Returns the name of the variable.
Definition: linear_solver.h:1055
operations_research::MPVariable::KnapsackInterface
friend class KnapsackInterface
Definition: linear_solver.h:1140
macros.h
operations_research::MPSolver::LookupVariableOrNull
MPVariable * LookupVariableOrNull(const std::string &var_name) const
Looks up a variable by name, and returns nullptr if it does not exist.
Definition: linear_solver.cc:616
operations_research::MPSolver::DurationSinceConstruction
absl::Duration DurationSinceConstruction() const
Definition: linear_solver.h:694
operations_research::MPSolver::InterruptSolve
bool InterruptSolve()
Interrupts the Solve() execution to terminate processing if possible.
Definition: linear_solver.cc:1078
operations_research::MPSolver::ComputeExactConditionNumber
double ComputeExactConditionNumber() const
Advanced usage: computes the exact condition number of the current scaled basis: L1norm(B) * L1norm(i...
Definition: linear_solver.cc:1510
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::MPObjective::offset
double offset() const
Gets the constant term in the objective.
Definition: linear_solver.h:961
operations_research::MPSolverParameters::kDefaultRelativeMipGap
static const double kDefaultRelativeMipGap
Definition: linear_solver.h:1442
operations_research::MPSolverInterface::SetStartingLpBasis
virtual void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
Definition: linear_solver.h:1689
operations_research::MPSolver::ClampSolutionWithinBounds
absl::Status ClampSolutionWithinBounds()
Resets values of out of bound variables to the corresponding bound and returns an error if any of the...
Definition: linear_solver.cc:1322
operations_research::MPSolverInterface::ClearObjective
virtual void ClearObjective()=0
operations_research::MPSolverParameters::kUnknownIntegerParamValue
static const int kUnknownIntegerParamValue
Definition: linear_solver.h:1435
operations_research::MPObjective::maximization
bool maximization() const
Is the optimization direction set to maximize?
Definition: linear_solver.cc:245
operations_research::MPSolverInterface::NextSolution
virtual bool NextSolution()
Definition: linear_solver.h:1698
operations_research::MPSolverInterface::InvalidateSolutionSynchronization
void InvalidateSolutionSynchronization()
Definition: linear_solver.cc:1718
operations_research::MPSolver::MODEL_INVALID
@ MODEL_INVALID
the model is trivially invalid (NaN coefficients, etc).
Definition: linear_solver.h:439
operations_research::SCIPInterface
Definition: scip_interface.cc:58
operations_research::MPSolverInterface
Definition: linear_solver.h:1516
operations_research::MPVariable::unrounded_solution_value
double unrounded_solution_value() const
Advanced usage: unrounded solution value.
Definition: linear_solver.cc:273
operations_research::MPSolver::Name
const std::string & Name() const
Returns the name of the model set at construction.
Definition: linear_solver.h:279
operations_research::MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING
@ GLPK_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:197
operations_research::MPSolver::variables
const std::vector< MPVariable * > & variables() const
Returns the array of variables handled by the MPSolver.
Definition: linear_solver.h:302
operations_research::MPSolverInterface::SupportsCallbacks
virtual bool SupportsCallbacks() const
Definition: linear_solver.h:1705
operations_research::MPSolverParameters::SCALING_OFF
@ SCALING_OFF
Scaling is off.
Definition: linear_solver.h:1423
operations_research::BopInterface
Definition: bop_interface.cc:50
operations_research::MPSolverInterface::SynchronizationStatus
SynchronizationStatus
Definition: linear_solver.h:1518
operations_research::MPSolver::ABNORMAL
@ ABNORMAL
abnormal, i.e., error of some kind.
Definition: linear_solver.h:437
operations_research::MPConstraint::ub
double ub() const
Returns the upper bound.
Definition: linear_solver.h:1212
operations_research::MPSolverInterface::DirectlySolveProto
virtual absl::optional< MPSolutionResponse > DirectlySolveProto(const MPModelRequest &request)
Definition: linear_solver.h:1551
int64
int64_t int64
Definition: integral_types.h:34
operations_research::MPVariable::solution_value
double solution_value() const
Returns the value of the variable in the current solution.
Definition: linear_solver.cc:264
operations_research::MPConstraint::index
int index() const
Returns the index of the constraint in the MPSolver::constraints_.
Definition: linear_solver.h:1245
operations_research::MPVariable::SLMInterface
friend class SLMInterface
Definition: linear_solver.h:1132
operations_research::MPConstraint::indicator_variable
const MPVariable * indicator_variable() const
Definition: linear_solver.h:1241
operations_research::ToString
const absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)
Definition: linear_solver.cc:569
operations_research::MPSolverParameters::kUnknownDoubleParamValue
static const double kUnknownDoubleParamValue
Definition: linear_solver.h:1434
operations_research::MPConstraint::name
const std::string & name() const
Returns the name of the constraint.
Definition: linear_solver.h:1180
operations_research::MPObjective::SetCoefficient
void SetCoefficient(const MPVariable *const var, double coeff)
Sets the coefficient of the variable in the objective.
Definition: linear_solver.cc:177
ABSL_DECLARE_FLAG
ABSL_DECLARE_FLAG(bool, linear_solver_enable_verbose_output)
index
int index
Definition: pack.cc:508
operations_research::MPSolverParameters
This class stores parameter settings for LP and MIP solvers.
Definition: linear_solver.h:1360
offset_
const int64 offset_
Definition: interval.cc:2076
operations_research::MPConstraint::SetUB
void SetUB(double ub)
Sets the upper bound.
Definition: linear_solver.h:1218
operations_research::MPConstraint
The class for constraints of a Mathematical Programming (MP) model.
Definition: linear_solver.h:1177
operations_research::MPConstraint::GetCoefficient
double GetCoefficient(const MPVariable *const var) const
Gets the coefficient of a given variable on the constraint (which is 0 if the variable does not appea...
Definition: linear_solver.cc:90
operations_research::MPObjective::GLPKInterface
friend class GLPKInterface
Definition: linear_solver.h:1022
operations_research::AbslUnparseFlag
std::string AbslUnparseFlag(MPSolver::OptimizationProblemType solver_type)
Definition: linear_solver.h:919
operations_research::MPConstraint::set_is_lazy
void set_is_lazy(bool laziness)
Advanced usage: sets the constraint "laziness".
Definition: linear_solver.h:1239
operations_research::MPSolverInterface::constraint_is_extracted
bool constraint_is_extracted(int ct_index) const
Definition: linear_solver.h:1660
operations_research::MPVariable::basis_status
MPSolver::BasisStatus basis_status() const
Advanced usage: returns the basis status of the variable in the current solution (only available for ...
Definition: linear_solver.cc:287
operations_research::MPSolver::NextSolution
ABSL_MUST_USE_RESULT bool NextSolution()
Some solvers (MIP only, not LP) can produce multiple solutions to the problem.
Definition: linear_solver.cc:1576
operations_research::MPSolverParameters::PresolveValues
PresolveValues
For each categorical parameter, enumeration of possible values.
Definition: linear_solver.h:1391
operations_research::MPSolverInterface::InterruptSolve
virtual bool InterruptSolve()
Definition: linear_solver.h:1695
operations_research::MPSolver::KnapsackInterface
friend class KnapsackInterface
Definition: linear_solver.h:814
operations_research::MPSolverParameters::PRESOLVE_ON
@ PRESOLVE_ON
Presolve is on.
Definition: linear_solver.h:1395
operations_research::MPSolverInterface::SetLpAlgorithm
virtual void SetLpAlgorithm(int value)=0
operations_research::MPSolverInterface::objective_value_
double objective_value_
Definition: linear_solver.h:1729
operations_research::AbslParseFlag
bool AbslParseFlag(const absl::string_view text, MPSolver::OptimizationProblemType *solver_type, std::string *error)
Definition: linear_solver.cc:581
operations_research::MPSolverInterface::last_variable_index
int last_variable_index() const
Definition: linear_solver.h:1652
operations_research::MPConstraint::GLPKInterface
friend class GLPKInterface
Definition: linear_solver.h:1272
operations_research::MPSolver::OutputIsEnabled
bool OutputIsEnabled() const
Controls (or queries) the amount of output produced by the underlying solver.
Definition: linear_solver.cc:1500
operations_research::MPSolverParameters::GetIntegerParam
int GetIntegerParam(MPSolverParameters::IntegerParam param) const
Returns the value of an integer parameter.
Definition: linear_solver.cc:1999
operations_research::MPSolverInterface::objective_value
double objective_value() const
Definition: linear_solver.cc:1695
operations_research::MPSolver::MakeIntVarArray
void MakeIntVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of integer variables.
Definition: linear_solver.cc:1137
operations_research::MPSolver::MakeBoolVar
MPVariable * MakeBoolVar(const std::string &name)
Creates a boolean variable.
Definition: linear_solver.cc:1110
operations_research::MPSolverParameters::SCALING_ON
@ SCALING_ON
Scaling is on.
Definition: linear_solver.h:1425
operations_research::MPSolver::wall_time
int64 wall_time() const
Definition: linear_solver.h:794
operations_research::MPSolverInterface::SetPresolveMode
virtual void SetPresolveMode(int value)=0
operations_research::MPSolverInterface::SetConstraintBounds
virtual void SetConstraintBounds(int index, double lb, double ub)=0
operations_research::MPSolverInterface::Write
virtual void Write(const std::string &filename)
Definition: linear_solver.cc:1633
operations_research::MPObjective::SetOffset
void SetOffset(double value)
Sets the constant term in the objective.
Definition: linear_solver.cc:192
operations_research::MPSolverInterface::ResetExtractionInformation
void ResetExtractionInformation()
Definition: linear_solver.cc:1665
operations_research::MPSolverParameters::INCREMENTALITY_ON
@ INCREMENTALITY_ON
Reuse results from previous solve as much as the underlying solver allows.
Definition: linear_solver.h:1417
operations_research::MPSolver::BASIC
@ BASIC
Definition: linear_solver.h:647
operations_research::MPSolverInterface::kUnknownNumberOfIterations
static constexpr int64 kUnknownNumberOfIterations
Definition: linear_solver.h:1533
operations_research::GLOPInterface
Definition: glop_interface.cc:34
operations_research::MPSolver::LoadModelFromProto
MPSolverResponseStatus LoadModelFromProto(const MPModelProto &input_model, std::string *error_message)
Loads model from protocol buffer.
Definition: linear_solver.cc:636
operations_research::MPSolverInterface::solver_
MPSolver *const solver_
Definition: linear_solver.h:1714
operations_research::MPSolverInterface::IsContinuous
virtual bool IsContinuous() const =0
operations_research::MPSolverInterface::IsMIP
virtual bool IsMIP() const =0
operations_research::MPSolver::constraints
const std::vector< MPConstraint * > & constraints() const
Returns the array of constraints handled by the MPSolver.
Definition: linear_solver.h:368
operations_research::MPSolverInterface::SetUnsupportedDoubleParam
void SetUnsupportedDoubleParam(MPSolverParameters::DoubleParam param)
Definition: linear_solver.cc:1761
operations_research::MPSolver::GLPK_LINEAR_PROGRAMMING
@ GLPK_LINEAR_PROGRAMMING
Definition: linear_solver.h:191
operations_research::MPSolver::NumConstraints
int NumConstraints() const
Returns the number of constraints.
Definition: linear_solver.h:361
operations_research::MPSolver::infinity
static double infinity()
Infinity.
Definition: linear_solver.h:670
operations_research::MPSolver::NOT_SOLVED
@ NOT_SOLVED
not been solved yet.
Definition: linear_solver.h:441
operations_research::MPSolver::BOP_INTEGER_PROGRAMMING
@ BOP_INTEGER_PROGRAMMING
Definition: linear_solver.h:210
operations_research::MPConstraint::KnapsackInterface
friend class KnapsackInterface
Definition: linear_solver.h:1281
operations_research::MPSolverInterface::kUnknownNumberOfNodes
static constexpr int64 kUnknownNumberOfNodes
Definition: linear_solver.h:1536
operations_research::MPSolver::SetSolverSpecificParametersAsString
bool SetSolverSpecificParametersAsString(const std::string &parameters)
Advanced usage: pass solver specific parameters in text format.
Definition: linear_solver.cc:346
timer.h
operations_research::MPVariable::branching_priority
int branching_priority() const
Advanced usage: Certain MIP solvers (e.g.
Definition: linear_solver.h:1122
operations_research::MPSolverParameters::PRESOLVE
@ PRESOLVE
Advanced usage: presolve mode.
Definition: linear_solver.h:1381
operations_research::MPVariable::set_reduced_cost
void set_reduced_cost(double reduced_cost)
Definition: linear_solver.h:1157
operations_research::MPSolver::KNAPSACK_MIXED_INTEGER_PROGRAMMING
@ KNAPSACK_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:218
operations_research::MPConstraint::CplexInterface
friend class CplexInterface
Definition: linear_solver.h:1276
operations_research::MPSolver::FREE
@ FREE
Definition: linear_solver.h:643
operations_research::MPSolver::MakeNumVar
MPVariable * MakeNumVar(double lb, double ub, const std::string &name)
Creates a continuous variable.
Definition: linear_solver.cc:1100
operations_research::MPSolverParameters::kDefaultPresolve
static const PresolveValues kDefaultPresolve
Definition: linear_solver.h:1445
operations_research::MPSolverInterface::ValidFileExtensionForParameterFile
virtual std::string ValidFileExtensionForParameterFile() const
Definition: linear_solver.cc:1828
operations_research::MPSolverInterface::SetVariableBounds
virtual void SetVariableBounds(int index, double lb, double ub)=0
operations_research::MPSolver::TimeLimit
absl::Duration TimeLimit() const
Definition: linear_solver.h:688
operations_research::MPSolverInterface::SOLUTION_SYNCHRONIZED
@ SOLUTION_SYNCHRONIZED
Definition: linear_solver.h:1528
operations_research::MPSolverParameters::ResetIntegerParam
void ResetIntegerParam(MPSolverParameters::IntegerParam param)
Sets an integer parameter to its default value (default value defined in MPSolverParameters if it exi...
Definition: linear_solver.cc:1945
operations_research::MPSolverInterface::SetDualTolerance
virtual void SetDualTolerance(double value)=0
operations_research::MPSolver::SetTimeLimit
void SetTimeLimit(absl::Duration time_limit)
Definition: linear_solver.h:689
operations_research::MPSolverInterface::SetSolverSpecificParametersAsString
virtual bool SetSolverSpecificParametersAsString(const std::string &parameters)
Definition: linear_solver.cc:1785
operations_research::MPSolverParameters::Reset
void Reset()
Sets all parameters to their default value.
Definition: linear_solver.cc:1970
operations_research::MPSolverParameters::kDefaultIncrementality
static const IncrementalityValues kDefaultIncrementality
Definition: linear_solver.h:1446
operations_research::CBCInterface
Definition: cbc_interface.cc:45
operations_research::MPSolverParameters::kDefaultDoubleParamValue
static const double kDefaultDoubleParamValue
Definition: linear_solver.h:1430
operations_research::MPSolver::MakeVar
MPVariable * MakeVar(double lb, double ub, bool integer, const std::string &name)
Creates a variable with the given bounds, integrality requirement and name.
Definition: linear_solver.cc:1086
operations_research::MPObjective::minimization
bool minimization() const
Is the optimization direction set to minimize?
Definition: linear_solver.cc:247
operations_research::MPSolver::Write
void Write(const std::string &file_name)
Writes the model using the solver internal write function.
Definition: linear_solver.cc:1257
operations_research::MPSolverInterface::SetCallback
virtual void SetCallback(MPCallback *mp_callback)
Definition: linear_solver.h:1701
operations_research::MPSolver::Solve
ResultStatus Solve()
Solves the problem using the default parameter values.
Definition: linear_solver.cc:1225
operations_research::MPSolverInterface::SetIntegerParamToUnsupportedValue
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
Definition: linear_solver.cc:1774
operations_research::MPSolverInterface::ComputeExactConditionNumber
virtual double ComputeExactConditionNumber() const
Definition: linear_solver.cc:1724
operations_research::MPSolver::time_limit
int64 time_limit() const
Definition: linear_solver.h:779
operations_research::MPSolverInterface::ReadParameterFile
virtual bool ReadParameterFile(const std::string &filename)
Definition: linear_solver.cc:1823
operations_research::MPSolver::BasisStatus
BasisStatus
Advanced usage: possible basis status values for a variable and the slack variable of a linear constr...
Definition: linear_solver.h:642
operations_research::MPSolverInterface::CheckSolutionIsSynchronizedAndExists
bool CheckSolutionIsSynchronizedAndExists() const
Definition: linear_solver.h:1634
operations_research::MPSolver::LookupConstraintOrNull
MPConstraint * LookupConstraintOrNull(const std::string &constraint_name) const
Looks up a constraint by name, and returns nullptr if it does not exist.
Definition: linear_solver.cc:625
operations_research::MPSolverParameters::kDefaultPrimalTolerance
static const double kDefaultPrimalTolerance
Definition: linear_solver.h:1443
operations_research::operator<<
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
Definition: constraint_solver/assignment.cc:1089
operations_research::MPObjective::Clear
void Clear()
Clears the offset, all variables and coefficients, and the optimization direction.
Definition: linear_solver.cc:227
objective_
IntVar *const objective_
Definition: search.cc:2951
operations_research::MPObjective::CplexInterface
friend class CplexInterface
Definition: linear_solver.h:1026
operations_research::MPSolverParameters::SetDoubleParam
void SetDoubleParam(MPSolverParameters::DoubleParam param, double value)
Sets a double parameter to a specific value.
Definition: linear_solver.cc:1861
operations_research::MPVariable::lb
double lb() const
Returns the lower bound.
Definition: linear_solver.h:1076
operations_research::MPSolver::SetGurobiLibraryPath
static void SetGurobiLibraryPath(const std::string &full_library_path)
Definition: gurobi_environment.cc:276
ct
const Constraint * ct
Definition: demon_profiler.cc:42
operations_research::MPVariable::SetUB
void SetUB(double ub)
Sets the upper bound.
Definition: linear_solver.h:1085
operations_research::CLPInterface
Definition: clp_interface.cc:42
operations_research::MPSolver::SLMInterface
friend class SLMInterface
Definition: linear_solver.h:809
operations_research::MPSolverInterface::Reset
virtual void Reset()=0
operations_research::MPObjective::MinimizeLinearExpr
void MinimizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to minimize linear_expr.
Definition: linear_solver.h:974
operations_research::MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING
@ SCIP_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:196
operations_research::MPSolverInterface::SetUnsupportedIntegerParam
virtual void SetUnsupportedIntegerParam(MPSolverParameters::IntegerParam param)
Definition: linear_solver.cc:1765
operations_research::MPSolver::MPSolver
MPSolver(const std::string &name, OptimizationProblemType problem_type)
Create a solver with the given name and underlying solver backend.
Definition: linear_solver.cc:445
operations_research::MPSolverInterface::SetOptimizationDirection
virtual void SetOptimizationDirection(bool maximize)=0
operations_research::MPSolverInterface::SetObjectiveCoefficient
virtual void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient)=0
operations_research::MPSolverParameters::INCREMENTALITY_OFF
@ INCREMENTALITY_OFF
Start solve from scratch.
Definition: linear_solver.h:1411
operations_research::MPSolver::AT_UPPER_BOUND
@ AT_UPPER_BOUND
Definition: linear_solver.h:645
operations_research::MPSolver::iterations
int64 iterations() const
Returns the number of simplex iterations.
Definition: linear_solver.cc:1506
operations_research::MPVariable::ub
double ub() const
Returns the upper bound.
Definition: linear_solver.h:1079
operations_research::MPSolverInterface::sync_status_
SynchronizationStatus sync_status_
Definition: linear_solver.h:1716
operations_research::SatInterface
Definition: sat_interface.cc:41
operations_research::MPVariable::MPVariableSolutionValueTest
friend class MPVariableSolutionValueTest
Definition: linear_solver.h:1137
operations_research::LinearRange
An expression of the form:
Definition: linear_expr.h:192
operations_research::MPSolver::SetCallback
void SetCallback(MPCallback *mp_callback)
Definition: linear_solver.cc:1578
operations_research::MPConstraint::MPConstraint
MPConstraint(int index, double lb, double ub, const std::string &name, MPSolverInterface *const interface_in)
Definition: linear_solver.h:1286
operations_research::MPSolver::MakeNumVarArray
void MakeNumVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of continuous variables.
Definition: linear_solver.cc:1131
operations_research::MPSolver::SetNumThreads
absl::Status SetNumThreads(int num_threads)
Sets the number of threads to use by the underlying solver.
Definition: linear_solver.cc:335
operations_research::MPObjective::XpressInterface
friend class XpressInterface
Definition: linear_solver.h:1027
operations_research::MPSolverInterface::SetRelativeMipGap
virtual void SetRelativeMipGap(double value)=0
operations_research::MPSolver::GUROBI_LINEAR_PROGRAMMING
@ GUROBI_LINEAR_PROGRAMMING
Definition: linear_solver.h:201
operations_research::MPSolverInterface::SolverVersion
virtual std::string SolverVersion() const =0
operations_research::MPSolver::time_limit_in_secs
double time_limit_in_secs() const
Definition: linear_solver.h:789
operations_research::MPSolverParameters::PRIMAL_TOLERANCE
@ PRIMAL_TOLERANCE
Advanced usage: tolerance for primal feasibility of basic solutions.
Definition: linear_solver.h:1373
operations_research::MPSolverParameters::IncrementalityValues
IncrementalityValues
Advanced usage: Incrementality options.
Definition: linear_solver.h:1409
operations_research::MPSolver::ResultStatus
ResultStatus
The status of solving the problem.
Definition: linear_solver.h:427
operations_research::MPSolverInterface::variable_is_extracted
bool variable_is_extracted(int var_index) const
Definition: linear_solver.h:1654
operations_research::MPSolver::SetStartingLpBasis
void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
Advanced usage: Incrementality.
Definition: linear_solver.cc:1080
operations_research::MPSolver::GetSolverSpecificParametersAsString
std::string GetSolverSpecificParametersAsString() const
Definition: linear_solver.h:619
operations_research::MPSolver::VerifySolution
bool VerifySolution(double tolerance, bool log_errors) const
Advanced usage: Verifies the correctness of the solution.
Definition: linear_solver.cc:1356
operations_research::MPSolverInterface::result_status
MPSolver::ResultStatus result_status() const
Definition: linear_solver.h:1673
operations_research::MPSolver::LoadGurobiSharedLibrary
static bool LoadGurobiSharedLibrary()
Definition: gurobi_environment.cc:261
DCHECK_GE
#define DCHECK_GE(val1, val2)
Definition: base/logging.h:889
operations_research::MPSolverInterface::ExtractModel
void ExtractModel()
Definition: linear_solver.cc:1637
operations_research::MPSolverInterface::set_quiet
void set_quiet(bool quiet_value)
Definition: linear_solver.h:1670
operations_research::MPSolverInterface::SetVariableInteger
virtual void SetVariableInteger(int index, bool integer)=0
operations_research::MPSolverInterface::SetMIPParameters
void SetMIPParameters(const MPSolverParameters &param)
Definition: linear_solver.cc:1754
operations_research::MPSolverParameters::GetDoubleParam
double GetDoubleParam(MPSolverParameters::DoubleParam param) const
Returns the value of a double parameter.
Definition: linear_solver.cc:1980
operations_research::MPSolver::EnableOutput
void EnableOutput()
Enables solver logging.
Definition: linear_solver.cc:1502
operations_research::MPSolverParameters::kDefaultDualTolerance
static const double kDefaultDualTolerance
Definition: linear_solver.h:1444
operations_research::MPSolver::FIXED_VALUE
@ FIXED_VALUE
Definition: linear_solver.h:646
operations_research::MPSolver::MakeRowConstraint
MPConstraint * MakeRowConstraint()
Creates a constraint with -infinity and +infinity bounds.
Definition: linear_solver.cc:1152
operations_research::MPSolver::LoadSolutionFromProto
absl::Status LoadSolutionFromProto(const MPSolutionResponse &response, double tolerance=kDefaultPrimalTolerance)
Load a solution encoded in a protocol buffer onto this solver for easy access via the MPSolver interf...
Definition: linear_solver.cc:991
operations_research::MPConstraint::lb
double lb() const
Returns the lower bound.
Definition: linear_solver.h:1209
operations_research::MPSolver::SAT_INTEGER_PROGRAMMING
@ SAT_INTEGER_PROGRAMMING
Definition: linear_solver.h:215
operations_research::MPSolver::nodes
int64 nodes() const
Returns the number of branch-and-bound nodes evaluated during the solve.
Definition: linear_solver.cc:1508
operations_research::MPSolverInterface::row_status
virtual MPSolver::BasisStatus row_status(int constraint_index) const =0
operations_research::MPSolverInterface::ExtractNewConstraints
virtual void ExtractNewConstraints()=0
operations_research::MPSolver::SolveWithProto
static void SolveWithProto(const MPModelRequest &model_request, MPSolutionResponse *response)
Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSo...
Definition: linear_solver.cc:834
operations_research::MPSolverParameters::LpAlgorithmValues
LpAlgorithmValues
LP algorithm to use.
Definition: linear_solver.h:1399
operations_research::MPSolverInterface::set_variable_as_extracted
void set_variable_as_extracted(int var_index, bool extracted)
Definition: linear_solver.h:1657
operations_research::MPSolverParameters::SCALING
@ SCALING
Advanced usage: enable or disable matrix scaling.
Definition: linear_solver.h:1387
operations_research::MPSolver::IsMIP
bool IsMIP() const
Definition: linear_solver.cc:325
operations_research::MPVariable::MPVariable
MPVariable(int index, double lb, double ub, bool integer, const std::string &name, MPSolverInterface *const interface_in)
Definition: linear_solver.h:1145
operations_research::MPSolver::ComputeConstraintActivities
std::vector< double > ComputeConstraintActivities() const
Advanced usage: compute the "activities" of all constraints, which are the sums of their linear terms...
Definition: linear_solver.cc:1340
coefficient
int64 coefficient
Definition: routing_search.cc:972
operations_research::MPSolver::~MPSolver
virtual ~MPSolver()
Definition: linear_solver.cc:457
operations_research::MPSolverParameters::IntegerParam
IntegerParam
Enumeration of parameters that take integer or categorical values.
Definition: linear_solver.h:1379
operations_research::MPConstraint::is_lazy
bool is_lazy() const
Advanced usage: returns true if the constraint is "lazy" (see below).
Definition: linear_solver.h:1224
operations_research::MPSolver::CPLEX_LINEAR_PROGRAMMING
@ CPLEX_LINEAR_PROGRAMMING
Definition: linear_solver.h:203
operations_research::MPSolver::MakeVarArray
void MakeVarArray(int nb, double lb, double ub, bool integer, const std::string &name_prefix, std::vector< MPVariable * > *vars)
Creates an array of variables.
Definition: linear_solver.cc:1114
operations_research::MPVariable::XpressInterface
friend class XpressInterface
Definition: linear_solver.h:1135
operations_research::MPSolverParameters::ResetDoubleParam
void ResetDoubleParam(MPSolverParameters::DoubleParam param)
Sets a double parameter to its default value (default value defined in MPSolverParameters if it exist...
Definition: linear_solver.cc:1924
operations_research::MPSolverInterface::underlying_solver
virtual void * underlying_solver()=0
operations_research::MPSolverInterface::ExtractNewVariables
virtual void ExtractNewVariables()=0
operations_research::MPConstraint::indicator_value
bool indicator_value() const
Definition: linear_solver.h:1242
operations_research::MPSolverInterface::last_variable_index_
int last_variable_index_
Definition: linear_solver.h:1726
operations_research::MPSolver::underlying_solver
void * underlying_solver()
Advanced usage: returns the underlying solver.
Definition: linear_solver.cc:331
operations_research::MPSolverInterface::iterations
virtual int64 iterations() const =0
operations_research::MPObjective::SLMInterface
friend class SLMInterface
Definition: linear_solver.h:1024
operations_research::MPSolverParameters::RELATIVE_MIP_GAP
@ RELATIVE_MIP_GAP
Limit for relative MIP gap.
Definition: linear_solver.h:1365
operations_research::MPObjective::MaximizeLinearExpr
void MaximizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to maximize linear_expr.
Definition: linear_solver.h:970
operations_research::MPSolver::CLP_LINEAR_PROGRAMMING
@ CLP_LINEAR_PROGRAMMING
Definition: linear_solver.h:190
operations_research::MPSolverParameters::INCREMENTALITY
@ INCREMENTALITY
Advanced usage: incrementality from one solve to the next.
Definition: linear_solver.h:1385
operations_research::MPVariable::GLPKInterface
friend class GLPKInterface
Definition: linear_solver.h:1130
operations_research::MPSolverInterface::best_objective_bound
double best_objective_bound() const
Definition: linear_solver.cc:1700
operations_research::MPSolverInterface::SetPrimalTolerance
virtual void SetPrimalTolerance(double value)=0
operations_research::MPObjective::SetMaximization
void SetMaximization()
Sets the optimization direction to maximize.
Definition: linear_solver.h:988
operations_research::MPSolverInterface::quiet
bool quiet() const
Definition: linear_solver.h:1668
operations_research::MPVariable
The class for variables of a Mathematical Programming (MP) model.
Definition: linear_solver.h:1052
operations_research::MPSolver::FillSolutionResponseProto
void FillSolutionResponseProto(MPSolutionResponse *response) const
Encodes the current solution in a solution response protocol buffer.
Definition: linear_solver.cc:806
operations_research::MPSolver::OptimizationProblemType
OptimizationProblemType
The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP,...
Definition: linear_solver.h:187
operations_research::MPSolverInterface::nodes
virtual int64 nodes() const =0
operations_research::MPSolver::ExportModelToProto
void ExportModelToProto(MPModelProto *output_model) const
Exports model to protocol buffer.
Definition: linear_solver.cc:902
DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:29
operations_research::MPSolverInterface::AddVariable
virtual void AddVariable(MPVariable *const var)=0
operations_research::MPObjective::terms
const absl::flat_hash_map< const MPVariable *, double > & terms() const
Returns a map from variables to their coefficients in the objective.
Definition: linear_solver.h:953
operations_research::MPSolverInterface::ClearConstraint
virtual void ClearConstraint(MPConstraint *const constraint)=0
operations_research::MPSolverInterface::SetCommonParameters
void SetCommonParameters(const MPSolverParameters &param)
Definition: linear_solver.cc:1733
operations_research::MPConstraint::SetCoefficient
void SetCoefficient(const MPVariable *const var, double coeff)
Sets the coefficient of the variable on the constraint.
Definition: linear_solver.cc:96
operations_research::MPSolverInterface::SetNumThreads
virtual absl::Status SetNumThreads(int num_threads)
Definition: linear_solver.cc:1780
operations_research::MPConstraint::dual_value
double dual_value() const
Advanced usage: returns the dual value of the constraint in the current solution (only available for ...
Definition: linear_solver.cc:136
operations_research::MPObjective::SetOptimizationDirection
void SetOptimizationDirection(bool maximize)
Sets the optimization direction (maximize: true or minimize: false).
Definition: linear_solver.cc:234
operations_research::MPSolver::ParseSolverType
static bool ParseSolverType(absl::string_view solver_id, OptimizationProblemType *type)
Parses the name of the solver.
Definition: linear_solver.cc:532
operations_research::MPSolver::INFEASIBLE
@ INFEASIBLE
proven infeasible.
Definition: linear_solver.h:433
operations_research::MPSolverInterface::SetCoefficient
virtual void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value)=0
absl
Definition: cleanup.h:22
linear_solver_callback.h
operations_research::MPSolver::CreateSolver
static MPSolver * CreateSolver(const std::string &solver_id)
Recommended factory method to create a MPSolver instance, especially in non C++ languages.
Definition: linear_solver.cc:602
operations_research::MPSolverResponseStatusIsRpcError
bool MPSolverResponseStatusIsRpcError(MPSolverResponseStatus status)
Definition: linear_solver.cc:1586
operations_research::MPConstraint::SLMInterface
friend class SLMInterface
Definition: linear_solver.h:1274
operations_research::MPSolver::MakeBoolVarArray
void MakeBoolVarArray(int nb, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of boolean variables.
Definition: linear_solver.cc:1143
operations_research::MPSolverParameters::PRIMAL
@ PRIMAL
Primal simplex.
Definition: linear_solver.h:1403
operations_research::kDefaultPrimalTolerance
constexpr double kDefaultPrimalTolerance
Definition: linear_solver.h:164
operations_research::MPSolverParameters::DoubleParam
DoubleParam
Enumeration of parameters that take continuous values.
Definition: linear_solver.h:1363
operations_research::MPSolverParameters::PRESOLVE_OFF
@ PRESOLVE_OFF
Presolve is off.
Definition: linear_solver.h:1393
operations_research::MPSolver::LoadModelFromProtoWithUniqueNamesOrDie
MPSolverResponseStatus LoadModelFromProtoWithUniqueNamesOrDie(const MPModelProto &input_model, std::string *error_message)
Loads model from protocol buffer.
Definition: linear_solver.cc:647
operations_research::MPConstraint::Clear
void Clear()
Clears all variables and coefficients. Does not clear the bounds.
Definition: linear_solver.cc:122
operations_research::MPVariable::SetLB
void SetLB(double lb)
Sets the lower bound.
Definition: linear_solver.h:1082
operations_research::MPSolverInterface::CheckSolutionExists
virtual bool CheckSolutionExists() const
Definition: linear_solver.cc:1685
operations_research::MPSolverInterface::MUST_RELOAD
@ MUST_RELOAD
Definition: linear_solver.h:1521
operations_research::MPSolver::Clear
void Clear()
Clears the objective (including the optimization direction), all variables and constraints.
Definition: linear_solver.cc:1058
operations_research::MPSolver::SetHint
void SetHint(std::vector< std::pair< const MPVariable *, double > > hint)
Sets a hint for solution.
Definition: linear_solver.cc:1552
operations_research::MPSolverParameters::SetIntegerParam
void SetIntegerParam(MPSolverParameters::IntegerParam param, int value)
Sets a integer parameter to a specific value.
Definition: linear_solver.cc:1882
operations_research::MPSolverInterface::kDummyVariableIndex
static const int kDummyVariableIndex
Definition: linear_solver.h:1739
operations_research::MPSolver::OwnsVariable
bool OwnsVariable(const MPVariable *var) const
Definition: linear_solver.cc:1514
operations_research::MPSolverInterface::CheckSolutionIsSynchronized
bool CheckSolutionIsSynchronized() const
Definition: linear_solver.cc:1673
operations_research::GurobiInterface
Definition: gurobi_interface.cc:72
operations_research::MPObjective
A class to express a linear objective.
Definition: linear_solver.h:925
operations_research::MPSolver::AT_LOWER_BOUND
@ AT_LOWER_BOUND
Definition: linear_solver.h:644
operations_research::MPVariable::SetBranchingPriority
void SetBranchingPriority(int priority)
Definition: linear_solver.cc:317
operations_research::MPSolverInterface::result_status_
MPSolver::ResultStatus result_status_
Definition: linear_solver.h:1719
operations_research::MPSolverInterface::maximize_
bool maximize_
Definition: linear_solver.h:1721
commandlineflags.h
operations_research::MPSolverInterface::set_constraint_as_extracted
void set_constraint_as_extracted(int ct_index, bool extracted)
Definition: linear_solver.h:1663
operations_research::MPSolver::GetNumThreads
int GetNumThreads() const
Returns the number of threads to be used during solve.
Definition: linear_solver.h:610
parameters
SatParameters parameters
Definition: cp_model_fz_solver.cc:108
operations_research::MPSolver::SupportsProblemType
static bool SupportsProblemType(OptimizationProblemType problem_type)
Whether the given problem type is supported (this will depend on the targets that you linked).
Definition: linear_solver.cc:460
name
const std::string name
Definition: default_search.cc:808
operations_research::MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING
@ XPRESS_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:206
operations_research::MPSolver::ParseSolverTypeOrDie
static OptimizationProblemType ParseSolverTypeOrDie(const std::string &solver_id)
Parses the name of the solver and returns the correct optimization type or dies.
Definition: linear_solver.cc:594
operations_research::MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING
@ GUROBI_MIXED_INTEGER_PROGRAMMING
Definition: linear_solver.h:202
operations_research::MPVariable::reduced_cost
double reduced_cost() const
Advanced usage: returns the reduced cost of the variable in the current solution (only available for ...
Definition: linear_solver.cc:278
operations_research::MPSolver::CplexInterface
friend class CplexInterface
Definition: linear_solver.h:807
operations_research::MPSolverParameters::DUAL
@ DUAL
Dual simplex.
Definition: linear_solver.h:1401
operations_research::MPSolverParameters::BARRIER
@ BARRIER
Barrier algorithm.
Definition: linear_solver.h:1405
operations_research::MPSolver::FEASIBLE
@ FEASIBLE
feasible, or stopped by limit.
Definition: linear_solver.h:431
operations_research::MPSolverInterface::~MPSolverInterface
virtual ~MPSolverInterface()
Definition: linear_solver.cc:1631
operations_research::MPSolverInterface::best_objective_bound_
double best_objective_bound_
Definition: linear_solver.h:1732
operations_research::MPVariable::CplexInterface
friend class CplexInterface
Definition: linear_solver.h:1134