add vrp constraint to the sat solver; remove old no_cycle code

This commit is contained in:
Laurent Perron
2017-10-16 11:20:54 +02:00
parent 4bea1f9922
commit e8540c1363
18 changed files with 593 additions and 880 deletions

View File

@@ -16,6 +16,7 @@
#include <limits>
#include "ortools/base/logging.h"
#include "ortools/linear_solver/linear_solver.h"
namespace operations_research {
@@ -70,6 +71,14 @@ LinearExpr LinearExpr::NotVar(LinearExpr var) {
return var;
}
double LinearExpr::SolutionValue() const {
double solution = offset_;
for (const auto& pair : terms_) {
solution += pair.first->solution_value() * pair.second;
}
return solution;
}
LinearExpr operator+(LinearExpr lhs, const LinearExpr& rhs) {
lhs += rhs;
return lhs;

View File

@@ -92,7 +92,7 @@ class MPVariable;
// * Get the value of the quantity after solving, e.g.
//
// solver.Solve();
// solver.SolutionValue(linear_expr);
// linear_expr.SolutionValue();
//
// LinearExpr is allowed to delete variables with coefficient zero from the map,
// but is not obligated to do so.
@@ -122,6 +122,10 @@ class LinearExpr {
return terms_;
}
// Call only after calling MPSolver::Solve. Evaluates the value of this
// expression at the solution found.
double SolutionValue() const;
private:
double offset_;
std::unordered_map<const MPVariable*, double> terms_;

View File

@@ -989,14 +989,6 @@ MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters& param) {
return status;
}
double MPSolver::SolutionValue(const LinearExpr& linear_expr) const {
double ans = linear_expr.offset();
for (const auto& kv : linear_expr.terms()) {
ans += (kv.second * kv.first->solution_value());
}
return ans;
}
void MPSolver::Write(const std::string& file_name) { interface_->Write(file_name); }
namespace {
@@ -1323,7 +1315,7 @@ bool MPSolverInterface::CheckSolutionIsSynchronized() const {
}
// Default version that can be overwritten by a solver-specific
// version to accomodate for the quirks of each solver.
// version to accommodate for the quirks of each solver.
bool MPSolverInterface::CheckSolutionExists() const {
if (result_status_ != MPSolver::OPTIMAL &&
result_status_ != MPSolver::FEASIBLE) {
@@ -1335,7 +1327,7 @@ bool MPSolverInterface::CheckSolutionExists() const {
}
// Default version that can be overwritten by a solver-specific
// version to accomodate for the quirks of each solver.
// version to accommodate for the quirks of each solver.
bool MPSolverInterface::CheckBestObjectiveBoundExists() const {
if (result_status_ != MPSolver::OPTIMAL &&
result_status_ != MPSolver::FEASIBLE) {

View File

@@ -332,10 +332,6 @@ class MPSolver {
// Solves the problem using the specified parameter values.
ResultStatus Solve(const MPSolverParameters& param);
// Call only after calling MPSolver::Solve. Evaluates "linear_expr" for the
// variable values at the solution found by solving.
double SolutionValue(const LinearExpr& linear_expr) const;
// Writes the model using the solver internal write function. Currently only
// available for Gurobi.
void Write(const std::string& file_name);