C++ Reference: class LinearExpr

This documentation is automatically generated.

LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization problem, i.e.

offset + sum_{i in S} a_i*x_i,

where the a_i and offset are constants and the x_i are MPVariables. You can use a LinearExpr "linear_expr" with an MPSolver "solver" to:
   * Set as the objective of your optimization problem, e.g.


   * Create a constraint in your optimization, e.g.

solver.MakeRowConstraint(linear_expr1 <= linear_expr2);

   * Get the value of the quantity after solving, e.g.

solver.Solve(); linear_expr.SolutionValue();

LinearExpr is allowed to delete variables with coefficient zero from the map, but is not obligated to do so.



Arguments: double constant

Possible implicit conversions are intentional.


Arguments: const MPVariable* var

* Possible implicit conversions are intentional. Warning: var is not owned.


Return type: static LinearExpr

Arguments: LinearExpr var

Returns 1-var. NOTE(user): if var is binary variable, this corresponds to the logical negation of var. Passing by value is intentional, see the discussion on binary ops.


Return type: double


Return type: double

Evaluates the value of this expression at the solution found. It must be called only after calling MPSolver::Solve.


Return type: const absl::flat_hash_map<const MPVariable*, double>&


Return type: std::string

A human readable representation of this. Variables will be printed in order of lowest index first.