KrisLibrary  1.0.0
LPOptimumFunction.h
1 #ifndef LP_OPTIMUM_FUNCTION
2 #define LP_OPTIMUM_FUNCTION
3 
4 #include "LinearProgram.h"
5 #include "GLPKInterface.h"
7 
8 namespace Optimization {
9  using namespace Math;
10 
19 {
20  public:
22  //subclasses overload these
23  virtual void InitLP(const Vector& x) {}
24  virtual void UpdateLP(const Vector& x) { FatalError("Update not defined in subclas of LPOptimumFunction"); }
25  virtual bool LPJacobianC(const Vector& x,Matrix& Jc) { return false; }
26  virtual bool LPJacobianC(const Vector& x,SparseMatrix& Jc) { return false; }
27  //derivative of row_i(A) w.r.t x
28  virtual bool LPJacobianA_i(const Vector& x,int i,Matrix& JAi) { return false; }
29  virtual bool LPJacobianA_i(const Vector& x,int i,SparseMatrix& JAi) { return false; }
30  virtual bool LPJacobianP_i(const Vector& x,int i,Vector& Jpi) { return false; }
31  virtual bool LPJacobianQ_i(const Vector& x,int i,Vector& Jqi) { return false; }
32  virtual bool LPJacobianL_j(const Vector& x,int j,Vector& Jlj) { return false; }
33  virtual bool LPJacobianU_j(const Vector& x,int j,Vector& Juj) { return false; }
34 
37  virtual void UpdateGLPK(const Vector& x);
38 
39  virtual std::string Label() const { return "LPOptimum"; }
40  virtual void PreEval(const Vector& x);
41  virtual Real Eval(const Vector& x);
42  virtual void Gradient(const Vector& x,Vector& grad);
43  virtual Real Gradient_i(const Vector& x,int i);
44 
45  bool initialized;
46  bool sparse;
47  LinearProgram lp;
49  GLPKInterface glpk;
50 
51  LinearProgram::Result solveResult;
52  Vector yopt;
53 };
54 
63 {
64  public:
66  virtual int NumDimensions() const;
67  //subclasses overload these
68  virtual void InitLP(const Vector& x) {}
69  virtual void UpdateLP(const Vector& x) { FatalError("Update not defined in subclas of LPOptimumFunction"); }
70  virtual bool LPJacobianA_i(const Vector& x,int i,Matrix& JAi) { return false; }
71  virtual bool LPJacobianA_i(const Vector& x,int i,SparseMatrix& JAi) { return false; }
72  virtual bool LPJacobianP_i(const Vector& x,int i,Vector& Jpi) { return false; }
73  virtual bool LPJacobianQ_i(const Vector& x,int i,Vector& Jqi) { return false; }
74  virtual bool LPJacobianL_j(const Vector& x,int j,Vector& Jlj) { return false; }
75  virtual bool LPJacobianU_j(const Vector& x,int j,Vector& Juj) { return false; }
76 
79  virtual void UpdateGLPK(const Vector& x);
80 
81  virtual std::string Label() const { return "LPOptimum"; }
82  virtual void PreEval(const Vector& x);
83  virtual void Eval(const Vector& x,Vector& v);
84  virtual void Jacobian(const Vector& x,Matrix& J);
85  virtual void Jacobian_i(const Vector& x,int i,Vector& Ji);
86 
87  bool initialized;
88  bool sparse;
89  LinearProgram lp;
91  GLPKInterface glpk;
92 
93  LinearProgram::Result solveResult;
94  Vector yopt;
95 };
96 
97 
98 } //namespace Optimization
99 
100 #endif
An interface to the GLPK linear program solver. Activated with the HAVE_GLPK preprocessor define...
Definition: GLPKInterface.h:19
Namespace for classes and functions in the Optimization package.
Definition: CSet.h:7
Abstract base classes for function interfaces.
Linear program definition with sparse matrix A.
Definition: LinearProgram.h:158
A function from R^n to R^m.
Definition: function.h:134
A vector field v(x) = arg min_y c(x)^T y s.t. q(x) <= A(x)y <= p(x), l(x) <= y <= u(x) where c...
Definition: LPOptimumFunction.h:62
A function from R^n to R.
Definition: function.h:97
Linear program definition.Represents the LP min/max c.x subject to qi <= ai.x <= pi lj <= xj <= u...
Definition: LinearProgram.h:139
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
A scalar field v(x) = min_y c(x)^T y s.t. q(x) <= A(x)y <= p(x), l(x) <= y <= u(x) where c...
Definition: LPOptimumFunction.h:18