OR-Tools  9.2
lp_solver.cc
Go to the documentation of this file.
1// Copyright 2010-2021 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
15
16#include <cmath>
17#include <stack>
18#include <vector>
19
20#include "absl/memory/memory.h"
21#include "absl/strings/match.h"
22#include "absl/strings/str_format.h"
25#include "ortools/base/timer.h"
27#include "ortools/glop/status.h"
32
33// TODO(user): abstract this in some way to the port directory.
34#ifndef __PORTABLE_PLATFORM__
36#endif
37
38ABSL_FLAG(bool, lp_dump_to_proto_file, false,
39 "Tells whether do dump the problem to a protobuf file.");
40ABSL_FLAG(bool, lp_dump_compressed_file, true,
41 "Whether the proto dump file is compressed.");
42ABSL_FLAG(bool, lp_dump_binary_file, false,
43 "Whether the proto dump file is binary.");
44ABSL_FLAG(int, lp_dump_file_number, -1,
45 "Number for the dump file, in the form name-000048.pb. "
46 "If < 0, the file is automatically numbered from the number of "
47 "calls to LPSolver::Solve().");
48ABSL_FLAG(std::string, lp_dump_dir, "/tmp",
49 "Directory where dump files are written.");
50ABSL_FLAG(std::string, lp_dump_file_basename, "",
51 "Base name for dump files. LinearProgram::name_ is used if "
52 "lp_dump_file_basename is empty. If LinearProgram::name_ is "
53 "empty, \"linear_program_dump_file\" is used.");
54ABSL_FLAG(std::string, glop_params, "",
55 "Override any user parameters with the value of this flag. This is "
56 "interpreted as a GlopParameters proto in text format.");
57
58namespace operations_research {
59namespace glop {
60namespace {
61
62// Writes a LinearProgram to a file if FLAGS_lp_dump_to_proto_file is true. The
63// integer num is appended to the base name of the file. When this function is
64// called from LPSolver::Solve(), num is usually the number of times Solve() was
65// called. For a LinearProgram whose name is "LinPro", and num = 48, the default
66// output file will be /tmp/LinPro-000048.pb.gz.
67//
68// Warning: is a no-op on portable platforms (android, ios, etc).
69void DumpLinearProgramIfRequiredByFlags(const LinearProgram& linear_program,
70 int num) {
71 if (!absl::GetFlag(FLAGS_lp_dump_to_proto_file)) return;
72#ifdef __PORTABLE_PLATFORM__
73 LOG(WARNING) << "DumpLinearProgramIfRequiredByFlags(linear_program, num) "
74 "requested for linear_program.name()='"
75 << linear_program.name() << "', num=" << num
76 << " but is not implemented for this platform.";
77#else
78 std::string filename = absl::GetFlag(FLAGS_lp_dump_file_basename);
79 if (filename.empty()) {
80 if (linear_program.name().empty()) {
81 filename = "linear_program_dump";
82 } else {
83 filename = linear_program.name();
84 }
85 }
86 const int file_num = absl::GetFlag(FLAGS_lp_dump_file_number) >= 0
87 ? absl::GetFlag(FLAGS_lp_dump_file_number)
88 : num;
89 absl::StrAppendFormat(&filename, "-%06d.pb", file_num);
90 const std::string filespec =
91 absl::StrCat(absl::GetFlag(FLAGS_lp_dump_dir), "/", filename);
92 MPModelProto proto;
93 LinearProgramToMPModelProto(linear_program, &proto);
94 const ProtoWriteFormat write_format = absl::GetFlag(FLAGS_lp_dump_binary_file)
97 if (!WriteProtoToFile(filespec, proto, write_format,
98 absl::GetFlag(FLAGS_lp_dump_compressed_file))) {
99 LOG(DFATAL) << "Could not write " << filespec;
100 }
101#endif
102}
103
104} // anonymous namespace
105
106// --------------------------------------------------------
107// LPSolver
108// --------------------------------------------------------
109
110LPSolver::LPSolver() : num_solves_(0) {}
111
113 parameters_ = parameters;
114#ifndef __PORTABLE_PLATFORM__
115 if (!absl::GetFlag(FLAGS_glop_params).empty()) {
116 GlopParameters flag_params;
117 CHECK(google::protobuf::TextFormat::ParseFromString(
118 absl::GetFlag(FLAGS_glop_params), &flag_params));
119 parameters_.MergeFrom(flag_params);
120 }
121#endif
122}
123
124const GlopParameters& LPSolver::GetParameters() const { return parameters_; }
125
127
129
131 std::unique_ptr<TimeLimit> time_limit =
132 TimeLimit::FromParameters(parameters_);
133 return SolveWithTimeLimit(lp, time_limit.get());
134}
135
138 if (time_limit == nullptr) {
139 LOG(DFATAL) << "SolveWithTimeLimit() called with a nullptr time_limit.";
141 }
142 ++num_solves_;
143 num_revised_simplex_iterations_ = 0;
144 DumpLinearProgramIfRequiredByFlags(lp, num_solves_);
145
146 // Display a warning if running in non-opt, unless we're inside a unit test.
148 << "\n******************************************************************"
149 "\n* WARNING: Glop will be very slow because it will use DCHECKs *"
150 "\n* to verify the results and the precision of the solver. *"
151 "\n* You can gain at least an order of magnitude speedup by *"
152 "\n* compiling with optimizations enabled and by defining NDEBUG. *"
153 "\n******************************************************************";
154
155 // Setup the logger.
156 logger_.EnableLogging(parameters_.log_search_progress());
157 logger_.SetLogToStdOut(parameters_.log_to_stdout());
158 if (!parameters_.log_search_progress() && VLOG_IS_ON(1)) {
159 logger_.EnableLogging(true);
160 logger_.SetLogToStdOut(false);
161 }
162
163 // Log some initial info about the input model.
164 if (logger_.LoggingIsEnabled()) {
165 SOLVER_LOG(&logger_, "");
166 SOLVER_LOG(&logger_, "Initial problem: ", lp.GetDimensionString());
167 SOLVER_LOG(&logger_, "Objective stats: ", lp.GetObjectiveStatsString());
168 SOLVER_LOG(&logger_, "Bounds stats: ", lp.GetBoundsStatsString());
169 }
170
171 // Check some preconditions.
172 if (!lp.IsCleanedUp()) {
173 LOG(DFATAL) << "The columns of the given linear program should be ordered "
174 << "by row and contain no zero coefficients. Call CleanUp() "
175 << "on it before calling Solve().";
176 ResizeSolution(lp.num_constraints(), lp.num_variables());
178 }
179 if (!lp.IsValid()) {
180 SOLVER_LOG(&logger_,
181 "The given linear program is invalid. It contains NaNs, "
182 "infinite coefficients or invalid bounds specification. "
183 "You can construct it in debug mode to get the exact cause.");
184 ResizeSolution(lp.num_constraints(), lp.num_variables());
186 }
187
188 // Make an internal copy of the problem for the preprocessing.
189 current_linear_program_.PopulateFromLinearProgram(lp);
190
191 // Preprocess.
192 MainLpPreprocessor preprocessor(&parameters_);
193 preprocessor.SetLogger(&logger_);
194 preprocessor.SetTimeLimit(time_limit);
195
196 const bool postsolve_is_needed = preprocessor.Run(&current_linear_program_);
197
198 if (logger_.LoggingIsEnabled()) {
199 SOLVER_LOG(&logger_, "");
200 SOLVER_LOG(&logger_, "Presolved problem: ",
201 current_linear_program_.GetDimensionString());
202 SOLVER_LOG(&logger_, "Objective stats: ",
203 current_linear_program_.GetObjectiveStatsString());
204 SOLVER_LOG(&logger_, "Bounds stats: ",
205 current_linear_program_.GetBoundsStatsString());
206 }
207
208 // At this point, we need to initialize a ProblemSolution with the correct
209 // size and status.
210 ProblemSolution solution(current_linear_program_.num_constraints(),
211 current_linear_program_.num_variables());
212 solution.status = preprocessor.status();
213
214 // Do not launch the solver if the time limit was already reached. This might
215 // mean that the pre-processors were not all run, and current_linear_program_
216 // might not be in a completely safe state.
217 if (!time_limit->LimitReached()) {
218 RunRevisedSimplexIfNeeded(&solution, time_limit);
219 }
220 if (postsolve_is_needed) preprocessor.DestructiveRecoverSolution(&solution);
221 const ProblemStatus status = LoadAndVerifySolution(lp, solution);
222 // LOG some statistics that can be parsed by our benchmark script.
223 if (logger_.LoggingIsEnabled()) {
224 SOLVER_LOG(&logger_, "status: ", GetProblemStatusString(status));
225 SOLVER_LOG(&logger_, "objective: ", GetObjectiveValue());
226 SOLVER_LOG(&logger_, "iterations: ", GetNumberOfSimplexIterations());
227 SOLVER_LOG(&logger_, "time: ", time_limit->GetElapsedTime());
228 SOLVER_LOG(&logger_, "deterministic_time: ",
229 time_limit->GetElapsedDeterministicTime());
230 SOLVER_LOG(&logger_, "");
231 }
232
233 return status;
234}
235
237 ResizeSolution(RowIndex(0), ColIndex(0));
238 revised_simplex_.reset(nullptr);
239}
240
242 const VariableStatusRow& variable_statuses,
243 const ConstraintStatusColumn& constraint_statuses) {
244 // Create the associated basis state.
245 BasisState state;
248 // Note the change of upper/lower bound between the status of a constraint
249 // and the status of its associated slack variable.
250 switch (status) {
253 break;
256 break;
259 break;
262 break;
265 break;
266 }
267 }
268 if (revised_simplex_ == nullptr) {
269 revised_simplex_ = absl::make_unique<RevisedSimplex>();
270 revised_simplex_->SetLogger(&logger_);
271 }
272 revised_simplex_->LoadStateForNextSolve(state);
273 if (parameters_.use_preprocessing()) {
274 LOG(WARNING) << "In GLOP, SetInitialBasis() was called but the parameter "
275 "use_preprocessing is true, this will likely not result in "
276 "what you want.";
277 }
278}
279
280namespace {
281// Computes the "real" problem objective from the one without offset nor
282// scaling.
283Fractional ProblemObjectiveValue(const LinearProgram& lp, Fractional value) {
284 return lp.objective_scaling_factor() * (value + lp.objective_offset());
285}
286
287// Returns the allowed error magnitude for something that should evaluate to
288// value under the given tolerance.
289Fractional AllowedError(Fractional tolerance, Fractional value) {
290 return tolerance * std::max(1.0, std::abs(value));
291}
292} // namespace
293
294// TODO(user): Try to also check the precision of an INFEASIBLE or UNBOUNDED
295// return status.
297 const ProblemSolution& solution) {
298 SOLVER_LOG(&logger_, "");
299 SOLVER_LOG(&logger_, "Final unscaled solution:");
300
301 if (!IsProblemSolutionConsistent(lp, solution)) {
302 SOLVER_LOG(&logger_, "Inconsistency detected in the solution.");
303 ResizeSolution(lp.num_constraints(), lp.num_variables());
305 }
306
307 // Load the solution.
308 primal_values_ = solution.primal_values;
309 dual_values_ = solution.dual_values;
310 variable_statuses_ = solution.variable_statuses;
311 constraint_statuses_ = solution.constraint_statuses;
312
313 ProblemStatus status = solution.status;
314
315 // Objective before eventually moving the primal/dual values inside their
316 // bounds.
317 ComputeReducedCosts(lp);
318 const Fractional primal_objective_value = ComputeObjective(lp);
319 const Fractional dual_objective_value = ComputeDualObjective(lp);
320 SOLVER_LOG(&logger_, "Primal objective (before moving primal/dual values) = ",
321 absl::StrFormat(
322 "%.15E", ProblemObjectiveValue(lp, primal_objective_value)));
323 SOLVER_LOG(&logger_, "Dual objective (before moving primal/dual values) = ",
324 absl::StrFormat("%.15E",
325 ProblemObjectiveValue(lp, dual_objective_value)));
326
327 // Eventually move the primal/dual values inside their bounds.
329 parameters_.provide_strong_optimal_guarantee()) {
330 MovePrimalValuesWithinBounds(lp);
331 MoveDualValuesWithinBounds(lp);
332 }
333
334 // The reported objective to the user.
335 problem_objective_value_ = ProblemObjectiveValue(lp, ComputeObjective(lp));
336 SOLVER_LOG(&logger_, "Primal objective (after moving primal/dual values) = ",
337 absl::StrFormat("%.15E", problem_objective_value_));
338
339 ComputeReducedCosts(lp);
340 ComputeConstraintActivities(lp);
341
342 // These will be set to true if the associated "infeasibility" is too large.
343 //
344 // The tolerance used is the parameter solution_feasibility_tolerance. To be
345 // somewhat independent of the original problem scaling, the thresholds used
346 // depend of the quantity involved and of its coordinates:
347 // - tolerance * max(1.0, abs(cost[col])) when a reduced cost is infeasible.
348 // - tolerance * max(1.0, abs(bound)) when a bound is crossed.
349 // - tolerance for an infeasible dual value (because the limit is always 0.0).
350 bool rhs_perturbation_is_too_large = false;
351 bool cost_perturbation_is_too_large = false;
352 bool primal_infeasibility_is_too_large = false;
353 bool dual_infeasibility_is_too_large = false;
354 bool primal_residual_is_too_large = false;
355 bool dual_residual_is_too_large = false;
356
357 // Computes all the infeasiblities and update the Booleans above.
358 ComputeMaxRhsPerturbationToEnforceOptimality(lp,
359 &rhs_perturbation_is_too_large);
360 ComputeMaxCostPerturbationToEnforceOptimality(
361 lp, &cost_perturbation_is_too_large);
362 const double primal_infeasibility =
363 ComputePrimalValueInfeasibility(lp, &primal_infeasibility_is_too_large);
364 const double dual_infeasibility =
365 ComputeDualValueInfeasibility(lp, &dual_infeasibility_is_too_large);
366 const double primal_residual =
367 ComputeActivityInfeasibility(lp, &primal_residual_is_too_large);
368 const double dual_residual =
369 ComputeReducedCostInfeasibility(lp, &dual_residual_is_too_large);
370
371 // TODO(user): the name is not really consistent since in practice those are
372 // the "residual" since the primal/dual infeasibility are zero when
373 // parameters_.provide_strong_optimal_guarantee() is true.
374 max_absolute_primal_infeasibility_ =
375 std::max(primal_infeasibility, primal_residual);
376 max_absolute_dual_infeasibility_ =
377 std::max(dual_infeasibility, dual_residual);
378 SOLVER_LOG(&logger_, "Max. primal infeasibility = ",
379 max_absolute_primal_infeasibility_);
380 SOLVER_LOG(&logger_,
381 "Max. dual infeasibility = ", max_absolute_dual_infeasibility_);
382
383 // Now that all the relevant quantities are computed, we check the precision
384 // and optimality of the result. See Chvatal pp. 61-62. If any of the tests
385 // fail, we return the IMPRECISE status.
386 const double objective_error_ub = ComputeMaxExpectedObjectiveError(lp);
387 SOLVER_LOG(&logger_, "Objective error <= ", objective_error_ub);
388
390 parameters_.provide_strong_optimal_guarantee()) {
391 // If the primal/dual values were moved to the bounds, then the primal/dual
392 // infeasibilities should be exactly zero (but not the residuals).
393 if (primal_infeasibility != 0.0 || dual_infeasibility != 0.0) {
394 LOG(ERROR) << "Primal/dual values have been moved to their bounds. "
395 << "Therefore the primal/dual infeasibilities should be "
396 << "exactly zero (but not the residuals). If this message "
397 << "appears, there is probably a bug in "
398 << "MovePrimalValuesWithinBounds() or in "
399 << "MoveDualValuesWithinBounds().";
400 }
401 if (rhs_perturbation_is_too_large) {
402 SOLVER_LOG(&logger_, "The needed rhs perturbation is too large !!");
403 if (parameters_.change_status_to_imprecise()) {
405 }
406 }
407 if (cost_perturbation_is_too_large) {
408 SOLVER_LOG(&logger_, "The needed cost perturbation is too large !!");
409 if (parameters_.change_status_to_imprecise()) {
411 }
412 }
413 }
414
415 // Note that we compare the values without offset nor scaling. We also need to
416 // compare them before we move the primal/dual values, otherwise we lose some
417 // precision since the values are modified independently of each other.
419 if (std::abs(primal_objective_value - dual_objective_value) >
420 objective_error_ub) {
421 SOLVER_LOG(&logger_,
422 "The objective gap of the final solution is too large.");
423 if (parameters_.change_status_to_imprecise()) {
425 }
426 }
427 }
430 (primal_residual_is_too_large || primal_infeasibility_is_too_large)) {
431 SOLVER_LOG(&logger_,
432 "The primal infeasibility of the final solution is too large.");
433 if (parameters_.change_status_to_imprecise()) {
435 }
436 }
439 (dual_residual_is_too_large || dual_infeasibility_is_too_large)) {
440 SOLVER_LOG(&logger_,
441 "The dual infeasibility of the final solution is too large.");
442 if (parameters_.change_status_to_imprecise()) {
444 }
445 }
446
447 may_have_multiple_solutions_ =
448 (status == ProblemStatus::OPTIMAL) ? IsOptimalSolutionOnFacet(lp) : false;
449 return status;
450}
451
452bool LPSolver::IsOptimalSolutionOnFacet(const LinearProgram& lp) {
453 // Note(user): We use the following same two tolerances for the dual and
454 // primal values.
455 // TODO(user): investigate whether to use the tolerances defined in
456 // parameters.proto.
457 const double kReducedCostTolerance = 1e-9;
458 const double kBoundTolerance = 1e-7;
459 const ColIndex num_cols = lp.num_variables();
460 for (ColIndex col(0); col < num_cols; ++col) {
461 if (variable_statuses_[col] == VariableStatus::FIXED_VALUE) continue;
464 const Fractional value = primal_values_[col];
465 if (AreWithinAbsoluteTolerance(reduced_costs_[col], 0.0,
466 kReducedCostTolerance) &&
467 (AreWithinAbsoluteTolerance(value, lower_bound, kBoundTolerance) ||
468 AreWithinAbsoluteTolerance(value, upper_bound, kBoundTolerance))) {
469 return true;
470 }
471 }
472 const RowIndex num_rows = lp.num_constraints();
473 for (RowIndex row(0); row < num_rows; ++row) {
474 if (constraint_statuses_[row] == ConstraintStatus::FIXED_VALUE) continue;
477 const Fractional activity = constraint_activities_[row];
478 if (AreWithinAbsoluteTolerance(dual_values_[row], 0.0,
479 kReducedCostTolerance) &&
480 (AreWithinAbsoluteTolerance(activity, lower_bound, kBoundTolerance) ||
481 AreWithinAbsoluteTolerance(activity, upper_bound, kBoundTolerance))) {
482 return true;
483 }
484 }
485 return false;
486}
487
489 return problem_objective_value_;
490}
491
493 return max_absolute_primal_infeasibility_;
494}
495
497 return max_absolute_dual_infeasibility_;
498}
499
501 return may_have_multiple_solutions_;
502}
503
505 return num_revised_simplex_iterations_;
506}
507
509 return revised_simplex_ == nullptr ? 0.0
510 : revised_simplex_->DeterministicTime();
511}
512
513void LPSolver::MovePrimalValuesWithinBounds(const LinearProgram& lp) {
514 const ColIndex num_cols = lp.num_variables();
515 DCHECK_EQ(num_cols, primal_values_.size());
516 Fractional error = 0.0;
517 for (ColIndex col(0); col < num_cols; ++col) {
521
522 error = std::max(error, primal_values_[col] - upper_bound);
523 error = std::max(error, lower_bound - primal_values_[col]);
524 primal_values_[col] = std::min(primal_values_[col], upper_bound);
525 primal_values_[col] = std::max(primal_values_[col], lower_bound);
526 }
527 SOLVER_LOG(&logger_, "Max. primal values move = ", error);
528}
529
530void LPSolver::MoveDualValuesWithinBounds(const LinearProgram& lp) {
531 const RowIndex num_rows = lp.num_constraints();
532 DCHECK_EQ(num_rows, dual_values_.size());
533 const Fractional optimization_sign = lp.IsMaximizationProblem() ? -1.0 : 1.0;
534 Fractional error = 0.0;
535 for (RowIndex row(0); row < num_rows; ++row) {
536 const Fractional lower_bound = lp.constraint_lower_bounds()[row];
537 const Fractional upper_bound = lp.constraint_upper_bounds()[row];
538
539 // For a minimization problem, we want a lower bound.
540 Fractional minimization_dual_value = optimization_sign * dual_values_[row];
541 if (lower_bound == -kInfinity && minimization_dual_value > 0.0) {
542 error = std::max(error, minimization_dual_value);
543 minimization_dual_value = 0.0;
544 }
545 if (upper_bound == kInfinity && minimization_dual_value < 0.0) {
546 error = std::max(error, -minimization_dual_value);
547 minimization_dual_value = 0.0;
548 }
549 dual_values_[row] = optimization_sign * minimization_dual_value;
550 }
551 SOLVER_LOG(&logger_, "Max. dual values move = ", error);
552}
553
554void LPSolver::ResizeSolution(RowIndex num_rows, ColIndex num_cols) {
555 primal_values_.resize(num_cols, 0.0);
556 reduced_costs_.resize(num_cols, 0.0);
557 variable_statuses_.resize(num_cols, VariableStatus::FREE);
558
559 dual_values_.resize(num_rows, 0.0);
560 constraint_activities_.resize(num_rows, 0.0);
561 constraint_statuses_.resize(num_rows, ConstraintStatus::FREE);
562}
563
564void LPSolver::RunRevisedSimplexIfNeeded(ProblemSolution* solution,
565 TimeLimit* time_limit) {
566 // Note that the transpose matrix is no longer needed at this point.
567 // This helps reduce the peak memory usage of the solver.
568 //
569 // TODO(user): actually, once the linear_program is loaded into the internal
570 // glop memory, there is no point keeping it around. Add a more complex
571 // Load/Solve API to RevisedSimplex so we can completely reclaim its memory
572 // right away.
573 current_linear_program_.ClearTransposeMatrix();
574 if (solution->status != ProblemStatus::INIT) return;
575 if (revised_simplex_ == nullptr) {
576 revised_simplex_ = absl::make_unique<RevisedSimplex>();
577 revised_simplex_->SetLogger(&logger_);
578 }
579 revised_simplex_->SetParameters(parameters_);
580 if (revised_simplex_->Solve(current_linear_program_, time_limit).ok()) {
581 num_revised_simplex_iterations_ = revised_simplex_->GetNumberOfIterations();
582 solution->status = revised_simplex_->GetProblemStatus();
583
584 // Make sure we do not copy the slacks added by revised_simplex_.
585 const ColIndex num_cols = solution->primal_values.size();
586 DCHECK_LE(num_cols, revised_simplex_->GetProblemNumCols());
587 for (ColIndex col(0); col < num_cols; ++col) {
588 solution->primal_values[col] = revised_simplex_->GetVariableValue(col);
589 solution->variable_statuses[col] =
590 revised_simplex_->GetVariableStatus(col);
591 }
592 const RowIndex num_rows = revised_simplex_->GetProblemNumRows();
593 DCHECK_EQ(solution->dual_values.size(), num_rows);
594 for (RowIndex row(0); row < num_rows; ++row) {
595 solution->dual_values[row] = revised_simplex_->GetDualValue(row);
596 solution->constraint_statuses[row] =
597 revised_simplex_->GetConstraintStatus(row);
598 }
599 if (!parameters_.use_preprocessing() && !parameters_.use_scaling()) {
600 if (solution->status == ProblemStatus::PRIMAL_UNBOUNDED) {
601 primal_ray_ = revised_simplex_->GetPrimalRay();
602 // Make sure we do not copy the slacks added by revised_simplex_.
603 primal_ray_.resize(num_cols);
604 } else if (solution->status == ProblemStatus::DUAL_UNBOUNDED) {
605 constraints_dual_ray_ = revised_simplex_->GetDualRay();
606 variable_bounds_dual_ray_ =
607 revised_simplex_->GetDualRayRowCombination();
608 // Make sure we do not copy the slacks added by revised_simplex_.
609 variable_bounds_dual_ray_.resize(num_cols);
610 // Revised simplex's GetDualRay is always such that GetDualRay.rhs < 0,
611 // which is a cost improving direction for the dual if the primal is a
612 // maximization problem (i.e. when the dual is a minimization problem).
613 // Hence, we change the sign of constraints_dual_ray_ for min problems.
614 //
615 // Revised simplex's GetDualRayRowCombination = A^T GetDualRay and
616 // we must have variable_bounds_dual_ray_ = - A^T constraints_dual_ray_.
617 // Then we need to change the sign of variable_bounds_dual_ray_, but for
618 // min problems this change is implicit because of the sign change of
619 // constraints_dual_ray_ described above.
620 if (current_linear_program_.IsMaximizationProblem()) {
621 ChangeSign(&variable_bounds_dual_ray_);
622 } else {
623 ChangeSign(&constraints_dual_ray_);
624 }
625 }
626 }
627 } else {
628 SOLVER_LOG(&logger_, "Error during the revised simplex algorithm.");
629 solution->status = ProblemStatus::ABNORMAL;
630 }
631}
632
633namespace {
634
635void LogVariableStatusError(ColIndex col, Fractional value,
637 Fractional ub) {
638 VLOG(1) << "Variable " << col << " status is "
639 << GetVariableStatusString(status) << " but its value is " << value
640 << " and its bounds are [" << lb << ", " << ub << "].";
641}
642
643void LogConstraintStatusError(RowIndex row, ConstraintStatus status,
644 Fractional lb, Fractional ub) {
645 VLOG(1) << "Constraint " << row << " status is "
646 << GetConstraintStatusString(status) << " but its bounds are [" << lb
647 << ", " << ub << "].";
648}
649
650} // namespace
651
652bool LPSolver::IsProblemSolutionConsistent(
653 const LinearProgram& lp, const ProblemSolution& solution) const {
654 const RowIndex num_rows = lp.num_constraints();
655 const ColIndex num_cols = lp.num_variables();
656 if (solution.variable_statuses.size() != num_cols) return false;
657 if (solution.constraint_statuses.size() != num_rows) return false;
658 if (solution.primal_values.size() != num_cols) return false;
659 if (solution.dual_values.size() != num_rows) return false;
660 if (solution.status != ProblemStatus::OPTIMAL &&
661 solution.status != ProblemStatus::PRIMAL_FEASIBLE &&
662 solution.status != ProblemStatus::DUAL_FEASIBLE) {
663 return true;
664 }
665
666 // This checks that the variable statuses verify the properties described
667 // in the VariableStatus declaration.
668 RowIndex num_basic_variables(0);
669 for (ColIndex col(0); col < num_cols; ++col) {
670 const Fractional value = solution.primal_values[col];
671 const Fractional lb = lp.variable_lower_bounds()[col];
672 const Fractional ub = lp.variable_upper_bounds()[col];
673 const VariableStatus status = solution.variable_statuses[col];
674 switch (solution.variable_statuses[col]) {
676 // TODO(user): Check that the reduced cost of this column is epsilon
677 // close to zero.
678 ++num_basic_variables;
679 break;
681 // TODO(user): Because of scaling, it is possible that a FIXED_VALUE
682 // status (only reserved for the exact lb == ub case) is now set for a
683 // variable where (ub == lb + epsilon). So we do not check here that the
684 // two bounds are exactly equal. The best is probably to remove the
685 // FIXED status from the API completely and report one of AT_LOWER_BOUND
686 // or AT_UPPER_BOUND instead. This also allows to indicate if at
687 // optimality, the objective is limited because of this variable lower
688 // bound or its upper bound. Note that there are other TODOs in the
689 // codebase about removing this FIXED_VALUE status.
690 if (value != ub && value != lb) {
691 LogVariableStatusError(col, value, status, lb, ub);
692 return false;
693 }
694 break;
696 if (value != lb || lb == ub) {
697 LogVariableStatusError(col, value, status, lb, ub);
698 return false;
699 }
700 break;
702 // TODO(user): revert to an exact comparison once the bug causing this
703 // to fail has been fixed.
704 if (!AreWithinAbsoluteTolerance(value, ub, 1e-7) || lb == ub) {
705 LogVariableStatusError(col, value, status, lb, ub);
706 return false;
707 }
708 break;
710 if (lb != -kInfinity || ub != kInfinity || value != 0.0) {
711 LogVariableStatusError(col, value, status, lb, ub);
712 return false;
713 }
714 break;
715 }
716 }
717 for (RowIndex row(0); row < num_rows; ++row) {
718 const Fractional dual_value = solution.dual_values[row];
719 const Fractional lb = lp.constraint_lower_bounds()[row];
720 const Fractional ub = lp.constraint_upper_bounds()[row];
721 const ConstraintStatus status = solution.constraint_statuses[row];
722
723 // The activity value is not checked since it is imprecise.
724 // TODO(user): Check that the activity is epsilon close to the expected
725 // value.
726 switch (status) {
728 if (dual_value != 0.0) {
729 VLOG(1) << "Constraint " << row << " is BASIC, but its dual value is "
730 << dual_value << " instead of 0.";
731 return false;
732 }
733 ++num_basic_variables;
734 break;
736 // Exactly the same remark as for the VariableStatus::FIXED_VALUE case
737 // above. Because of precision error, this can happen when the
738 // difference between the two bounds is small and not just exactly zero.
739 if (ub - lb > 1e-12) {
740 LogConstraintStatusError(row, status, lb, ub);
741 return false;
742 }
743 break;
745 if (lb == -kInfinity) {
746 LogConstraintStatusError(row, status, lb, ub);
747 return false;
748 }
749 break;
751 if (ub == kInfinity) {
752 LogConstraintStatusError(row, status, lb, ub);
753 return false;
754 }
755 break;
757 if (dual_value != 0.0) {
758 VLOG(1) << "Constraint " << row << " is FREE, but its dual value is "
759 << dual_value << " instead of 0.";
760 return false;
761 }
762 if (lb != -kInfinity || ub != kInfinity) {
763 LogConstraintStatusError(row, status, lb, ub);
764 return false;
765 }
766 break;
767 }
768 }
769
770 // TODO(user): We could check in debug mode (because it will be costly) that
771 // the basis is actually factorizable.
772 if (num_basic_variables != num_rows) {
773 VLOG(1) << "Wrong number of basic variables: " << num_basic_variables;
774 return false;
775 }
776 return true;
777}
778
779// This computes by how much the objective must be perturbed to enforce the
780// following complementary slackness conditions:
781// - Reduced cost is exactly zero for FREE and BASIC variables.
782// - Reduced cost is of the correct sign for variables at their bounds.
783Fractional LPSolver::ComputeMaxCostPerturbationToEnforceOptimality(
784 const LinearProgram& lp, bool* is_too_large) {
785 Fractional max_cost_correction = 0.0;
786 const ColIndex num_cols = lp.num_variables();
787 const Fractional optimization_sign = lp.IsMaximizationProblem() ? -1.0 : 1.0;
788 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
789 for (ColIndex col(0); col < num_cols; ++col) {
790 // We correct the reduced cost, so we have a minimization problem and
791 // thus the dual objective value will be a lower bound of the primal
792 // objective.
793 const Fractional reduced_cost = optimization_sign * reduced_costs_[col];
794 const VariableStatus status = variable_statuses_[col];
796 (status == VariableStatus::AT_UPPER_BOUND && reduced_cost > 0.0) ||
797 (status == VariableStatus::AT_LOWER_BOUND && reduced_cost < 0.0)) {
798 max_cost_correction =
799 std::max(max_cost_correction, std::abs(reduced_cost));
800 *is_too_large |=
801 std::abs(reduced_cost) >
802 AllowedError(tolerance, lp.objective_coefficients()[col]);
803 }
804 }
805 SOLVER_LOG(&logger_, "Max. cost perturbation = ", max_cost_correction);
806 return max_cost_correction;
807}
808
809// This computes by how much the rhs must be perturbed to enforce the fact that
810// the constraint activities exactly reflect their status.
811Fractional LPSolver::ComputeMaxRhsPerturbationToEnforceOptimality(
812 const LinearProgram& lp, bool* is_too_large) {
813 Fractional max_rhs_correction = 0.0;
814 const RowIndex num_rows = lp.num_constraints();
815 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
816 for (RowIndex row(0); row < num_rows; ++row) {
817 const Fractional lower_bound = lp.constraint_lower_bounds()[row];
818 const Fractional upper_bound = lp.constraint_upper_bounds()[row];
819 const Fractional activity = constraint_activities_[row];
820 const ConstraintStatus status = constraint_statuses_[row];
821
822 Fractional rhs_error = 0.0;
823 Fractional allowed_error = 0.0;
825 rhs_error = std::abs(activity - lower_bound);
826 allowed_error = AllowedError(tolerance, lower_bound);
828 activity > upper_bound) {
829 rhs_error = std::abs(activity - upper_bound);
830 allowed_error = AllowedError(tolerance, upper_bound);
831 }
832 max_rhs_correction = std::max(max_rhs_correction, rhs_error);
833 *is_too_large |= rhs_error > allowed_error;
834 }
835 SOLVER_LOG(&logger_, "Max. rhs perturbation = ", max_rhs_correction);
836 return max_rhs_correction;
837}
838
839void LPSolver::ComputeConstraintActivities(const LinearProgram& lp) {
840 const RowIndex num_rows = lp.num_constraints();
841 const ColIndex num_cols = lp.num_variables();
842 DCHECK_EQ(num_cols, primal_values_.size());
843 constraint_activities_.assign(num_rows, 0.0);
844 for (ColIndex col(0); col < num_cols; ++col) {
845 lp.GetSparseColumn(col).AddMultipleToDenseVector(primal_values_[col],
846 &constraint_activities_);
847 }
848}
849
850void LPSolver::ComputeReducedCosts(const LinearProgram& lp) {
851 const RowIndex num_rows = lp.num_constraints();
852 const ColIndex num_cols = lp.num_variables();
853 DCHECK_EQ(num_rows, dual_values_.size());
854 reduced_costs_.resize(num_cols, 0.0);
855 for (ColIndex col(0); col < num_cols; ++col) {
856 reduced_costs_[col] = lp.objective_coefficients()[col] -
857 ScalarProduct(dual_values_, lp.GetSparseColumn(col));
858 }
859}
860
861double LPSolver::ComputeObjective(const LinearProgram& lp) {
862 const ColIndex num_cols = lp.num_variables();
863 DCHECK_EQ(num_cols, primal_values_.size());
864 KahanSum sum;
865 for (ColIndex col(0); col < num_cols; ++col) {
866 sum.Add(lp.objective_coefficients()[col] * primal_values_[col]);
867 }
868 return sum.Value();
869}
870
871// By the duality theorem, the dual "objective" is a bound on the primal
872// objective obtained by taking the linear combinaison of the constraints
873// given by dual_values_.
874//
875// As it is written now, this has no real precise meaning since we ignore
876// infeasible reduced costs. This is almost the same as computing the objective
877// to the perturbed problem, but then we don't use the pertubed rhs. It is just
878// here as an extra "consistency" check.
879//
880// Note(user): We could actually compute an EXACT lower bound for the cost of
881// the non-cost perturbed problem. The idea comes from "Safe bounds in linear
882// and mixed-integer linear programming", Arnold Neumaier , Oleg Shcherbina,
883// Math Prog, 2003. Note that this requires having some variable bounds that may
884// not be in the original problem so that the current dual solution is always
885// feasible. It also involves changing the rounding mode to obtain exact
886// confidence intervals on the reduced costs.
887double LPSolver::ComputeDualObjective(const LinearProgram& lp) {
888 KahanSum dual_objective;
889
890 // Compute the part coming from the row constraints.
891 const RowIndex num_rows = lp.num_constraints();
892 const Fractional optimization_sign = lp.IsMaximizationProblem() ? -1.0 : 1.0;
893 for (RowIndex row(0); row < num_rows; ++row) {
894 const Fractional lower_bound = lp.constraint_lower_bounds()[row];
895 const Fractional upper_bound = lp.constraint_upper_bounds()[row];
896
897 // We correct the optimization_sign so we have to compute a lower bound.
898 const Fractional corrected_value = optimization_sign * dual_values_[row];
899 if (corrected_value > 0.0 && lower_bound != -kInfinity) {
900 dual_objective.Add(dual_values_[row] * lower_bound);
901 }
902 if (corrected_value < 0.0 && upper_bound != kInfinity) {
903 dual_objective.Add(dual_values_[row] * upper_bound);
904 }
905 }
906
907 // For a given column associated to a variable x, we want to find a lower
908 // bound for c.x (where c is the objective coefficient for this column). If we
909 // write a.x the linear combination of the constraints at this column we have:
910 // (c + a - c) * x = a * x, and so
911 // c * x = a * x + (c - a) * x
912 // Now, if we suppose for example that the reduced cost 'c - a' is positive
913 // and that x is lower-bounded by 'lb' then the best bound we can get is
914 // c * x >= a * x + (c - a) * lb.
915 //
916 // Note: when summing over all variables, the left side is the primal
917 // objective and the right side is a lower bound to the objective. In
918 // particular, a necessary and sufficient condition for both objectives to be
919 // the same is that all the single variable inequalities above be equalities.
920 // This is possible only if c == a or if x is at its bound (modulo the
921 // optimization_sign of the reduced cost), or both (this is one side of the
922 // complementary slackness conditions, see Chvatal p. 62).
923 const ColIndex num_cols = lp.num_variables();
924 for (ColIndex col(0); col < num_cols; ++col) {
925 const Fractional lower_bound = lp.variable_lower_bounds()[col];
926 const Fractional upper_bound = lp.variable_upper_bounds()[col];
927
928 // Correct the reduced cost, so as to have a minimization problem and
929 // thus a dual objective that is a lower bound of the primal objective.
930 const Fractional reduced_cost = optimization_sign * reduced_costs_[col];
931
932 // We do not do any correction if the reduced cost is 'infeasible', which is
933 // the same as computing the objective of the perturbed problem.
934 Fractional correction = 0.0;
935 if (variable_statuses_[col] == VariableStatus::AT_LOWER_BOUND &&
936 reduced_cost > 0.0) {
937 correction = reduced_cost * lower_bound;
938 } else if (variable_statuses_[col] == VariableStatus::AT_UPPER_BOUND &&
939 reduced_cost < 0.0) {
940 correction = reduced_cost * upper_bound;
941 } else if (variable_statuses_[col] == VariableStatus::FIXED_VALUE) {
942 correction = reduced_cost * upper_bound;
943 }
944 // Now apply the correction in the right direction!
945 dual_objective.Add(optimization_sign * correction);
946 }
947 return dual_objective.Value();
948}
949
950double LPSolver::ComputeMaxExpectedObjectiveError(const LinearProgram& lp) {
951 const ColIndex num_cols = lp.num_variables();
952 DCHECK_EQ(num_cols, primal_values_.size());
953 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
954 Fractional primal_objective_error = 0.0;
955 for (ColIndex col(0); col < num_cols; ++col) {
956 // TODO(user): Be more precise since the non-BASIC variables are exactly at
957 // their bounds, so for them the error bound is just the term magnitude
958 // times std::numeric_limits<double>::epsilon() with KahanSum.
959 primal_objective_error += std::abs(lp.objective_coefficients()[col]) *
960 AllowedError(tolerance, primal_values_[col]);
961 }
962 return primal_objective_error;
963}
964
965double LPSolver::ComputePrimalValueInfeasibility(const LinearProgram& lp,
966 bool* is_too_large) {
967 double infeasibility = 0.0;
968 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
969 const ColIndex num_cols = lp.num_variables();
970 for (ColIndex col(0); col < num_cols; ++col) {
971 const Fractional lower_bound = lp.variable_lower_bounds()[col];
972 const Fractional upper_bound = lp.variable_upper_bounds()[col];
973 DCHECK(IsFinite(primal_values_[col]));
974
975 if (lower_bound == upper_bound) {
976 const Fractional error = std::abs(primal_values_[col] - upper_bound);
977 infeasibility = std::max(infeasibility, error);
978 *is_too_large |= error > AllowedError(tolerance, upper_bound);
979 continue;
980 }
981 if (primal_values_[col] > upper_bound) {
982 const Fractional error = primal_values_[col] - upper_bound;
983 infeasibility = std::max(infeasibility, error);
984 *is_too_large |= error > AllowedError(tolerance, upper_bound);
985 }
986 if (primal_values_[col] < lower_bound) {
987 const Fractional error = lower_bound - primal_values_[col];
988 infeasibility = std::max(infeasibility, error);
989 *is_too_large |= error > AllowedError(tolerance, lower_bound);
990 }
991 }
992 return infeasibility;
993}
994
995double LPSolver::ComputeActivityInfeasibility(const LinearProgram& lp,
996 bool* is_too_large) {
997 double infeasibility = 0.0;
998 int num_problematic_rows(0);
999 const RowIndex num_rows = lp.num_constraints();
1000 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
1001 for (RowIndex row(0); row < num_rows; ++row) {
1002 const Fractional activity = constraint_activities_[row];
1003 const Fractional lower_bound = lp.constraint_lower_bounds()[row];
1004 const Fractional upper_bound = lp.constraint_upper_bounds()[row];
1005 DCHECK(IsFinite(activity));
1006
1007 if (lower_bound == upper_bound) {
1008 if (std::abs(activity - upper_bound) >
1009 AllowedError(tolerance, upper_bound)) {
1010 VLOG(2) << "Row " << row.value() << " has activity " << activity
1011 << " which is different from " << upper_bound << " by "
1012 << activity - upper_bound;
1013 ++num_problematic_rows;
1014 }
1015 infeasibility = std::max(infeasibility, std::abs(activity - upper_bound));
1016 continue;
1017 }
1018 if (activity > upper_bound) {
1019 const Fractional row_excess = activity - upper_bound;
1020 if (row_excess > AllowedError(tolerance, upper_bound)) {
1021 VLOG(2) << "Row " << row.value() << " has activity " << activity
1022 << ", exceeding its upper bound " << upper_bound << " by "
1023 << row_excess;
1024 ++num_problematic_rows;
1025 }
1026 infeasibility = std::max(infeasibility, row_excess);
1027 }
1028 if (activity < lower_bound) {
1029 const Fractional row_deficit = lower_bound - activity;
1030 if (row_deficit > AllowedError(tolerance, lower_bound)) {
1031 VLOG(2) << "Row " << row.value() << " has activity " << activity
1032 << ", below its lower bound " << lower_bound << " by "
1033 << row_deficit;
1034 ++num_problematic_rows;
1035 }
1036 infeasibility = std::max(infeasibility, row_deficit);
1037 }
1038 }
1039 if (num_problematic_rows > 0) {
1040 *is_too_large = true;
1041 VLOG(1) << "Number of infeasible rows = " << num_problematic_rows;
1042 }
1043 return infeasibility;
1044}
1045
1046double LPSolver::ComputeDualValueInfeasibility(const LinearProgram& lp,
1047 bool* is_too_large) {
1048 const Fractional allowed_error = parameters_.solution_feasibility_tolerance();
1049 const Fractional optimization_sign = lp.IsMaximizationProblem() ? -1.0 : 1.0;
1050 double infeasibility = 0.0;
1051 const RowIndex num_rows = lp.num_constraints();
1052 for (RowIndex row(0); row < num_rows; ++row) {
1053 const Fractional dual_value = dual_values_[row];
1054 const Fractional lower_bound = lp.constraint_lower_bounds()[row];
1055 const Fractional upper_bound = lp.constraint_upper_bounds()[row];
1056 DCHECK(IsFinite(dual_value));
1057 const Fractional minimization_dual_value = optimization_sign * dual_value;
1058 if (lower_bound == -kInfinity) {
1059 *is_too_large |= minimization_dual_value > allowed_error;
1060 infeasibility = std::max(infeasibility, minimization_dual_value);
1061 }
1062 if (upper_bound == kInfinity) {
1063 *is_too_large |= -minimization_dual_value > allowed_error;
1064 infeasibility = std::max(infeasibility, -minimization_dual_value);
1065 }
1066 }
1067 return infeasibility;
1068}
1069
1070double LPSolver::ComputeReducedCostInfeasibility(const LinearProgram& lp,
1071 bool* is_too_large) {
1072 const Fractional optimization_sign = lp.IsMaximizationProblem() ? -1.0 : 1.0;
1073 double infeasibility = 0.0;
1074 const ColIndex num_cols = lp.num_variables();
1075 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
1076 for (ColIndex col(0); col < num_cols; ++col) {
1077 const Fractional reduced_cost = reduced_costs_[col];
1078 const Fractional lower_bound = lp.variable_lower_bounds()[col];
1079 const Fractional upper_bound = lp.variable_upper_bounds()[col];
1080 DCHECK(IsFinite(reduced_cost));
1081 const Fractional minimization_reduced_cost =
1082 optimization_sign * reduced_cost;
1083 const Fractional allowed_error =
1084 AllowedError(tolerance, lp.objective_coefficients()[col]);
1085 if (lower_bound == -kInfinity) {
1086 *is_too_large |= minimization_reduced_cost > allowed_error;
1087 infeasibility = std::max(infeasibility, minimization_reduced_cost);
1088 }
1089 if (upper_bound == kInfinity) {
1090 *is_too_large |= -minimization_reduced_cost > allowed_error;
1091 infeasibility = std::max(infeasibility, -minimization_reduced_cost);
1092 }
1093 }
1094 return infeasibility;
1095}
1096
1097} // namespace glop
1098} // namespace operations_research
int64_t max
Definition: alldiff_cst.cc:140
int64_t min
Definition: alldiff_cst.cc:139
#define DLOG(severity)
Definition: base/logging.h:880
#define CHECK(condition)
Definition: base/logging.h:495
#define DCHECK_LE(val1, val2)
Definition: base/logging.h:892
#define LOG(severity)
Definition: base/logging.h:420
#define DCHECK(condition)
Definition: base/logging.h:889
#define DCHECK_EQ(val1, val2)
Definition: base/logging.h:890
#define VLOG(verboselevel)
Definition: base/logging.h:983
void push_back(const value_type &x)
void Add(const FpNumber &value)
Definition: accurate_sum.h:29
void SetLogToStdOut(bool enable)
Definition: util/logging.h:45
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Definition: time_limit.h:106
static std::unique_ptr< TimeLimit > FromParameters(const Parameters &parameters)
Creates a time limit object initialized from an object that provides methods max_time_in_seconds() an...
Definition: time_limit.h:160
void MergeFrom(const GlopParameters &from)
const GlopParameters & GetParameters() const
Definition: lp_solver.cc:124
void SetInitialBasis(const VariableStatusRow &variable_statuses, const ConstraintStatusColumn &constraint_statuses)
Definition: lp_solver.cc:241
bool MayHaveMultipleOptimalSolutions() const
Definition: lp_solver.cc:500
const VariableStatusRow & variable_statuses() const
Definition: lp_solver.h:103
GlopParameters * GetMutableParameters()
Definition: lp_solver.cc:126
Fractional GetMaximumDualInfeasibility() const
Definition: lp_solver.cc:496
const ConstraintStatusColumn & constraint_statuses() const
Definition: lp_solver.h:117
Fractional GetMaximumPrimalInfeasibility() const
Definition: lp_solver.cc:492
Fractional GetObjectiveValue() const
Definition: lp_solver.cc:488
ProblemStatus LoadAndVerifySolution(const LinearProgram &lp, const ProblemSolution &solution)
Definition: lp_solver.cc:296
ABSL_MUST_USE_RESULT ProblemStatus Solve(const LinearProgram &lp)
Definition: lp_solver.cc:130
ABSL_MUST_USE_RESULT ProblemStatus SolveWithTimeLimit(const LinearProgram &lp, TimeLimit *time_limit)
Definition: lp_solver.cc:136
void SetParameters(const GlopParameters &parameters)
Definition: lp_solver.cc:112
std::string GetObjectiveStatsString() const
Definition: lp_data.cc:452
void PopulateFromLinearProgram(const LinearProgram &linear_program)
Definition: lp_data.cc:862
std::string GetBoundsStatsString() const
Definition: lp_data.cc:465
const DenseColumn & constraint_lower_bounds() const
Definition: lp_data.h:215
const DenseRow & variable_upper_bounds() const
Definition: lp_data.h:232
const DenseColumn & constraint_upper_bounds() const
Definition: lp_data.h:218
const DenseRow & variable_lower_bounds() const
Definition: lp_data.h:229
std::string GetDimensionString() const
Definition: lp_data.cc:425
Fractional objective_scaling_factor() const
Definition: lp_data.h:261
void DestructiveRecoverSolution(ProblemSolution *solution)
void SetTimeLimit(TimeLimit *time_limit)
Definition: preprocessor.h:75
void assign(IntType size, const T &v)
Definition: lp_types.h:278
SatParameters parameters
CpModelProto proto
ModelSharedTimeLimit * time_limit
int64_t value
absl::Status status
Definition: g_gurobi.cc:35
double upper_bound
double lower_bound
const int WARNING
Definition: log_severity.h:31
const int ERROR
Definition: log_severity.h:32
ABSL_FLAG(bool, lp_dump_to_proto_file, false, "Tells whether do dump the problem to a protobuf file.")
ColIndex col
Definition: markowitz.cc:183
RowIndex row
Definition: markowitz.cc:182
AccurateSum< Fractional > KahanSum
Fractional ScalarProduct(const DenseRowOrColumn1 &u, const DenseRowOrColumn2 &v)
std::string GetProblemStatusString(ProblemStatus problem_status)
Definition: lp_types.cc:19
std::string GetConstraintStatusString(ConstraintStatus status)
Definition: lp_types.cc:90
void LinearProgramToMPModelProto(const LinearProgram &input, MPModelProto *output)
Definition: proto_utils.cc:20
bool IsFinite(Fractional value)
Definition: lp_types.h:91
void ChangeSign(StrictITIVector< IndexType, Fractional > *data)
std::string GetVariableStatusString(VariableStatus status)
Definition: lp_types.cc:71
const double kInfinity
Definition: lp_types.h:84
Collection of objects used to extend the Constraint Solver library.
bool WriteProtoToFile(absl::string_view filename, const google::protobuf::Message &proto, ProtoWriteFormat proto_write_format, bool gzipped, bool append_extension_to_file_name)
Definition: file_util.cc:106
bool AreWithinAbsoluteTolerance(FloatType x, FloatType y, FloatType absolute_tolerance)
Definition: fp_utils.h:145
ConstraintStatusColumn constraint_statuses
Definition: lp_data.h:686
#define SOLVER_LOG(logger,...)
Definition: util/logging.h:69
#define VLOG_IS_ON(verboselevel)
Definition: vlog_is_on.h:44