• Main Page
  • Classes
  • Files
  • File List
  • File Members

sc_lp_problem.h

00001 /*
00002  *  sc_lp_problem.h
00003  *  DCSPackage
00004  *
00005  *  Created by David Hoerl on 12/8/10.
00006  *  Copyright 2010 Princeton Satellite Systems. All rights reserved.
00007  *
00008  */
00009 
00010 #ifndef _LP_PROBLEM
00011 #define _LP_PROBLEM
00012 
00013 #include <MatrixLib/matrixlib.h>
00014 
00023 class StatusReport
00024 {
00025 public:
00026         StatusReport() : 
00027     x(),
00028     fVal(),
00029     xConSlack(),
00030     xVarSlack(),
00031     xRelSlack(),
00032     err()
00033     {}
00034         ~StatusReport() {}
00036         bool status() const { return err ? false : true; }
00041         void display(const char *msg = NULL) const
00042     {
00043         printf("STATUS_REPORT: %s\n", msg ? msg : "" );
00044         if(err) { printf("ERROR: %s\n", err); return; }
00045         x.display("x"); printf("fVal=%lg\n", fVal); xConSlack.display("xConSlack"); xVarSlack.display("xVarSlack"); xRelSlack.display("xRelSlack");
00046     }
00047     
00048         StatusReport(const StatusReport& right) :
00049     x(right.x),
00050     fVal(right.fVal),
00051     xConSlack(right.xConSlack),
00052     xVarSlack(right.xVarSlack),
00053     xRelSlack(right.xRelSlack),
00054     err(right.err)
00055     {}
00056     
00057 private:        
00058         StatusReport& operator=(const StatusReport &that);      
00059     
00060 public:
00062         ml_matrix x;
00064         double fVal;
00066         ml_matrix xConSlack;
00068         ml_matrix xVarSlack;
00070         ml_matrix xRelSlack;
00072         const char *err;
00073 };
00074 
00075 // TODO: expand description
00087 class lp_problem
00088 {
00089 public:
00090         lp_problem(unsigned int nv=0);
00091         ~lp_problem() {}
00092     
00093         void add_constraint(const ml_matrix& A, const ml_matrix& b, const ml_int_array& cType);
00094         void add_vars(unsigned int nv, const ml_int_array *_vType=NULL, const ml_matrix *_lb=NULL, const ml_matrix *_ub=NULL, const ml_int_array *_absVal=NULL);
00095         void set_cost(const ml_int_array& kv, const ml_matrix& c, const ml_int_array& absVal);
00096         void relax(const ml_int_array& kRelax, const ml_matrix& cRelax);
00097         void var_bounds(ml_int_array kv, ml_matrix lb, ml_matrix ub);
00098         StatusReport solve(const char *solver = "glpk");
00099         void display(const char *msg = "") const;
00100     
00101 public:
00102         const ml_matrix& get_A() const { return lp_A; } // mostly for debugging
00103         const ml_matrix& get_b() const { return lp_b; } // mostly for debugging
00104         // TODO: description
00105         ml_int_array& set_kRelax(const ml_int_array& kRelax) { lp_kRelax = kRelax; return lp_kRelax; }
00106         // TODO: description
00107         ml_matrix& set_cRelax(const ml_matrix& cRelax) { lp_cRelax = cRelax; return lp_cRelax; }
00108     
00109 private:        
00110         //lp_problem(const lp_problem &right);
00111         //lp_problem& operator=(const lp_problem &that);        
00112     
00113 private:
00114         ml_matrix               lp_c;           // (n,1)   Cost vector
00115         ml_matrix               lp_A;           // (m,n)   Constraint matrix
00116         ml_matrix               lp_b;           // (m,1)   Constraint vector
00117         ml_matrix               lp_lb;          // (n,1)   Lower bounds (defaults to all 0 if [])
00118         ml_matrix               lp_ub;          // (n,1)   Upper bounds (defaults to all DBL_MAX if [])
00119         ml_int_array    lp_cType;       // (m,1)   Constraint types character array. Elements can be:
00120     //                  'L' lower bound   Ai*x >= bi
00121     //                  'U' lower bound   Ai*x >= bi
00122     //                  'S' equality      Ai*x == bi
00123         ml_int_array    lp_vType;       // (n,1)   Variable types character array. Elements can be:
00124     //                  'B' binary
00125     //                  'I' integer
00126     //                  'C' continuous
00127         ml_int_array    lp_absVal;      // Indices of vars. whose cost is prop. to its abs. val. ["v" is a non-negative integer that is less than or equal to "n"]
00128         ml_int_array    lp_kRelax;      // (n)
00129         ml_matrix               lp_cRelax;      // (n, 1) // TODO: n correct?
00130     
00131     
00132 public: 
00134         static void error(const char *str);
00136         static void msg(int num, const char *str);
00138         static ml_matrix diff(const ml_matrix &a);
00139 };
00140 
00141 
00142 #endif
00143 

Generated on Thu Aug 2 2012 11:08:35 for Spacecraft Control Framework by  doxygen 1.7.2