- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/FlopCpp/src/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 #include <string>
    00016
    00017 #include "MP_expression.hpp"
    00018 #include "MP_constraint.hpp"
    00019 #include <CoinPackedVector.hpp>
    00020 class OsiSolverInterface;
    00021
    00022 namespace flopc {
    00023
    00024     class MP_variable;
    00025     class MP_index;
    00026     class MP_set;
    00027
    00035     class Messenger {
    00036     public:
    00037         virtual void logMessage(int level, const char * const msg){}
    00038         friend class MP_model;
    00039     private:
    00040         virtual void constraintDebug(std::string name, const std::vector<Coef>& cfs) {}
    00041         virtual void objectiveDebug(const std::vector<Coef>& cfs) {}
    00042         virtual void statistics(int bm, int m, int bn, int n, int nz) {}
    00043         virtual void generationTime(double t) {}
    00044     protected:
    00045         virtual ~Messenger() {}
    00046     };
    00047
    00051     class NormalMessenger : public Messenger {
    00052         friend class MP_model;
    00053     private:
    00054         virtual void statistics(int bm, int m, int bn, int n, int nz);
    00055         virtual void generationTime(double t);
    00056     };
    00057
    00061     class VerboseMessenger : public NormalMessenger {
    00062         friend class MP_model;
    00063     private:
    00064         virtual void constraintDebug(std::string name, const std::vector<Coef>& cfs);
    00065         virtual void objectiveDebug(const std::vector<Coef>& cfs);
    00066     };
    00067
    00089     class MP_model {
    00090         friend class MP_constraint;
    00091     public:
    00093         typedef enum {MINIMIZE=1, MAXIMIZE=-1} MP_direction;
    00094
    00097         typedef enum {
    00099             OPTIMAL,
    00101             PRIMAL_INFEASIBLE,
    00103             DUAL_INFEASIBLE,
    00106             ABANDONED,
    00109             SOLVER_ONLY,
    00111             ATTACHED,
    00113             DETACHED
    00114         } MP_status;
    00115
    00117         MP_model(OsiSolverInterface* s, Messenger* m = new NormalMessenger);
    00118
    00119         ~MP_model() {
    00120             delete messenger;
    00121         }
    00122
    00130         MP_status getStatus()const {
    00131             return mSolverState;
    00132         }
    00134         void silent() {
    00135             delete messenger;
    00136             messenger = new Messenger;
    00137         }
    00139         void verbose() {
    00140             delete messenger;
    00141             messenger = new VerboseMessenger;
    00142         }
    00143
    00145         void setSolver(OsiSolverInterface* s) {
    00146             Solver = s;
    00147         }
    00148
    00150         OsiSolverInterface* operator->() {
    00151             return Solver;
    00152         }
    00153
    00155         MP_model& add(MP_constraint& c);
    00156
    00160         void maximize();
    00164         void maximize(const MP_expression &obj);
    00168         void minimize();
    00172         void minimize(const MP_expression &obj);
    00173
    00177         void minimize_max(MP_set& d, const MP_expression &obj);
    00178
    00180         void setObjective(const MP_expression& o);
    00191         void attach(OsiSolverInterface *solver=NULL);
    00198         void detach();
    00206         MP_model::MP_status solve(const MP_model::MP_direction &dir);
    00211         const double* solution;
    00212         const double* reducedCost;
    00213         const double* rowPrice;
    00214         const double* rowActivity;
    00218         double getInfinity() const;
    00219
    00221         void add(MP_variable* v);
    00223         void addRow(const Constraint& c);
    00224
    00228         static MP_model &getDefaultModel();
    00232         static MP_model *getCurrentModel();
    00235         Messenger *getMessenger(){
    00236             return messenger;
    00237         }
    00238     private:
    00239         typedef std::set<MP_variable* >::iterator varIt;
    00240         typedef std::set<MP_constraint* >::iterator conIt;
    00241         static MP_model& default_model;
    00242         static MP_model* current_model;
    00243         MP_model(const MP_model&);
    00244         MP_model& operator=(const MP_model&);
    00245
    00246         Messenger* messenger;
    00247
    00248
    00249         static void assemble(std::vector<Coef>& v, std::vector<Coef>& av);
    00250         void add(MP_constraint* c);
    00251         MP_expression Objective;
    00252         std::set<MP_constraint *> Constraints;
    00253         std::set<MP_variable *> Variables;
    00254     public:
    00256         OsiSolverInterface* Solver;
    00257     private:
    00258         int m;
    00259         int n;
    00260         int nz;
    00261         int *Cst;
    00262         int *Clg;
    00263         int *Rnr;
    00264         double *Elm;
    00265         double *bl;
    00266         double *bu;
    00267         double *c;
    00268         double *l;
    00269         double *u;
    00270         MP_status mSolverState;
    00271     };
    00272
    00274     std::ostream &operator<<(std::ostream &os,
    00275                              const MP_model::MP_status &condition);
    00277     std::ostream &operator<<(std::ostream &os,
    00278                              const MP_model::MP_direction &direction);
    00279
    00280 } // End of namespace flopc
    00281 #endif