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 #include <string>
16 
17 #include "MP_expression.hpp"
18 #include "MP_constraint.hpp"
19 #include <CoinPackedVector.hpp>
20 class OsiSolverInterface;
21 
22 namespace flopc {
23 
24  class MP_variable;
25  class MP_index;
26  class MP_set;
27 
35  class Messenger {
36  public:
37  virtual void logMessage(int level, const char * const msg){}
38  friend class MP_model;
39  private:
40  virtual void constraintDebug(std::string name, const std::vector<Coef>& cfs) {}
41  virtual void objectiveDebug(const std::vector<Coef>& cfs) {}
42  virtual void statistics(int bm, int m, int bn, int n, int nz) {}
43  virtual void generationTime(double t) {}
44  protected:
45  virtual ~Messenger() {}
46  };
47 
51  class NormalMessenger : public Messenger {
52  friend class MP_model;
53  private:
54  virtual void statistics(int bm, int m, int bn, int n, int nz);
55  virtual void generationTime(double t);
56  };
57 
62  friend class MP_model;
63  private:
64  virtual void constraintDebug(std::string name, const std::vector<Coef>& cfs);
65  virtual void objectiveDebug(const std::vector<Coef>& cfs);
66  };
67 
89  class MP_model {
90  friend class MP_constraint;
91  public:
93  typedef enum {MINIMIZE=1, MAXIMIZE=-1} MP_direction;
94 
97  typedef enum {
114  } MP_status;
115 
117  MP_model(OsiSolverInterface* s, Messenger* m = new NormalMessenger);
118 
120  delete messenger;
121  }
122 
131  return mSolverState;
132  }
134  void silent() {
135  delete messenger;
136  messenger = new Messenger;
137  }
139  void verbose() {
140  delete messenger;
142  }
143 
145  void setSolver(OsiSolverInterface* s) {
146  Solver = s;
147  }
148 
150  OsiSolverInterface* operator->() {
151  return Solver;
152  }
153 
156 
160  void maximize();
164  void maximize(const MP_expression &obj);
168  void minimize();
172  void minimize(const MP_expression &obj);
173 
177  void minimize_max(MP_set& d, const MP_expression &obj);
178 
180  void setObjective(const MP_expression& o);
191  void attach(OsiSolverInterface *solver=NULL);
198  void detach();
211  const double* solution;
212  const double* reducedCost;
213  const double* rowPrice;
214  const double* rowActivity;
218  double getInfinity() const;
219 
221  void add(MP_variable* v);
223  void addRow(const Constraint& c);
224 
228  static MP_model &getDefaultModel();
232  static MP_model *getCurrentModel();
236  return messenger;
237  }
238  private:
239  typedef std::set<MP_variable* >::iterator varIt;
240  typedef std::set<MP_constraint* >::iterator conIt;
243  MP_model(const MP_model&);
244  MP_model& operator=(const MP_model&);
245 
247 
248 
249  static void assemble(std::vector<Coef>& v, std::vector<Coef>& av);
250  void add(MP_constraint* c);
252  std::set<MP_constraint *> Constraints;
253  std::set<MP_variable *> Variables;
254  public:
256  OsiSolverInterface* Solver;
257  private:
258  int m;
259  int n;
260  int nz;
261  int *Cst;
262  int *Clg;
263  int *Rnr;
264  double *Elm;
265  double *bl;
266  double *bu;
267  double *c;
268  double *l;
269  double *u;
271  };
272 
274  std::ostream &operator<<(std::ostream &os,
275  const MP_model::MP_status &condition);
277  std::ostream &operator<<(std::ostream &os,
278  const MP_model::MP_direction &direction);
279 
280 } // End of namespace flopc
281 #endif
MP_status getStatus() const
Returns the current status of the model-solver interaction. This method will return the current under...
Definition: MP_model.hpp:130
OsiSolverInterface * operator->()
allows access to the OsiSolverInterface *
Definition: MP_model.hpp:150
Symbolic representation of a linear expression.This is one of the main public interface classes...
Messenger * messenger
Definition: MP_model.hpp:246
MP_model(OsiSolverInterface *s, Messenger *m=new NormalMessenger)
Constructs an MP_model from an OsiSolverInterface *.
Definition: MP_model.cpp:61
std::ostream & operator<<(std::ostream &os, const MP_model::MP_status &condition)
allows print of result from call to solve();
Definition: MP_model.cpp:475
static void assemble(std::vector< Coef > &v, std::vector< Coef > &av)
Definition: MP_model.cpp:159
static MP_model * getCurrentModel()
Definition: MP_model.cpp:26
virtual ~Messenger()
Definition: MP_model.hpp:45
double getInfinity() const
Definition: MP_model.cpp:79
std::set< MP_constraint * >::iterator conIt
Definition: MP_model.hpp:240
Messenger * getMessenger()
Definition: MP_model.hpp:235
MP_model & add(MP_constraint &c)
Adds a constrataint block to the model.
Definition: MP_model.cpp:68
std::set< MP_variable * >::iterator varIt
Definition: MP_model.hpp:239
Inteface for hooking up to internal flopc++ message handling.In more advanced use of FlopC++...
Definition: MP_model.hpp:35
virtual void statistics(int bm, int m, int bn, int n, int nz)
Definition: MP_model.cpp:28
const double * rowPrice
Definition: MP_model.hpp:213
virtual void constraintDebug(std::string name, const std::vector< Coef > &cfs)
Definition: MP_model.hpp:40
std::set< MP_variable * > Variables
Definition: MP_model.hpp:253
virtual void generationTime(double t)
Definition: MP_model.hpp:43
MP_model & operator=(const MP_model &)
void setObjective(const MP_expression &o)
sets the &quot;current objective&quot; to the parameter o
Definition: MP_model.cpp:133
void addRow(const Constraint &c)
Adds a constraint to the MP_model.
Definition: MP_model.cpp:93
const double * rowActivity
Definition: MP_model.hpp:214
MP_expression Objective
Definition: MP_model.hpp:251
static MP_model * current_model
Definition: MP_model.hpp:242
double * Elm
Definition: MP_model.hpp:264
void verbose()
used to help understanding and debugging FlopC++&#39;s behavior.
Definition: MP_model.hpp:139
MP_status mSolverState
Definition: MP_model.hpp:270
A solver is attached, but not yet solved.
Definition: MP_model.hpp:111
MP_status
Reflects the state of the solution from solve()
Definition: MP_model.hpp:97
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:89
virtual void statistics(int bm, int m, int bn, int n, int nz)
Definition: MP_model.hpp:42
OsiSolverInterface * Solver
Definition: MP_model.hpp:256
if solve is called and solver finds model primal infeasible.
Definition: MP_model.hpp:101
MP_model::MP_status solve(const MP_model::MP_direction &dir)
Definition: MP_model.cpp:421
void silent()
used to silence FlopC++
Definition: MP_model.hpp:134
void minimize_max(MP_set &d, const MP_expression &obj)
Definition: MP_model.cpp:137
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:75
if solve is called and solver finds the model dual infeasible.
Definition: MP_model.hpp:103
Representation of a set for indexing into some other construct.This is one of the main public interfa...
Definition: MP_set.hpp:78
const double * reducedCost
Definition: MP_model.hpp:212
virtual void objectiveDebug(const std::vector< Coef > &cfs)
Definition: MP_model.cpp:51
virtual void constraintDebug(std::string name, const std::vector< Coef > &cfs)
Definition: MP_model.cpp:40
const double * solution
Definition: MP_model.hpp:211
static MP_model & default_model
Definition: MP_model.hpp:241
static MP_model & getDefaultModel()
Definition: MP_model.cpp:25
No solver is attached.
Definition: MP_model.hpp:113
if the solve method is called and the optimal solution found.
Definition: MP_model.hpp:99
void setSolver(OsiSolverInterface *s)
allows for replacement of the solver used.
Definition: MP_model.hpp:145
virtual void logMessage(int level, const char *const msg)
Definition: MP_model.hpp:37
MP_direction
used when calling the solve() method.
Definition: MP_model.hpp:93
virtual void objectiveDebug(const std::vector< Coef > &cfs)
Definition: MP_model.hpp:41
void detach()
detaches an OsiSolverInterface object from the model. In essence, this will clean up any intermediate...
Definition: MP_model.cpp:413
void attach(OsiSolverInterface *solver=NULL)
attaches the symantic representation of a model and data to a particular OsiSolverInterface ...
Definition: MP_model.cpp:219
std::set< MP_constraint * > Constraints
Definition: MP_model.hpp:252
virtual void generationTime(double t)
Definition: MP_model.cpp:36
Semantic representation of a linear constraint.This is one of the main public interface classes...