22 LinExpr(
double constant=0.0) { constant_ = constant; vars_.clear(); coeffs_.clear(); }
23 LinExpr(
Var var,
double coeff=1.0) { constant_ = 0.0; vars_.push_back(var); coeffs_.push_back(coeff); }
25 double getValue()
const;
26 static bool isClean(
const LinExpr& rhs);
28 size_t size()
const {
return vars_.size(); }
29 double& getConstant() {
return constant_; }
30 const Var& getVar(
int i)
const {
return vars_[i]; }
31 double getCoeff(
int i)
const {
return coeffs_[i]; }
32 const double& getConstant()
const {
return constant_; }
33 void clear() { constant_ = 0.0; coeffs_.clear(); vars_.clear(); }
35 LinExpr operator*(
double factor)
const;
37 LinExpr& operator+=(
double a) { *
this +=
LinExpr(a);
return *
this; }
38 LinExpr& operator-=(
double a) { *
this +=
LinExpr(-a);
return *
this; }
39 LinExpr& operator-=(
const LinExpr& rhs) { *
this += rhs*(-1.0);
return *
this; }
40 LinExpr operator/(
double a) {
LinExpr result = 0.0; result = *
this*(1.0/a);
return result; }
46 LinExpr operator-(
const LinExpr& rhs)
const {
LinExpr result = *
this; result += rhs*(-1.0);
return result; }
47 LinExpr operator=(
const LinExpr& rhs) { constant_ = rhs.constant_; vars_ = rhs.vars_; coeffs_ = rhs.coeffs_;
return *
this; }
48 LinExpr& operator*=(
double a) { constant_ *= a;
for (
int i=0; i<(int)vars_.size(); i++) { coeffs_[i] *= a; }
return *
this; }
49 LinExpr& operator/=(
double a) { constant_ /= a;
for (
int i=0; i<(int)vars_.size(); i++) { coeffs_[i] /= a; }
return *
this; }
67 friend LinExpr operator*(
double factor,
const LinExpr& rhs) {
LinExpr result = rhs*factor;
return result; }
69 friend std::ostream& operator<<(std::ostream &stream,
LinExpr expr);
73 std::vector<Var> vars_;
74 std::vector<double> coeffs_;
94 std::ostream& operator<<(std::ostream &stream,
LinExpr expr);
103 DCPQuadExpr() : lexpr_(0.0), trust_region_(
false), soft_constraint_(
false) {}
106 double getValue()
const;
107 void addLinTerm(
const LinExpr& lexpr) { lexpr_ += lexpr; }
108 void clear() { lexpr_ = 0.0; qexpr_.clear(); coeffs_.clear(); extra_vars_.clear(); }
109 void addQuaTerm(
double coeff,
const LinExpr& lexpr) {
if (coeff != 0.0) { qexpr_.push_back(lexpr); coeffs_.push_back(coeff); } }
111 LinExpr& lexpr() {
return lexpr_; }
112 std::string& sense() {
return sense_; }
113 bool& trustRegion() {
return trust_region_; }
114 std::vector<LinExpr>& qexpr() {
return qexpr_; }
115 std::vector<double>& coeffs() {
return coeffs_; }
116 bool& softConstraint() {
return soft_constraint_; }
117 std::vector<Var>& extraVars() {
return extra_vars_; }
119 const LinExpr& lexpr()
const {
return lexpr_; }
120 const std::string& sense()
const {
return sense_; }
121 const bool& trustRegion()
const {
return trust_region_; }
122 const std::vector<LinExpr>& qexpr()
const {
return qexpr_; }
123 const std::vector<double>& coeffs()
const {
return coeffs_; }
124 const bool& softConstraint()
const {
return soft_constraint_; }
125 const std::vector<Var>& extraVars()
const {
return extra_vars_; }
126 const Var& getVar(
int qid,
int lid)
const {
return qexpr_[qid].getVar(lid); }
131 std::vector<double> coeffs_;
132 std::vector<LinExpr> qexpr_;
133 std::vector<Var> extra_vars_;
134 bool trust_region_, soft_constraint_;
Helper class to ease the construction of a quadratic expression (e.g.
Definition: Exprs.hpp:100
Helper class to define an optimization variable, used in the construction of linear and quadratic exp...
Definition: Var.hpp:36
Helper class to ease the construction of a linear expression (e.g.
Definition: Exprs.hpp:19