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
No solver is attached.
Definition: MP_model.hpp:114
void attach(OsiSolverInterface *solver=0)
attaches the symantic representation of a model and data to a particular OsiSolverInterface ...
Definition: MP_model.cpp:217
static void assemble(vector< MP::Coef > &v, vector< MP::Coef > &av)
Definition: MP_model.cpp:157
MP_status getStatus() const
Returns the current status of the model-solver interaction. This method will return the current under...
Definition: MP_model.hpp:129
OsiSolverInterface * operator->()
allows access to the OsiSolverInterface *
Definition: MP_model.hpp:149
MP_model & add(MP_constraint &constraint)
Adds a constrataint block to the model.
Definition: MP_model.cpp:77
virtual void constraintDebug(string name, const vector< MP::Coef > &cfs)
Definition: MP_model.hpp:41
virtual void constraintDebug(string name, const vector< MP::Coef > &cfs)
Definition: MP_model.cpp:41
Symbolic representation of a linear expression.This is one of the main public interface classes...
Messenger * messenger
Definition: MP_model.hpp:241
MP_model(OsiSolverInterface *s, Messenger *m=new NormalMessenger)
Constructs an MP_model from an OsiSolverInterface *.
Definition: MP_model.cpp:62
std::ostream & operator<<(std::ostream &os, const MP_model::MP_status &condition)
allows print of result from call to solve();
Definition: MP_model.cpp:461
static MP_model * getCurrentModel()
Definition: MP_model.cpp:27
virtual ~Messenger()
Definition: MP_model.hpp:46
double getInfinity() const
Definition: MP_model.cpp:90
std::set< MP_constraint * >::iterator conIt
Definition: MP_model.hpp:235
Messenger * getMessenger()
Definition: MP_model.hpp:230
std::set< MP_variable * >::iterator varIt
Definition: MP_model.hpp:234
if the solve method is called and the optimal solution found.
Definition: MP_model.hpp:100
Inteface for hooking up to internal flopc++ message handling.In more advanced use of FlopC++...
Definition: MP_model.hpp:36
virtual void statistics(int bm, int m, int bn, int n, int nz)
Definition: MP_model.cpp:29
virtual void generationTime(double t)
Definition: MP_model.hpp:44
MP_model & operator=(const MP_model &)
void setObjective(const MP_expression &o)
sets the "current objective" to the parameter o
Definition: MP_model.cpp:144
MP_direction
used when calling the solve() method.
Definition: MP_model.hpp:94
MP_expression Objective
Definition: MP_model.hpp:246
static MP_model * current_model
Definition: MP_model.hpp:237
double * Elm
Definition: MP_model.hpp:259
void addRow(const Constraint &constraint)
Adds a constraint to the MP_model.
Definition: MP_model.cpp:104
void verbose()
used to help understanding and debugging FlopC++'s behavior.
Definition: MP_model.hpp:138
MP_status mSolverState
Definition: MP_model.hpp:265
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:90
virtual void statistics(int bm, int m, int bn, int n, int nz)
Definition: MP_model.hpp:43
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
OsiSolverInterface * Solver
Definition: MP_model.hpp:251
MP_model::MP_status solve(const MP_model::MP_direction &dir)
Definition: MP_model.cpp:411
set< MP_variable * > Variables
Definition: MP_model.hpp:248
void silent()
used to silence FlopC++
Definition: MP_model.hpp:133
if solve is called and solver finds the model dual infeasible.
Definition: MP_model.hpp:104
if solve is called and solver finds model primal infeasible.
Definition: MP_model.hpp:102
set< MP_constraint * > Constraints
Definition: MP_model.hpp:247
void minimize_max(MP_set &d, const MP_expression &obj)
Definition: MP_model.cpp:148
Symantic representation of a variable.This is one of the main public interface classes. It should be directly declared by clients of the FlopC++. The parametersof construction are MP_set s which specify the indexes over which the variable is defined.
Definition: MP_variable.hpp:35
Representation of a set for indexing into some other construct.This is one of the main public interfa...
Definition: MP_set.hpp:79
A solver is attached, but not yet solved.
Definition: MP_model.hpp:112
virtual void objectiveDebug(const vector< MP::Coef > &cfs)
Definition: MP_model.hpp:42
static MP_model & default_model
Definition: MP_model.hpp:236
static MP_model & getDefaultModel()
Definition: MP_model.cpp:26
virtual void objectiveDebug(const vector< MP::Coef > &cfs)
Definition: MP_model.cpp:52
MP_status
Reflects the state of the solution from solve()
Definition: MP_model.hpp:98
void setSolver(OsiSolverInterface *s)
allows for replacement of the solver used.
Definition: MP_model.hpp:144
virtual void logMessage(int level, const char *const msg)
Definition: MP_model.hpp:38
void detach()
detaches an OsiSolverInterface object from the model. In essence, this will clean up any intermediate...
Definition: MP_model.cpp:404
virtual void generationTime(double t)
Definition: MP_model.cpp:37
Semantic representation of a linear constraint.This is one of the main public interface classes...