OR-Tools  8.1
clp_interface.cc
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 
14 //
15 
16 #include <algorithm>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include "absl/memory/memory.h"
22 #include "absl/strings/match.h"
23 #include "absl/strings/str_format.h"
25 #include "ortools/base/hash.h"
27 #include "ortools/base/logging.h"
28 #include "ortools/base/timer.h"
30 
31 #if defined(USE_CLP) || defined(USE_CBC)
32 
33 #undef PACKAGE
34 #undef VERSION
35 #include "ClpConfig.h"
36 #include "ClpMessage.hpp"
37 #include "ClpSimplex.hpp"
38 #include "CoinBuild.hpp"
39 
40 namespace operations_research {
41 
43  public:
44  // Constructor that takes a name for the underlying CLP solver.
45  explicit CLPInterface(MPSolver* const solver);
46  ~CLPInterface() override;
47 
48  // Sets the optimization direction (min/max).
49  void SetOptimizationDirection(bool maximize) override;
50 
51  // ----- Solve -----
52  // Solve the problem using the parameter values specified.
53  MPSolver::ResultStatus Solve(const MPSolverParameters& param) override;
54 
55  // ----- Model modifications and extraction -----
56  // Resets extracted model
57  void Reset() override;
58 
59  // Modify bounds.
60  void SetVariableBounds(int var_index, double lb, double ub) override;
61  void SetVariableInteger(int var_index, bool integer) override;
62  void SetConstraintBounds(int row_index, double lb, double ub) override;
63 
64  // Add constraint incrementally.
65  void AddRowConstraint(MPConstraint* const ct) override;
66  // Add variable incrementally.
67  void AddVariable(MPVariable* const var) override;
68  // Change a coefficient in a constraint.
69  void SetCoefficient(MPConstraint* const constraint,
70  const MPVariable* const variable, double new_value,
71  double old_value) override;
72  // Clear a constraint from all its terms.
73  void ClearConstraint(MPConstraint* const constraint) override;
74 
75  // Change a coefficient in the linear objective.
76  void SetObjectiveCoefficient(const MPVariable* const variable,
77  double coefficient) override;
78  // Change the constant term in the linear objective.
79  void SetObjectiveOffset(double offset) override;
80  // Clear the objective from all its terms.
81  void ClearObjective() override;
82 
83  // ------ Query statistics on the solution and the solve ------
84  // Number of simplex iterations
85  int64 iterations() const override;
86  // Number of branch-and-bound nodes. Only available for discrete problems.
87  int64 nodes() const override;
88 
89  // Returns the basis status of a row.
90  MPSolver::BasisStatus row_status(int constraint_index) const override;
91  // Returns the basis status of a column.
92  MPSolver::BasisStatus column_status(int variable_index) const override;
93 
94  // ----- Misc -----
95  // Query problem type.
96  bool IsContinuous() const override { return true; }
97  bool IsLP() const override { return true; }
98  bool IsMIP() const override { return false; }
99 
100  void ExtractNewVariables() override;
101  void ExtractNewConstraints() override;
102  void ExtractObjective() override;
103 
104  std::string SolverVersion() const override { return "Clp " CLP_VERSION; }
105 
106  void* underlying_solver() override {
107  return reinterpret_cast<void*>(clp_.get());
108  }
109 
110  private:
111  // Create dummy variable to be able to create empty constraints.
112  void CreateDummyVariableForEmptyConstraints();
113 
114  // Set all parameters in the underlying solver.
115  void SetParameters(const MPSolverParameters& param) override;
116  // Reset to their default value the parameters for which CLP has a
117  // stateful API. To be called after the solve so that the next solve
118  // starts from a clean parameter state.
119  void ResetParameters();
120  // Set each parameter in the underlying solver.
121  void SetRelativeMipGap(double value) override;
122  void SetPrimalTolerance(double value) override;
123  void SetDualTolerance(double value) override;
124  void SetPresolveMode(int value) override;
125  void SetScalingMode(int value) override;
126  void SetLpAlgorithm(int value) override;
127 
128  // Transforms basis status from CLP enum to MPSolver::BasisStatus.
129  MPSolver::BasisStatus TransformCLPBasisStatus(
130  ClpSimplex::Status clp_basis_status) const;
131 
132  std::unique_ptr<ClpSimplex> clp_; // TODO(user) : remove pointer.
133  std::unique_ptr<ClpSolve> options_; // For parameter setting.
134 };
135 
136 // ----- Solver -----
137 
138 // Creates a LP/MIP instance with the specified name and minimization objective.
140  : MPSolverInterface(solver), clp_(new ClpSimplex), options_(new ClpSolve) {
141  clp_->setStrParam(ClpProbName, solver_->name_);
142  clp_->setOptimizationDirection(1);
143 }
144 
146 
148  clp_ = absl::make_unique<ClpSimplex>();
149  clp_->setOptimizationDirection(maximize_ ? -1 : 1);
151 }
152 
153 // ------ Model modifications and extraction -----
154 
155 namespace {
156 // Variable indices are shifted by 1 internally because of the dummy "objective
157 // offset" variable (with internal index 0).
158 int MPSolverVarIndexToClpVarIndex(int var_index) { return var_index + 1; }
159 } // namespace
160 
161 // Not cached
164  clp_->setOptimizationDirection(maximize ? -1 : 1);
165 }
166 
167 void CLPInterface::SetVariableBounds(int var_index, double lb, double ub) {
169  if (variable_is_extracted(var_index)) {
170  // Not cached if the variable has been extracted
171  DCHECK_LT(var_index, last_variable_index_);
172  clp_->setColumnBounds(MPSolverVarIndexToClpVarIndex(var_index), lb, ub);
173  } else {
175  }
176 }
177 
178 // Ignore as CLP does not solve models with integer variables
179 void CLPInterface::SetVariableInteger(int var_index, bool integer) {}
180 
181 void CLPInterface::SetConstraintBounds(int index, double lb, double ub) {
184  // Not cached if the row has been extracted
186  clp_->setRowBounds(index, lb, ub);
187  } else {
189  }
190 }
191 
193  const MPVariable* const variable,
194  double new_value, double old_value) {
196  if (constraint_is_extracted(constraint->index()) &&
197  variable_is_extracted(variable->index())) {
198  // The modification of the coefficient for an extracted row and
199  // variable is not cached.
200  DCHECK_LE(constraint->index(), last_constraint_index_);
201  DCHECK_LE(variable->index(), last_variable_index_);
202  clp_->modifyCoefficient(constraint->index(),
203  MPSolverVarIndexToClpVarIndex(variable->index()),
204  new_value);
205  } else {
206  // The modification of an unextracted row or variable is cached
207  // and handled in ExtractModel.
209  }
210 }
211 
212 // Not cached
215  // Constraint may not have been extracted yet.
216  if (!constraint_is_extracted(constraint->index())) return;
217  for (const auto& entry : constraint->coefficients_) {
218  DCHECK(variable_is_extracted(entry.first->index()));
219  clp_->modifyCoefficient(constraint->index(),
220  MPSolverVarIndexToClpVarIndex(entry.first->index()),
221  0.0);
222  }
223 }
224 
225 // Cached
227  double coefficient) {
229  if (variable_is_extracted(variable->index())) {
230  clp_->setObjectiveCoefficient(
231  MPSolverVarIndexToClpVarIndex(variable->index()), coefficient);
232  } else {
234  }
235 }
236 
237 // Cached
238 void CLPInterface::SetObjectiveOffset(double offset) {
239  // Constant term. Use -offset instead of +offset because CLP does
240  // not follow conventions.
242  clp_->setObjectiveOffset(-offset);
243 }
244 
245 // Clear objective of all its terms.
248  // Clear linear terms
249  for (const auto& entry : solver_->objective_->coefficients_) {
250  const int mpsolver_var_index = entry.first->index();
251  // Variable may have not been extracted yet.
252  if (!variable_is_extracted(mpsolver_var_index)) {
254  } else {
255  clp_->setObjectiveCoefficient(
256  MPSolverVarIndexToClpVarIndex(mpsolver_var_index), 0.0);
257  }
258  }
259  // Clear constant term.
260  clp_->setObjectiveOffset(0.0);
261 }
262 
265 }
266 
269 }
270 
271 void CLPInterface::CreateDummyVariableForEmptyConstraints() {
272  clp_->setColumnBounds(kDummyVariableIndex, 0.0, 0.0);
273  clp_->setObjectiveCoefficient(kDummyVariableIndex, 0.0);
274  // Workaround for peculiar signature of setColumnName. Note that we do need
275  // std::string here, and not 'string', which aren't the same as of 2013-12
276  // (this will change later).
277  std::string dummy = "dummy"; // We do need to create this temporary variable.
278  clp_->setColumnName(kDummyVariableIndex, dummy);
279 }
280 
281 // Define new variables and add them to existing constraints.
283  // Define new variables
284  int total_num_vars = solver_->variables_.size();
285  if (total_num_vars > last_variable_index_) {
286  if (last_variable_index_ == 0 && last_constraint_index_ == 0) {
287  // Faster extraction when nothing has been extracted yet.
288  clp_->resize(0, total_num_vars + 1);
289  CreateDummyVariableForEmptyConstraints();
290  for (int i = 0; i < total_num_vars; ++i) {
291  MPVariable* const var = solver_->variables_[i];
292  set_variable_as_extracted(i, true);
293  if (!var->name().empty()) {
294  std::string name = var->name();
295  clp_->setColumnName(MPSolverVarIndexToClpVarIndex(i), name);
296  }
297  clp_->setColumnBounds(MPSolverVarIndexToClpVarIndex(i), var->lb(),
298  var->ub());
299  }
300  } else {
301  // TODO(user): This could perhaps be made slightly faster by
302  // iterating through old constraints, constructing by hand the
303  // column-major representation of the addition to them and call
304  // clp_->addColumns. But this is good enough for now.
305  // Create new variables.
306  for (int j = last_variable_index_; j < total_num_vars; ++j) {
307  MPVariable* const var = solver_->variables_[j];
309  set_variable_as_extracted(j, true);
310  // The true objective coefficient will be set later in ExtractObjective.
311  double tmp_obj_coef = 0.0;
312  clp_->addColumn(0, nullptr, nullptr, var->lb(), var->ub(),
313  tmp_obj_coef);
314  if (!var->name().empty()) {
315  std::string name = var->name();
316  clp_->setColumnName(MPSolverVarIndexToClpVarIndex(j), name);
317  }
318  }
319  // Add new variables to existing constraints.
320  for (int i = 0; i < last_constraint_index_; i++) {
321  MPConstraint* const ct = solver_->constraints_[i];
322  const int ct_index = ct->index();
323  for (const auto& entry : ct->coefficients_) {
324  const int mpsolver_var_index = entry.first->index();
325  DCHECK(variable_is_extracted(mpsolver_var_index));
326  if (mpsolver_var_index >= last_variable_index_) {
327  clp_->modifyCoefficient(
328  ct_index, MPSolverVarIndexToClpVarIndex(mpsolver_var_index),
329  entry.second);
330  }
331  }
332  }
333  }
334  }
335 }
336 
337 // Define new constraints on old and new variables.
339  int total_num_rows = solver_->constraints_.size();
340  if (last_constraint_index_ < total_num_rows) {
341  // Find the length of the longest row.
342  int max_row_length = 0;
343  for (int i = last_constraint_index_; i < total_num_rows; ++i) {
344  MPConstraint* const ct = solver_->constraints_[i];
345  DCHECK(!constraint_is_extracted(ct->index()));
346  set_constraint_as_extracted(ct->index(), true);
347  if (ct->coefficients_.size() > max_row_length) {
348  max_row_length = ct->coefficients_.size();
349  }
350  }
351  // Make space for dummy variable.
352  max_row_length = std::max(1, max_row_length);
353  std::unique_ptr<int[]> indices(new int[max_row_length]);
354  std::unique_ptr<double[]> coefs(new double[max_row_length]);
355  CoinBuild build_object;
356  // Add each new constraint.
357  for (int i = last_constraint_index_; i < total_num_rows; ++i) {
358  MPConstraint* const ct = solver_->constraints_[i];
359  DCHECK(constraint_is_extracted(ct->index()));
360  int size = ct->coefficients_.size();
361  if (size == 0) {
362  // Add dummy variable to be able to build the constraint.
363  indices[0] = kDummyVariableIndex;
364  coefs[0] = 1.0;
365  size = 1;
366  }
367  int j = 0;
368  for (const auto& entry : ct->coefficients_) {
369  const int mpsolver_var_index = entry.first->index();
370  DCHECK(variable_is_extracted(mpsolver_var_index));
371  indices[j] = MPSolverVarIndexToClpVarIndex(mpsolver_var_index);
372  coefs[j] = entry.second;
373  j++;
374  }
375  build_object.addRow(size, indices.get(), coefs.get(), ct->lb(), ct->ub());
376  }
377  // Add and name the rows.
378  clp_->addRows(build_object);
379  for (int i = last_constraint_index_; i < total_num_rows; ++i) {
380  MPConstraint* const ct = solver_->constraints_[i];
381  if (!ct->name().empty()) {
382  std::string name = ct->name();
383  clp_->setRowName(ct->index(), name);
384  }
385  }
386  }
387 }
388 
390  // Linear objective: set objective coefficients for all variables
391  // (some might have been modified)
392  for (const auto& entry : solver_->objective_->coefficients_) {
393  clp_->setObjectiveCoefficient(
394  MPSolverVarIndexToClpVarIndex(entry.first->index()), entry.second);
395  }
396 
397  // Constant term. Use -offset instead of +offset because CLP does
398  // not follow conventions.
399  clp_->setObjectiveOffset(-solver_->Objective().offset());
400 }
401 
402 // Extracts model and solve the LP/MIP. Returns the status of the search.
404  try {
405  WallTimer timer;
406  timer.Start();
407 
410  Reset();
411  }
412 
413  // Set log level.
414  CoinMessageHandler message_handler;
415  clp_->passInMessageHandler(&message_handler);
416  if (quiet_) {
417  message_handler.setLogLevel(1, 0);
418  clp_->setLogLevel(0);
419  } else {
420  message_handler.setLogLevel(1, 1);
421  clp_->setLogLevel(1);
422  }
423 
424  // Special case if the model is empty since CLP is not able to
425  // handle this special case by itself.
426  if (solver_->variables_.empty() && solver_->constraints_.empty()) {
430  return result_status_;
431  }
432 
433  ExtractModel();
434  VLOG(1) << absl::StrFormat("Model built in %.3f seconds.", timer.Get());
435 
436  // Time limit.
437  if (solver_->time_limit() != 0) {
438  VLOG(1) << "Setting time limit = " << solver_->time_limit() << " ms.";
439  clp_->setMaximumSeconds(solver_->time_limit_in_secs());
440  } else {
441  clp_->setMaximumSeconds(-1.0);
442  }
443 
444  // Start from a fresh set of default parameters and set them to
445  // specified values.
446  options_ = absl::make_unique<ClpSolve>();
447  SetParameters(param);
448 
449  // Solve
450  timer.Restart();
451  clp_->initialSolve(*options_);
452  VLOG(1) << absl::StrFormat("Solved in %.3f seconds.", timer.Get());
453 
454  // Check the status: optimal, infeasible, etc.
455  int tmp_status = clp_->status();
456  VLOG(1) << "clp result status: " << tmp_status;
457  switch (tmp_status) {
458  case CLP_SIMPLEX_FINISHED:
460  break;
461  case CLP_SIMPLEX_INFEASIBLE:
463  break;
464  case CLP_SIMPLEX_UNBOUNDED:
466  break;
467  case CLP_SIMPLEX_STOPPED:
469  break;
470  default:
472  break;
473  }
474 
477  // Get the results
478  objective_value_ = clp_->objectiveValue();
479  VLOG(1) << "objective=" << objective_value_;
480  const double* const values = clp_->getColSolution();
481  const double* const reduced_costs = clp_->getReducedCost();
482  for (int i = 0; i < solver_->variables_.size(); ++i) {
483  MPVariable* const var = solver_->variables_[i];
484  const int clp_var_index = MPSolverVarIndexToClpVarIndex(var->index());
485  const double val = values[clp_var_index];
486  var->set_solution_value(val);
487  VLOG(3) << var->name() << ": value = " << val;
488  double reduced_cost = reduced_costs[clp_var_index];
489  var->set_reduced_cost(reduced_cost);
490  VLOG(4) << var->name() << ": reduced cost = " << reduced_cost;
491  }
492  const double* const dual_values = clp_->getRowPrice();
493  for (int i = 0; i < solver_->constraints_.size(); ++i) {
494  MPConstraint* const ct = solver_->constraints_[i];
495  const int constraint_index = ct->index();
496  const double dual_value = dual_values[constraint_index];
497  ct->set_dual_value(dual_value);
498  VLOG(4) << "row " << ct->index() << " dual value = " << dual_value;
499  }
500  }
501 
502  ResetParameters();
504  return result_status_;
505  } catch (CoinError& e) {
506  LOG(WARNING) << "Caught exception in Coin LP: " << e.message();
508  return result_status_;
509  }
510 }
511 
512 MPSolver::BasisStatus CLPInterface::TransformCLPBasisStatus(
513  ClpSimplex::Status clp_basis_status) const {
514  switch (clp_basis_status) {
515  case ClpSimplex::isFree:
516  return MPSolver::FREE;
517  case ClpSimplex::basic:
518  return MPSolver::BASIC;
519  case ClpSimplex::atUpperBound:
521  case ClpSimplex::atLowerBound:
523  case ClpSimplex::superBasic:
524  return MPSolver::FREE;
525  case ClpSimplex::isFixed:
526  return MPSolver::FIXED_VALUE;
527  default:
528  LOG(FATAL) << "Unknown CLP basis status";
529  return MPSolver::FREE;
530  }
531 }
532 
533 // ------ Query statistics on the solution and the solve ------
534 
537  return clp_->getIterationCount();
538 }
539 
541  LOG(DFATAL) << "Number of nodes only available for discrete problems";
542  return kUnknownNumberOfNodes;
543 }
544 
545 MPSolver::BasisStatus CLPInterface::row_status(int constraint_index) const {
546  DCHECK_LE(0, constraint_index);
547  DCHECK_GT(last_constraint_index_, constraint_index);
548  const ClpSimplex::Status clp_basis_status =
549  clp_->getRowStatus(constraint_index);
550  return TransformCLPBasisStatus(clp_basis_status);
551 }
552 
554  DCHECK_LE(0, variable_index);
555  DCHECK_GT(last_variable_index_, variable_index);
556  const ClpSimplex::Status clp_basis_status =
557  clp_->getColumnStatus(MPSolverVarIndexToClpVarIndex(variable_index));
558  return TransformCLPBasisStatus(clp_basis_status);
559 }
560 
561 // ------ Parameters ------
562 
563 void CLPInterface::SetParameters(const MPSolverParameters& param) {
564  SetCommonParameters(param);
565 }
566 
567 void CLPInterface::ResetParameters() {
568  clp_->setPrimalTolerance(MPSolverParameters::kDefaultPrimalTolerance);
569  clp_->setDualTolerance(MPSolverParameters::kDefaultDualTolerance);
570 }
571 
572 void CLPInterface::SetRelativeMipGap(double value) {
573  LOG(WARNING) << "The relative MIP gap is only available "
574  << "for discrete problems.";
575 }
576 
577 void CLPInterface::SetPrimalTolerance(double value) {
578  clp_->setPrimalTolerance(value);
579 }
580 
581 void CLPInterface::SetDualTolerance(double value) {
582  clp_->setDualTolerance(value);
583 }
584 
585 void CLPInterface::SetPresolveMode(int value) {
586  switch (value) {
588  options_->setPresolveType(ClpSolve::presolveOff);
589  break;
590  }
592  options_->setPresolveType(ClpSolve::presolveOn);
593  break;
594  }
595  default: {
597  }
598  }
599 }
600 
601 void CLPInterface::SetScalingMode(int value) {
603 }
604 
605 void CLPInterface::SetLpAlgorithm(int value) {
606  switch (value) {
608  options_->setSolveType(ClpSolve::useDual);
609  break;
610  }
612  options_->setSolveType(ClpSolve::usePrimal);
613  break;
614  }
616  options_->setSolveType(ClpSolve::useBarrier);
617  break;
618  }
619  default: {
621  value);
622  }
623  }
624 }
625 
627  return new CLPInterface(solver);
628 }
629 
630 } // namespace operations_research
631 #endif // #if defined(USE_CBC) || defined(USE_CLP)
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::CLPInterface::~CLPInterface
~CLPInterface() override
Definition: clp_interface.cc:145
operations_research::CLPInterface::ExtractObjective
void ExtractObjective() override
Definition: clp_interface.cc:389
integral_types.h
DCHECK_LT
#define DCHECK_LT(val1, val2)
Definition: base/logging.h:888
VLOG
#define VLOG(verboselevel)
Definition: base/logging.h:978
max
int64 max
Definition: alldiff_cst.cc:139
operations_research::CLPInterface::SolverVersion
std::string SolverVersion() const override
Definition: clp_interface.cc:104
operations_research::CLPInterface::AddRowConstraint
void AddRowConstraint(MPConstraint *const ct) override
Definition: clp_interface.cc:263
LOG
#define LOG(severity)
Definition: base/logging.h:420
WallTimer::Get
double Get() const
Definition: timer.h:45
operations_research::MPSolver::OPTIMAL
@ OPTIMAL
optimal.
Definition: linear_solver.h:429
operations_research::CLPInterface::SetConstraintBounds
void SetConstraintBounds(int row_index, double lb, double ub) override
Definition: clp_interface.cc:181
operations_research::MPSolverParameters::LP_ALGORITHM
@ LP_ALGORITHM
Algorithm to solve linear programs.
Definition: linear_solver.h:1383
operations_research::CLPInterface::iterations
int64 iterations() const override
Definition: clp_interface.cc:535
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::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::CLPInterface::column_status
MPSolver::BasisStatus column_status(int variable_index) const override
Definition: clp_interface.cc:553
logging.h
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::CLPInterface::AddVariable
void AddVariable(MPVariable *const var) override
Definition: clp_interface.cc:267
DCHECK_GT
#define DCHECK_GT(val1, val2)
Definition: base/logging.h:890
value
int64 value
Definition: demon_profiler.cc:43
operations_research::CLPInterface::SetObjectiveOffset
void SetObjectiveOffset(double offset) override
Definition: clp_interface.cc:238
operations_research::MPSolverInterface::MODEL_SYNCHRONIZED
@ MODEL_SYNCHRONIZED
Definition: linear_solver.h:1525
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
WARNING
const int WARNING
Definition: log_severity.h:31
operations_research::MPSolverInterface::InvalidateSolutionSynchronization
void InvalidateSolutionSynchronization()
Definition: linear_solver.cc:1718
operations_research::MPSolverInterface
Definition: linear_solver.h:1516
operations_research::CLPInterface::IsLP
bool IsLP() const override
Definition: clp_interface.cc:97
operations_research::MPSolver::ABNORMAL
@ ABNORMAL
abnormal, i.e., error of some kind.
Definition: linear_solver.h:437
WallTimer::Restart
void Restart()
Definition: timer.h:35
int64
int64_t int64
Definition: integral_types.h:34
operations_research::MPConstraint::index
int index() const
Returns the index of the constraint in the MPSolver::constraints_.
Definition: linear_solver.h:1245
operations_research::CLPInterface::ClearConstraint
void ClearConstraint(MPConstraint *const constraint) override
Definition: clp_interface.cc:213
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
operations_research::MPConstraint
The class for constraints of a Mathematical Programming (MP) model.
Definition: linear_solver.h:1177
operations_research::CLPInterface::ExtractNewVariables
void ExtractNewVariables() override
Definition: clp_interface.cc:282
operations_research::MPSolverInterface::constraint_is_extracted
bool constraint_is_extracted(int ct_index) const
Definition: linear_solver.h:1660
operations_research::CLPInterface::IsMIP
bool IsMIP() const override
Definition: clp_interface.cc:98
operations_research::MPSolverParameters::PRESOLVE_ON
@ PRESOLVE_ON
Presolve is on.
Definition: linear_solver.h:1395
DCHECK_NE
#define DCHECK_NE(val1, val2)
Definition: base/logging.h:886
operations_research::MPSolverInterface::objective_value_
double objective_value_
Definition: linear_solver.h:1729
operations_research::MPSolverParameters::GetIntegerParam
int GetIntegerParam(MPSolverParameters::IntegerParam param) const
Returns the value of an integer parameter.
Definition: linear_solver.cc:1999
WallTimer::Start
void Start()
Definition: timer.h:31
operations_research::MPSolverInterface::ResetExtractionInformation
void ResetExtractionInformation()
Definition: linear_solver.cc:1665
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::MPSolverInterface::solver_
MPSolver *const solver_
Definition: linear_solver.h:1714
operations_research::CLPInterface::SetVariableBounds
void SetVariableBounds(int var_index, double lb, double ub) override
Definition: clp_interface.cc:167
operations_research::MPSolverInterface::kUnknownNumberOfNodes
static constexpr int64 kUnknownNumberOfNodes
Definition: linear_solver.h:1536
timer.h
operations_research::MPSolverParameters::PRESOLVE
@ PRESOLVE
Advanced usage: presolve mode.
Definition: linear_solver.h:1381
operations_research::MPSolver::FREE
@ FREE
Definition: linear_solver.h:643
operations_research::CLPInterface::underlying_solver
void * underlying_solver() override
Definition: clp_interface.cc:106
operations_research::MPSolverInterface::SOLUTION_SYNCHRONIZED
@ SOLUTION_SYNCHRONIZED
Definition: linear_solver.h:1528
operations_research::CLPInterface::row_status
MPSolver::BasisStatus row_status(int constraint_index) const override
Definition: clp_interface.cc:545
operations_research::CLPInterface::Solve
MPSolver::ResultStatus Solve(const MPSolverParameters &param) override
Definition: clp_interface.cc:403
operations_research::MPSolverInterface::SetIntegerParamToUnsupportedValue
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
Definition: linear_solver.cc:1774
operations_research::MPSolver::time_limit
int64 time_limit() const
Definition: linear_solver.h:779
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::MPSolverParameters::kDefaultPrimalTolerance
static const double kDefaultPrimalTolerance
Definition: linear_solver.h:1443
operations_research::BuildCLPInterface
MPSolverInterface * BuildCLPInterface(MPSolver *const solver)
Definition: clp_interface.cc:626
ct
const Constraint * ct
Definition: demon_profiler.cc:42
operations_research::CLPInterface
Definition: clp_interface.cc:42
WallTimer
Definition: timer.h:23
operations_research::CLPInterface::IsContinuous
bool IsContinuous() const override
Definition: clp_interface.cc:96
operations_research::MPSolverInterface::SetUnsupportedIntegerParam
virtual void SetUnsupportedIntegerParam(MPSolverParameters::IntegerParam param)
Definition: linear_solver.cc:1765
operations_research::CLPInterface::CLPInterface
CLPInterface(MPSolver *const solver)
Definition: clp_interface.cc:139
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::MPSolverInterface::sync_status_
SynchronizationStatus sync_status_
Definition: linear_solver.h:1716
DCHECK
#define DCHECK(condition)
Definition: base/logging.h:884
operations_research::MPSolver::time_limit_in_secs
double time_limit_in_secs() const
Definition: linear_solver.h:789
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::CLPInterface::SetCoefficient
void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value) override
Definition: clp_interface.cc:192
operations_research::MPSolverInterface::ExtractModel
void ExtractModel()
Definition: linear_solver.cc:1637
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::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
coefficient
int64 coefficient
Definition: routing_search.cc:972
operations_research::CLPInterface::Reset
void Reset() override
Definition: clp_interface.cc:147
operations_research::MPSolverInterface::last_variable_index_
int last_variable_index_
Definition: linear_solver.h:1726
operations_research::CLPInterface::SetOptimizationDirection
void SetOptimizationDirection(bool maximize) override
Definition: clp_interface.cc:162
operations_research::CLPInterface::nodes
int64 nodes() const override
Definition: clp_interface.cc:540
operations_research::MPSolverParameters::INCREMENTALITY
@ INCREMENTALITY
Advanced usage: incrementality from one solve to the next.
Definition: linear_solver.h:1385
operations_research::MPVariable
The class for variables of a Mathematical Programming (MP) model.
Definition: linear_solver.h:1052
hash.h
linear_solver.h
A C++ wrapper that provides a simple and unified interface to several linear programming and mixed in...
operations_research::MPSolverInterface::SetCommonParameters
void SetCommonParameters(const MPSolverParameters &param)
Definition: linear_solver.cc:1733
operations_research::CLPInterface::ExtractNewConstraints
void ExtractNewConstraints() override
Definition: clp_interface.cc:338
operations_research::MPSolver::INFEASIBLE
@ INFEASIBLE
proven infeasible.
Definition: linear_solver.h:433
operations_research::MPSolverParameters::PRIMAL
@ PRIMAL
Primal simplex.
Definition: linear_solver.h:1403
operations_research::MPSolverParameters::PRESOLVE_OFF
@ PRESOLVE_OFF
Presolve is off.
Definition: linear_solver.h:1393
DCHECK_LE
#define DCHECK_LE(val1, val2)
Definition: base/logging.h:887
operations_research::CLPInterface::SetVariableInteger
void SetVariableInteger(int var_index, bool integer) override
Definition: clp_interface.cc:179
operations_research::MPSolverInterface::MUST_RELOAD
@ MUST_RELOAD
Definition: linear_solver.h:1521
operations_research::MPSolverInterface::kDummyVariableIndex
static const int kDummyVariableIndex
Definition: linear_solver.h:1739
operations_research::CLPInterface::ClearObjective
void ClearObjective() override
Definition: clp_interface.cc:246
operations_research::MPSolverInterface::CheckSolutionIsSynchronized
bool CheckSolutionIsSynchronized() const
Definition: linear_solver.cc:1673
operations_research::MPSolver::AT_LOWER_BOUND
@ AT_LOWER_BOUND
Definition: linear_solver.h:644
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
name
const std::string name
Definition: default_search.cc:808
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::CLPInterface::SetObjectiveCoefficient
void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient) override
Definition: clp_interface.cc:226