GAMSlinks  0.4
GamsBCH.hpp
Go to the documentation of this file.
1 // Copyright (C) GAMS Development 2007-2008
2 // All Rights Reserved.
3 // This code is published under the Common Public License.
4 //
5 // $Id: GamsBCH.hpp 510 2008-08-16 19:31:27Z stefan $
6 //
7 // Author: Stefan Vigerske
8 
9 #ifndef GAMSBCH_HPP_
10 #define GAMSBCH_HPP_
11 
12 #include "GAMSlinksConfig.h"
13 // from CoinUtils
14 #include "CoinPragma.hpp"
15 
16 #include <vector>
17 
18 #include "GamsHandler.hpp"
19 #include "GamsOptions.hpp"
20 #include "GamsDictionary.hpp"
21 
24 class GamsBCH {
25 public:
28  class Cut {
29  public:
31  double lb;
33  double ub;
35  int nnz;
37  int* indices;
39  double* coeff;
40 
44  Cut();
47  ~Cut();
48  };
49 
50 private:
52 
53  struct dictRec* dict;
54 
55  /* storage of size iolib.ncols for node relaxation solution */
56  double *node_x;
57  /* storage of size iolib.ncols for node lower bound */
58  double *node_lb;
59  /* storage of size iolib.ncols for node upper bound */
60  double *node_ub;
61 
64  double incumbent_value; /* objective function value of incumbent */
65  /* storage of size iolib.ncols for incumbent solution */
66  double *incumbent;
67  /* storage of size iolib.ncols for global lower bounds */
68  double *global_lb;
69  /* storage of size iolib.ncols for global upper bounds */
70  double *global_ub;
71 
72  bool userkeep; /* indicator for running gamskeep */
73 
74  int heurfreq; /* heuristic frequency */
76  int heurmult;
77  int heurfirst; /* heuristic at first nodes */
78  bool heurnewint; /* heuristic if new incumbent */
79  int heurobjfirst; /* heurisitc at first nodes if node obj is good */
80  char heurcall[1024]; /* command line minus gams for the heuristic */
81 
82  char cutcall[1024]; /* command line minus gams for the cut generation */
83  int cutfreq; /* cut frequency */
85  int cutmult;
86  int cutfirst; /* cuts at first nodes */
87  bool cutnewint; /* cuts if new incumbent */
88 
89  char incbcall[1024]; /* command line minus gams for the incumbent checking callback */
90  char incbicall[1024]; /* command line minus gams for the incumbent reporting callback */
91 
92  char userjobid[1024]; /* jobid added to gdxname, gdxnameinc, usergdxin, adds --userjobid to the calls and o and lf */
93 
94  char gdxname[1024]; /* GDX file name for solution read by the GAMS models */
95  char gdxnameinc[1024]; /* GDX file name for incumbent read by the GAMS models */
96  char usergdxin[1024]; /* GDX file name for reading stuff back */
97 
98  int ncalls; /* number of BCH calls performed */
99  int ncuts; /* number of cuts received */
100  int nsols; /* number of primal solutions received */
101 
102  int loglevel; /* amount of output printed by GamsBCH class */
103 
104  void init();
105 
110  int reportIncumbent();
111 public:
117  GamsBCH(GamsHandler& gams_, GamsDictionary& gamsdict, GamsOptions& opt);
123  GamsBCH(GamsHandler& gams_, GamsDictionary& gamsdict);
124 
127  ~GamsBCH();
128 
132  void setupParameters(GamsOptions& opt);
133 
137  void set_userjobid(const char* userjobid);
138  void set_usergdxname(const char* usergdxname, const char* usergdxprefix = NULL);
139  void set_usergdxnameinc(const char* usergdxnameinc, const char* usergdxprefix = NULL);
140  void set_usergdxin(const char* usergdxin_, const char* usergdxprefix = NULL);
141  void set_userkeep(bool userkeep_) { userkeep = userkeep_; }
142 
143  void set_usercutcall(const char* usercutcall);
144  void set_usercutfreq(int usercutfreq) { cutfreq=usercutfreq; }
145  void set_usercutinterval(int usercutinterval) { cutinterval=usercutinterval; }
146  void set_usercutmult(int usercutmult) { cutmult=usercutmult; }
147  void set_usercutfirst(int usercutfirst) { cutfirst=usercutfirst; }
148  void set_usercutnewint(bool usercutnewint) { cutnewint=usercutnewint; }
149 
150  void set_userheurcall(const char* userheurcall);
151  void set_userheurfreq(int userheurfreq) { heurfreq=userheurfreq; }
152  void set_userheurinterval(int userheurinterval) { heurinterval=userheurinterval; }
153  void set_userheurmult(int userheurmult) { heurmult=userheurmult; }
154  void set_userheurfirst(int userheurfirst) { heurfirst=userheurfirst; }
155  void set_userheurnewint(bool userheurnewint) { heurnewint=userheurnewint; }
156  void set_userheurobjfirst(int userheurobjfirst) { heurobjfirst=userheurobjfirst; }
157 
158  void set_userincbcall(const char* userincbcall);
159  void set_userincbicall(const char* userincbicall);
160 
161  const char* get_usercutcall() { return cutcall; }
162  bool get_usercutnewint() const { return cutnewint; }
163 
164  const char* get_userheurcall() { return heurcall; }
165  bool get_userheurnewint() const { return heurnewint; }
166 
170  void setLogLevel(int loglevel_) { loglevel=loglevel_; }
171 
174  int getNumCalls() const { return ncalls; }
177  int getNumCuts() const { return ncuts; }
180  int getNumSols() const { return nsols; }
181 
185  int getNumCols() const { return gams.getColCount(); }
186 
187  void printParameters() const;
188 
191  void setGlobalBounds(const double* lb_, const double* ub_);
192 
196  void setNodeSolution(const double* x_, double objval_, const double* lb_, const double* ub_);
197 
204  bool setIncumbentSolution(const double* x_, double objval_);
205 
209  bool doCuts();
210 
216  bool generateCuts(std::vector<Cut>& cuts);
217 
221  bool doHeuristic(double bestbnd, double curobj);
222 
228  bool runHeuristic(double* x, double& objvalue);
229 };
230 
231 #endif /*GAMSBCH_HPP_*/
const char * get_userheurcall()
Definition: GamsBCH.hpp:164
bool doCuts()
Returns true if generateCuts should be called, otherwise false.
void set_userincbicall(const char *userincbicall)
void set_usercutfirst(int usercutfirst)
Definition: GamsBCH.hpp:147
int nsols
Definition: GamsBCH.hpp:100
GamsHandler & gams
Definition: GamsBCH.hpp:51
Structure to store a Cut generated by a Gams BCH cut generator.
Definition: GamsBCH.hpp:28
bool cutnewint
Definition: GamsBCH.hpp:87
void set_userjobid(const char *userjobid)
Sets the users job id.
void set_usercutnewint(bool usercutnewint)
Definition: GamsBCH.hpp:148
double * global_lb
Definition: GamsBCH.hpp:68
int loglevel
Definition: GamsBCH.hpp:102
void set_usercutmult(int usercutmult)
Definition: GamsBCH.hpp:146
int getNumSols() const
Accumulated number of solutions.
Definition: GamsBCH.hpp:180
double * node_ub
Definition: GamsBCH.hpp:60
void set_userheurfirst(int userheurfirst)
Definition: GamsBCH.hpp:154
int getNumCalls() const
Accumulated number of BCH calls.
Definition: GamsBCH.hpp:174
const char * get_usercutcall()
Definition: GamsBCH.hpp:161
bool setIncumbentSolution(const double *x_, double objval_)
Informs BCH about the current incumbent.
int heurfreq
Definition: GamsBCH.hpp:74
int heurfirst
Definition: GamsBCH.hpp:77
void set_usergdxname(const char *usergdxname, const char *usergdxprefix=NULL)
bool get_usercutnewint() const
Definition: GamsBCH.hpp:162
int reportIncumbent()
Writes the incumbent to the file specified in gdxnameinc and calls the incumbent reporting callback...
void set_userheurfreq(int userheurfreq)
Definition: GamsBCH.hpp:151
double * coeff
Nonzero coefficients.
Definition: GamsBCH.hpp:39
bool userkeep
Definition: GamsBCH.hpp:72
bool runHeuristic(double *x, double &objvalue)
Calls the GAMS heuristic.
int ncalls
Definition: GamsBCH.hpp:98
int ncuts
Definition: GamsBCH.hpp:99
char cutcall[1024]
Definition: GamsBCH.hpp:82
virtual int getColCount() const =0
The number of columns in the possibly transformed problem space.
void set_userheurobjfirst(int userheurobjfirst)
Definition: GamsBCH.hpp:156
void set_userincbcall(const char *userincbcall)
int getNumCuts() const
Accumulated number of created cuts.
Definition: GamsBCH.hpp:177
void set_userheurmult(int userheurmult)
Definition: GamsBCH.hpp:153
int heurobjfirst
Definition: GamsBCH.hpp:79
int cutfirst
Definition: GamsBCH.hpp:86
double * node_lb
Definition: GamsBCH.hpp:58
char gdxname[1024]
Definition: GamsBCH.hpp:94
struct dictRec * dict
Definition: GamsBCH.hpp:53
bool get_userheurnewint() const
Definition: GamsBCH.hpp:165
int * indices
Indices of nonzero coefficients.
Definition: GamsBCH.hpp:37
void setupParameters(GamsOptions &opt)
Reads the BCH parameters from a GamsOptions object.
int heurinterval
Definition: GamsBCH.hpp:75
void set_userheurinterval(int userheurinterval)
Definition: GamsBCH.hpp:152
~GamsBCH()
Destructor.
Class to provide access to a GAMS dictionary.
void set_usercutcall(const char *usercutcall)
int cutinterval
Definition: GamsBCH.hpp:84
int cutmult
Definition: GamsBCH.hpp:85
char gdxnameinc[1024]
Definition: GamsBCH.hpp:95
int getNumCols() const
The number of columns expected by GamsBCH.
Definition: GamsBCH.hpp:185
Forwards requests for output, point transformations, dictionary files, and other things to a GAMS I/O...
Definition: GamsHandler.hpp:18
void set_userheurnewint(bool userheurnewint)
Definition: GamsBCH.hpp:155
int heurmult
Definition: GamsBCH.hpp:76
int nnz
Number of nonzero coefficients.
Definition: GamsBCH.hpp:35
double * global_ub
Definition: GamsBCH.hpp:70
double incumbent_value
Definition: GamsBCH.hpp:64
bool new_incumbent
Definition: GamsBCH.hpp:63
bool have_incumbent
Definition: GamsBCH.hpp:62
char usergdxin[1024]
Definition: GamsBCH.hpp:96
Cut()
Constructor.
void set_usercutfreq(int usercutfreq)
Definition: GamsBCH.hpp:144
void set_usergdxin(const char *usergdxin_, const char *usergdxprefix=NULL)
GamsBCH(GamsHandler &gams_, GamsDictionary &gamsdict, GamsOptions &opt)
Constructor that also reads the BCH parameters from a GamsOptions object.
double ub
Upper bound of cut.
Definition: GamsBCH.hpp:33
void set_usergdxnameinc(const char *usergdxnameinc, const char *usergdxprefix=NULL)
void set_userkeep(bool userkeep_)
Definition: GamsBCH.hpp:141
void setNodeSolution(const double *x_, double objval_, const double *lb_, const double *ub_)
Sets the solution and bounds of the current node.
void setLogLevel(int loglevel_)
Level of output created by GamsBCH handler.
Definition: GamsBCH.hpp:170
char userjobid[1024]
Definition: GamsBCH.hpp:92
void init()
void setGlobalBounds(const double *lb_, const double *ub_)
You should call this method after the constructor.
Class to handle the access to a GAMS options file.
Definition: GamsOptions.hpp:22
void set_usercutinterval(int usercutinterval)
Definition: GamsBCH.hpp:145
double * incumbent
Definition: GamsBCH.hpp:66
char incbcall[1024]
Definition: GamsBCH.hpp:89
bool doHeuristic(double bestbnd, double curobj)
Returns true if runHeuristic should be called, otherwise false.
double * node_x
Definition: GamsBCH.hpp:56
void set_userheurcall(const char *userheurcall)
char heurcall[1024]
Definition: GamsBCH.hpp:80
bool heurnewint
Definition: GamsBCH.hpp:78
int cutfreq
Definition: GamsBCH.hpp:83
char incbicall[1024]
Definition: GamsBCH.hpp:90
~Cut()
Destructor.
double lb
Lower bound of cut.
Definition: GamsBCH.hpp:31
bool generateCuts(std::vector< Cut > &cuts)
Calls the GAMS cut generator.
Interface to GAMS BCH facility.
Definition: GamsBCH.hpp:24
void printParameters() const