FLOPC++
MP_model.hpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_model.hpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 // ****************************************************************************
8 
9 #ifndef _MP_model_hpp_
10 #define _MP_model_hpp_
11 
12 #include <ostream>
13 #include <vector>
14 #include <set>
15 using std::vector;
16 using std::set;
17 
18 #include "MP_expression.hpp"
19 #include "MP_constraint.hpp"
20 #include <CoinPackedVector.hpp>
21 class OsiSolverInterface;
22 
23 namespace flopc {
24 
25  class MP_variable;
26  class MP_index;
27  class MP_set;
28 
36  class Messenger {
37  public:
38  virtual void logMessage(int level, const char * const msg){}
39  friend class MP_model;
40  private:
41  virtual void constraintDebug(string name, const vector<MP::Coef>& cfs) {}
42  virtual void objectiveDebug(const vector<MP::Coef>& cfs) {}
43  virtual void statistics(int bm, int m, int bn, int n, int nz) {}
44  virtual void generationTime(double t) {}
45  protected:
46  virtual ~Messenger() {}
47  };
48 
52  class NormalMessenger : public Messenger {
53  friend class MP_model;
54  private:
55  virtual void statistics(int bm, int m, int bn, int n, int nz);
56  virtual void generationTime(double t);
57  };
58 
63  friend class MP_model;
64  private:
65  virtual void constraintDebug(string name, const vector<MP::Coef>& cfs);
66  virtual void objectiveDebug(const vector<MP::Coef>& cfs);
67  };
68 
90  class MP_model {
91  friend class MP_constraint;
92  public:
94  typedef enum {MINIMIZE=1, MAXIMIZE=-1} MP_direction;
95 
98  typedef enum {
115  } MP_status;
116 
118  MP_model(OsiSolverInterface* s, Messenger* m = new NormalMessenger);
119 
120  ~MP_model();
121 
130  return mSolverState;
131  }
133  void silent() {
134  delete messenger;
135  messenger = new Messenger;
136  }
138  void verbose() {
139  delete messenger;
141  }
142 
144  void setSolver(OsiSolverInterface* s) {
145  Solver = s;
146  }
147 
149  OsiSolverInterface* operator->() {
150  return Solver;
151  }
152 
154  MP_model& add(MP_constraint& constraint);
155 
159  void maximize();
163  void maximize(const MP_expression &obj);
167  void minimize();
171  void minimize(const MP_expression &obj);
172 
176  void minimize_max(MP_set& d, const MP_expression &obj);
177 
179  void setObjective(const MP_expression& o);
190  void attach(OsiSolverInterface *solver = 0);
197  void detach();
213  double getInfinity() const;
214 
216  void add(MP_variable* v);
218  void addRow(const Constraint& constraint);
219 
223  static MP_model &getDefaultModel();
227  static MP_model *getCurrentModel();
231  return messenger;
232  }
233  private:
234  typedef std::set<MP_variable* >::iterator varIt;
235  typedef std::set<MP_constraint* >::iterator conIt;
238  MP_model(const MP_model&);
239  MP_model& operator=(const MP_model&);
240 
242 
243 
244  static void assemble(vector<MP::Coef>& v, vector<MP::Coef>& av);
245  void add(MP_constraint* constraint);
247  set<MP_constraint *> Constraints;
248  set<MP_variable *> Variables;
249  public:
251  OsiSolverInterface* Solver;
252  private:
253  int m;
254  int n;
255  int nz;
256  int *Cst;
257  int *Clg;
258  int *Rnr;
259  double *Elm;
260  double *bl;
261  double *bu;
262  double *c;
263  double *l;
264  double *u;
266 
267  };
268 
270  std::ostream &operator<<(std::ostream &os,
271  const MP_model::MP_status &condition);
273  std::ostream &operator<<(std::ostream &os,
274  const MP_model::MP_direction &direction);
275 
276 } // End of namespace flopc
277 #endif