2 #include <boost/shared_ptr.hpp>
22 typedef vector<double> DblVec;
23 typedef vector<int> IntVec;
36 typedef vector<Var> VarVector;
37 typedef vector<AffExpr> AffExprVector;
38 typedef vector<QuadExpr> QuadExprVector;
48 virtual Var addVar(
const string& name)=0;
49 virtual Var addVar(
const string& name,
double lb,
double ub);
51 virtual Cnt addEqCnt(
const AffExpr&,
const string& name)=0;
52 virtual Cnt addIneqCnt(
const AffExpr&,
const string& name)=0;
53 virtual Cnt addIneqCnt(
const QuadExpr&,
const string& name)=0;
55 virtual void removeVar(
const Var& var);
56 virtual void removeCnt(
const Cnt& cnt);
57 virtual void removeVars(
const VarVector& vars)=0;
58 virtual void removeCnts(
const vector<Cnt>& cnts)=0;
60 virtual void update() = 0;
61 virtual void setVarBounds(
const Var& var,
double lower,
double upper);
62 virtual void setVarBounds(
const VarVector& vars,
const vector<double>& lower,
const vector<double>& upper)=0;
63 virtual double getVarValue(
const Var& var)
const;
64 virtual vector<double> getVarValues(
const VarVector& vars)
const=0;
65 virtual CvxOptStatus optimize()=0;
67 virtual void setObjective(
const AffExpr&)=0;
68 virtual void setObjective(
const QuadExpr&)=0;
69 virtual void writeToFile(
const string& fname)=0;
71 virtual VarVector getVars()
const=0;
78 VarRep(
int _index,
const string& _name,
void* _creator) : index(_index), name(_name), removed(
false), creator(_creator) {}
87 Var() : var_rep(NULL) {}
88 Var(
VarRep* var_rep) : var_rep(var_rep) {}
89 Var(
const Var& other) : var_rep(other.var_rep) {}
90 double value(
const double* x)
const {
return x[var_rep->index];}
91 double value(
const vector<double>& x)
const {assert(var_rep->index < (
int)x.size());
return x[var_rep->index];}
95 CntRep(
int _index,
void* _creator) : index(_index), removed(
false), creator(_creator){}
105 Cnt(): cnt_rep(NULL) {}
106 Cnt(
CntRep* cnt_rep) : cnt_rep(cnt_rep) {}
107 Cnt(
const Cnt& other) : cnt_rep(other.cnt_rep) {}
112 vector<double> coeffs;
115 explicit AffExpr(
double a) : constant(a) {}
116 explicit AffExpr(
const Var& v) : constant(0), coeffs(1, 1), vars(1, v) {}
118 constant(other.constant), coeffs(other.coeffs), vars(other.vars) {}
119 size_t size()
const {
return coeffs.size();}
120 double value(
const double* x)
const;
121 double value(
const vector<double>& x)
const;
126 vector<double> coeffs;
130 explicit QuadExpr(
double a) : affexpr(a) {}
133 size_t size()
const {
return coeffs.size();}
134 double value(
const double* x)
const;
135 double value(
const vector<double>& x)
const;
139 ostream& operator<<(ostream&,
const Var&);
140 ostream& operator<<(ostream&,
const Cnt&);
141 ostream& operator<<(ostream&,
const AffExpr&);
142 ostream& operator<<(ostream&,
const QuadExpr&);
145 ModelPtr createModel();