GAMSlinks  0.4
GamsModel.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006-2008 GAMS Development and others
2 // All Rights Reserved.
3 // This code is published under the Common Public License.
4 //
5 // $Id: GamsModel.hpp 510 2008-08-16 19:31:27Z stefan $
6 //
7 // Authors: Michael Bussieck, Stefan Vigerske
8 
9 #ifndef __GAMSMODEL_HPP__
10 #define __GAMSMODEL_HPP__
11 
12 #include "GAMSlinksConfig.h"
13 // from CoinUtils
14 #include "CoinPragma.hpp"
15 
16 extern "C" struct dictRec;
17 
21 class GamsModel {
22 public:
25  enum BasisStatus {
31  };
32 
36  VarNormal = 0,
41  };
42 
45  enum RowStatus {
46  RowNormal = 0,
51  };
52 
55  enum SolverStatus {
71  };
72 
75  enum ModelStatus {
97  };
98 
101  enum PrintMask {
102  LogMask = 0x1,
103  StatusMask = 0x2,
106  };
107 
108 
114  GamsModel(const char *cntrfile);
115 
118  ~GamsModel();
119 
122  void readMatrix();
123 
133  void PrintOut(PrintMask mask, const char *msg);
134 
137  int getSysOut();
144  void TimerStart();
147  double SecondsSinceStart();
153  const char* getSystemDir();
154 
157  double getMInfinity() const;
160  double getPInfinity() const;
163  void setInfinity(const double& SolverMInf, const double& SolverPInf);
164 
167  bool isReformulated() const { return isReform_; }
168 
174  bool isLP() const;
177  inline int nCols() const { return nCols_; }
180  inline int nDCols() const { return nDCols_; }
183  inline int nSOS1() const { return nSOS1_; }
186  inline int nSOS2() const { return nSOS2_; }
189  inline int nSemiContinuous() const { return nSemiCon_; }
192  inline int nRows() const { return nRows_; }
195  inline int nNnz() const { return nNnz_; }
196 
199  inline double *ColLb() { return ColLb_; }
202  inline double *ColUb() { return ColUb_; }
205  inline bool *ColDisc() { return ColDisc_; }
213  inline int *SOSIndicator() { return SOSIndicator_; }
218  inline bool *ColSemiContinuous() { return ColSemiCon_; }
221  inline double *ColLevel() { return ColLevel_; }
224  inline double *ColMargin() { return ColMargin_; }
227  inline int *ColBasis() { return ColBasis_; }
232  inline double *ColPriority() { return ColPriority_; }
236  inline double *ColScale() { return ColScale_; }
237 
246  inline char *RowSense() { return RowSense_; }
249  inline double *RowRhs() { return RowRhs_; }
252  inline double *RowLevel() { return RowLevel_; }
255  inline double *RowMargin() { return RowMargin_; }
258  inline int *RowBasis() { return RowBasis_; }
262  inline double *RowScale() { return RowScale_; }
263 
266  inline double *ObjCoef() { return ObjCoef_; }
269  inline double ObjConstant() { return ObjRhs_; }
273  inline double ObjSense() const { return ObjSense_; }
278  inline double ObjScale() const { return ObjScale_; }
279 
282  inline int *matStart() { return matStart_; }
285  inline int *matRowIdx() { return matRowIdx_; }
288  inline double *matValue() { return matValue_; }
294  int matSqueezeZeros();
305 
310  void setStatus(const SolverStatus& newSolverStatus,
311  const ModelStatus& newModelStatus);
312 
316  inline void setIterUsed(const int IterUsed) { IterUsed_ = IterUsed; }
320  inline void setResUsed(const double ResUsed) { ResUsed_ = ResUsed; }
324  inline void setNodesUsed(const int NodesUsed) { NodeUsed_ = NodesUsed; }
328  inline void setObjVal(const double ObjVal) { ObjVal_ = ObjVal; }
332  inline void setObjBound(const double ObjBound) { ObjBound_ = ObjBound; }
335  inline double getObjVal() { return ObjVal_; }
338  inline double getResUsed() { return ResUsed_; }
339 
343  inline int *ColIndicator() { return ColIndicator_; }
347  inline int *RowIndicator() { return RowIndicator_; }
348 
354  void setSolution(const double *ColLevel=0, const double *ColMargin=0,
355  const int *ColBasis=0, const int *ColIndicator=0,
356  const double *RowLevel=0, const double *RowMargin=0,
357  const int *RowBasis=0, const int *RowIndicator=0);
364  double getResLim();
367  int getIterLim(); // Iteration limit for model run
370  int getNodeLim();
376  int getGamsInteger(int nr);
383  int getGamsInteger(int intnr, int bitnr);
386  double getOptCA();
389  double getOptCR();
392  double getCheat();
395  double getCutOff();
398  bool getScaleOption();
401  bool getPriorityOption();
402 
406  const char* getOptionfile();
411 // inline bool haveNames() { return dict; }
412 
413 private:
414  int nCols_; // # columns
415  int nDCols_; // # discrete columns
416  int nSOS1_; // # SOS type 1
417  int nSOS2_; // # SOS type 2
418  int nSemiCon_; // # semicontinuous or semicont. integer columns
419  int nRows_; // # rows
420  int nNnz_; // # non zeros
421 
422  double startTime_; // Start time
423 
424  double *ColLb_; // lower bound for columns
425  double *ColUb_; // upper bound for columns
426  bool *ColDisc_; // indicator for discrete columns: discrete (true) or not (false)
427  int *SOSIndicator_; // indicator for SOS of type 1 and 2
428  bool *ColSemiCon_; // indicator for semicontinuous columns: semicon. (true) or not (false)
429  double *ColLevel_; // values of column variables
430  double *ColMargin_; // marginal values = duals
431  int *ColBasis_; // column basis status
432  double *ColPriority_; // branching priority
433  double *ColScale_; // scaling parameter
434  int *ColIndicator_; // indicator for feasibility
435 
436  char *RowSense_; // sense of row
437  double *RowRhs_; // right hand side
438  double *RowScale_; // scaling parameters
439  double *RowLevel_; // values of rows = row activity
440  double *RowMargin_; // marginal values = duals
441  int *RowBasis_; // Row basis status
442  int *RowIndicator_; // indicator for feasibility
443 
444  double ObjSense_; // objective sense 1=min, -1=max
445  double *ObjCoef_; // Dense objective function
446  double ObjRhs_; // constant in objective function
447  double zCoef_; // coefficient of objective variable
448  double ObjScale_; // scale value of objective variable
449  int isReform_; // reformulated objective function
450 
451  int *matStart_; // matrix start of column
452  int *matRowIdx_; // matrix row index
453  double *matValue_; // matrix values
454 
455  void Allocate();
456 
457  double ObjVal_;
458  double ObjBound_;
459  double ResUsed_;
461  int DomUsed_;
463 
466 };
467 
468 #endif // __GAMSMODEL_HPP__
double startTime_
Definition: GamsModel.hpp:422
const char * getSystemDir()
Name of GAMS System directory.
double getMInfinity() const
Value used by GAMS for minus infinity.
double * ColScale_
Definition: GamsModel.hpp:433
int nNnz() const
The number of nonzeros in the matrix of the model.
Definition: GamsModel.hpp:195
ModelStatus
GAMS Model status codes.
Definition: GamsModel.hpp:75
int * matRowIdx_
Definition: GamsModel.hpp:452
double * RowMargin_
Definition: GamsModel.hpp:440
Representation of a mixed-integer linear GAMS model read in from GAMS iolib.
Definition: GamsModel.hpp:21
int * RowIndicator()
Storage for row indicators.
Definition: GamsModel.hpp:347
double * ColMargin_
Definition: GamsModel.hpp:430
const char * getOptionfile()
The name of the option file.
double getResUsed()
Gives the stored number of seconds used.
Definition: GamsModel.hpp:338
int getGamsInteger(int nr)
GAMS Parameter: Integers 1 to 5.
int NodeUsed_
Definition: GamsModel.hpp:462
double getCutOff()
GAMS Parmeter: Implied upper/lower bound on objective function.
int IterUsed_
Definition: GamsModel.hpp:460
double * ColLb()
The column lower bounds.
Definition: GamsModel.hpp:199
int * RowBasis()
Initial basis status and storage for the solution basis status of the rows.
Definition: GamsModel.hpp:258
double ObjScale_
Definition: GamsModel.hpp:448
double * RowScale()
Scaling parameters for rows.
Definition: GamsModel.hpp:262
void TimerStart()
Starts the GAMS timer.
double ObjSense_
Definition: GamsModel.hpp:444
char * RowSense()
The sense of the rows.
Definition: GamsModel.hpp:246
void readMatrix()
Reads the LP from the GAMS matrix file and stores it into the data structures of this class...
VariableStatus
Column status indicator used in GAMS.
Definition: GamsModel.hpp:35
int * ColIndicator()
Storage for column indicators.
Definition: GamsModel.hpp:343
SolverStatus SolverStatus_
Definition: GamsModel.hpp:464
int nDCols() const
The number of discrete columns in the model.
Definition: GamsModel.hpp:180
ModelStatus getModelStatus()
The current GAMS model status.
GamsModel(const char *cntrfile)
Constructor.
bool isLP() const
Indicates whether we represent an LP or not.
int * matStart()
The column starts for the problem matrix.
Definition: GamsModel.hpp:282
int isReform_
Definition: GamsModel.hpp:449
int getNodeLim()
GAMS Parameter: Node limit for model run if using a branch-and-bound algorithm.
double * RowRhs()
The right-hand-side of the rows.
Definition: GamsModel.hpp:249
double * matValue()
The values for the problem matrix.
Definition: GamsModel.hpp:288
int * SOSIndicator()
The special ordered sets indicator.
Definition: GamsModel.hpp:213
double ObjBound_
Definition: GamsModel.hpp:458
SolverStatus
GAMS Solver status codes.
Definition: GamsModel.hpp:55
double ObjSense() const
The sense of the objective function or optimization, respectively.
Definition: GamsModel.hpp:273
ModelStatus ModelStatus_
Definition: GamsModel.hpp:465
double getOptCA()
GAMS Parameter: Allowed absolute difference between incumbent solution and best bound (for MIPs)...
double * ColUb()
The column upper bounds.
Definition: GamsModel.hpp:202
double ObjScale() const
Scaling parameter for objective function.
Definition: GamsModel.hpp:278
SolverStatus getSolverStatus()
The current GAMS solver status.
int DomUsed_
Definition: GamsModel.hpp:461
int * ColIndicator_
Definition: GamsModel.hpp:434
double * ColLb_
Definition: GamsModel.hpp:424
int nRows() const
The number of rows in the model.
Definition: GamsModel.hpp:192
void setObjBound(const double ObjBound)
Sets an bound (estimate) on the optimal value.
Definition: GamsModel.hpp:332
int * SOSIndicator_
Definition: GamsModel.hpp:427
double getPInfinity() const
Value used by GAMS for plus infinity.
int nSOS1() const
The number of special ordered sets of type 1 in the model.
Definition: GamsModel.hpp:183
double * RowRhs_
Definition: GamsModel.hpp:437
double SecondsSinceStart()
The number of seconds since the GAMS timer was started.
void PrintOut(PrintMask mask, const char *msg)
Log- and Statusfile print function.
double * matValue_
Definition: GamsModel.hpp:453
int nCols() const
The number of columns in the model.
Definition: GamsModel.hpp:177
int nCols_
Indicates whether we have column and row names.
Definition: GamsModel.hpp:414
int getSysOut()
If SysOut is set, the solver should give plenty off output.
int * ColBasis()
Initial basis status and storage for the solution basis status of the columns.
Definition: GamsModel.hpp:227
double * RowLevel()
Initial values and storage for the solution levels of the rows (row activities).
Definition: GamsModel.hpp:252
void setStatus(const SolverStatus &newSolverStatus, const ModelStatus &newModelStatus)
Sets the GAMS solver and model status.
char * RowSense_
Definition: GamsModel.hpp:436
int * RowBasis_
Definition: GamsModel.hpp:441
void setResUsed(const double ResUsed)
Sets the number of seconds used.
Definition: GamsModel.hpp:320
bool getPriorityOption()
GAMS Option: If set, then the solver should use the branching priorities in ColPriority().
double ObjRhs_
Definition: GamsModel.hpp:446
void setNodesUsed(const int NodesUsed)
Sets the number of nodes used (in a branch-and-bound algorithm).
Definition: GamsModel.hpp:324
double * ColPriority_
Definition: GamsModel.hpp:432
bool * ColDisc_
Definition: GamsModel.hpp:426
bool isReformulated() const
Tells whether the model has been reformulated by moving the objective equation into the objective and...
Definition: GamsModel.hpp:167
int getIterLim()
GAMS Parameter: Iteration limit for model run.
double * ObjCoef()
The coefficients of the objective function (dense format).
Definition: GamsModel.hpp:266
BasisStatus
Basis status indicator used in GAMS.
Definition: GamsModel.hpp:25
int nSOS2() const
The number of special ordered sets of type 2 in the model.
Definition: GamsModel.hpp:186
int nSemiContinuous() const
The number of semicontinuous variables.
Definition: GamsModel.hpp:189
void setSolution(const double *ColLevel=0, const double *ColMargin=0, const int *ColBasis=0, const int *ColIndicator=0, const double *RowLevel=0, const double *RowMargin=0, const int *RowBasis=0, const int *RowIndicator=0)
Sets the solution information and writes the solution file.
bool * ColDisc()
Indicates whether a variable is discrete (true) or not (false).
Definition: GamsModel.hpp:205
void Allocate()
double ResUsed_
Definition: GamsModel.hpp:459
double ObjConstant()
A constant term in the objective function.
Definition: GamsModel.hpp:269
double getOptCR()
GAMS Parameter: Allowed relative difference between incumbent solution and best bound (for MIPs)...
double getObjVal()
Gives the stored objective function value.
Definition: GamsModel.hpp:335
double * ColPriority()
Branching priorities of columns.
Definition: GamsModel.hpp:232
int * RowIndicator_
Definition: GamsModel.hpp:442
bool getScaleOption()
GAMS Option: If set, then the solver should use the scaling parameters in ColScale() and RowScale()...
void setIterUsed(const int IterUsed)
Sets the number of iterations used.
Definition: GamsModel.hpp:316
PrintMask
Distinguishing between message types.
Definition: GamsModel.hpp:101
int * matStart_
Definition: GamsModel.hpp:451
double getResLim()
GAMS Parameter: Time limit for model run in seconds.
double ObjVal_
Definition: GamsModel.hpp:457
double * ColLevel_
Definition: GamsModel.hpp:429
int * matRowIdx()
The row indices for the problem matrix.
Definition: GamsModel.hpp:285
double * ColMargin()
Initial marginals and storage for the solution values of the dual variables corresponding to the colu...
Definition: GamsModel.hpp:224
int matSqueezeZeros()
Removes zero entries in the problem matrix.
void setObjVal(const double ObjVal)
Sets the objective function value in the solution.
Definition: GamsModel.hpp:328
~GamsModel()
Destructor.
int nSemiCon_
Definition: GamsModel.hpp:418
double getCheat()
GAMS Parameter: A new valid solution must be at least this much better than incumbent integer solutio...
int * ColBasis_
Definition: GamsModel.hpp:431
double * RowScale_
Definition: GamsModel.hpp:438
bool * ColSemiCon_
Definition: GamsModel.hpp:428
double * RowMargin()
Initial marginals and storage for the solution values of the dual variables corresponding to the rows...
Definition: GamsModel.hpp:255
double * ColUb_
Definition: GamsModel.hpp:425
double * ObjCoef_
Definition: GamsModel.hpp:445
void setInfinity(const double &SolverMInf, const double &SolverPInf)
Set values that GAMS should use for minus and plus infinity.
double zCoef_
Definition: GamsModel.hpp:447
RowStatus
Row status indicator used in GAMS.
Definition: GamsModel.hpp:45
double * RowLevel_
Definition: GamsModel.hpp:439
double * ColLevel()
Initial values and storage for the solution values of the primal variables.
Definition: GamsModel.hpp:221
double * ColScale()
Scaling parameters for columns.
Definition: GamsModel.hpp:236
bool * ColSemiContinuous()
Indicates whether a variable is semicontinuous or semiinteger (true) or not (false).
Definition: GamsModel.hpp:218