MP_model.hpp

Go to the documentation of this file.
00001 // ******************** FlopCpp **********************************************
00002 // File: MP_model.hpp
00003 // $Id$
00004 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
00005 // Copyright (C) 2003 Tim Helge Hultberg
00006 // All Rights Reserved.
00007 // ****************************************************************************
00008 
00009 #ifndef _MP_model_hpp_
00010 #define _MP_model_hpp_
00011 
00012 #include <ostream>
00013 #include <vector>
00014 #include <set>
00015 using std::vector;
00016 using std::set;
00017 
00018 #include "MP_expression.hpp"
00019 #include "MP_constraint.hpp"
00020 #include <CoinPackedVector.hpp>
00021 class OsiSolverInterface;
00022 
00023 namespace flopc {
00024 
00025   class MP_variable;
00026   class MP_index;
00027   class MP_set;
00028 
00036   class Messenger {
00037   public:
00038     virtual void logMessage(int level, const char * const msg){}
00039     friend class MP_model;
00040   private:
00041     virtual void constraintDebug(string name, const vector<Coef>& cfs) {}
00042     virtual void objectiveDebug(const vector<Coef>& cfs) {}
00043     virtual void statistics(int bm, int m, int bn, int n, int nz) {}
00044     virtual void generationTime(double t) {}
00045   protected:
00046     virtual ~Messenger() {}
00047   };
00048 
00052   class NormalMessenger : public Messenger {
00053     friend class MP_model;
00054   private:
00055     virtual void statistics(int bm, int m, int bn, int n, int nz);
00056     virtual void generationTime(double t);
00057   };
00058 
00062   class VerboseMessenger : public NormalMessenger {
00063     friend class MP_model;
00064   private:
00065     virtual void constraintDebug(string name, const vector<Coef>& cfs);
00066     virtual void objectiveDebug(const vector<Coef>& cfs);
00067   };
00068 
00090   class MP_model {
00091     friend class MP_constraint;
00092   public:
00094     typedef enum {MINIMIZE=1, MAXIMIZE=-1} MP_direction;
00095 
00098     typedef enum {  
00100       OPTIMAL, 
00102       PRIMAL_INFEASIBLE, 
00104       DUAL_INFEASIBLE, 
00107       ABANDONED,
00110       SOLVER_ONLY,
00112       ATTACHED,
00114       DETACHED
00115     } MP_status;
00116 
00118     MP_model(OsiSolverInterface* s, Messenger* m = new NormalMessenger);
00119 
00120     ~MP_model();
00121 
00129     MP_status getStatus()const {
00130       return mSolverState;
00131     }
00133     void silent() {
00134       delete messenger;
00135       messenger = new Messenger;
00136     }
00138     void verbose() {
00139       delete messenger;
00140       messenger = new VerboseMessenger;
00141     }
00142 
00144     void setSolver(OsiSolverInterface* s) {
00145       Solver = s;
00146     }
00147 
00149     OsiSolverInterface* operator->() {
00150       return Solver;
00151     }
00152 
00154     MP_model& add(MP_constraint& c);
00155 
00159     void maximize();
00163     void maximize(const MP_expression &obj);
00167     void minimize();
00171     void minimize(const MP_expression &obj);
00172    
00176     void minimize_max(MP_set& d, const MP_expression &obj);
00177 
00179     void setObjective(const MP_expression& o);
00190     void attach(OsiSolverInterface *solver=NULL);
00197     void detach();
00205     MP_model::MP_status solve(const MP_model::MP_direction &dir);
00210     const double* solution;
00211     const double* reducedCost;
00212     const double* rowPrice;
00213     const double* rowActivity;
00217     double getInfinity() const;
00218 
00220     void add(MP_variable* v);
00222     void addRow(const Constraint& c); 
00223 
00227     static MP_model &getDefaultModel();
00231     static MP_model *getCurrentModel();
00234     Messenger *getMessenger(){ 
00235       return messenger;
00236     }
00237   private:
00238     typedef std::set<MP_variable* >::iterator varIt;
00239     typedef std::set<MP_constraint* >::iterator conIt;
00240     static MP_model& default_model;
00241     static MP_model* current_model;
00242     MP_model(const MP_model&);
00243     MP_model& operator=(const MP_model&);
00244 
00245     Messenger* messenger;
00246    
00247     
00248     static void assemble(vector<Coef>& v, vector<Coef>& av);
00249     void add(MP_constraint* c);
00250     MP_expression Objective;
00251     set<MP_constraint *> Constraints;
00252     set<MP_variable *> Variables;
00253   public:
00255     OsiSolverInterface* Solver; 
00256   private:
00257     int m;
00258     int n;
00259     int nz;
00260     int *Cst;
00261     int *Clg;
00262     int *Rnr;
00263     double *Elm;
00264     double *bl;
00265     double *bu;
00266     double *c;
00267     double *l;
00268     double *u;
00269     MP_status mSolverState;
00270   };
00271     
00273   std::ostream &operator<<(std::ostream &os, 
00274                            const MP_model::MP_status &condition);
00276   std::ostream &operator<<(std::ostream &os, 
00277                            const MP_model::MP_direction &direction);
00278 
00279 } // End of namespace flopc
00280 #endif

Generated on Fri May 16 00:25:12 2008 for FLOPC++ by  doxygen 1.4.7