From 3e013bb5be45540d210a3d24523b939730e7e573 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 1 Aug 2018 10:17:08 -0700 Subject: [PATCH] access to coefficients-variables pairs in linear_solver --- ortools/linear_solver/linear_solver.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index 425147c295..919d12f715 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -696,6 +696,12 @@ class MPObjective { // is 0 if the variable does not appear in the objective). double GetCoefficient(const MPVariable* const var) const; + // Returns a map from variables to their coefficients in the objective. If a + // variable is not present in the map, then its coefficient is zero. + const std::unordered_map& terms() const { + return coefficients_; + } + // Sets the constant term in the objective. void SetOffset(double value); // Gets the constant term in the objective. @@ -878,6 +884,12 @@ class MPConstraint { // is 0 if the variable does not appear in the constraint). double GetCoefficient(const MPVariable* const var) const; + // Returns a map from variables to their coefficients in the constraint. If a + // variable is not present in the map, then its coefficient is zero. + const std::unordered_map& terms() const { + return coefficients_; + } + // Returns the lower bound. double lb() const { return lb_; } // Returns the upper bound.