source: stable/1.6/Clp/src/CbcOrClpParam.hpp @ 1609

Last change on this file since 1609 was 1161, checked in by forrest, 12 years ago

for Stefan messages

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#ifdef USE_CBCCONFIG
5# include "CbcConfig.h"
6#else
7# include "ClpConfig.h"
8#endif
9
10#ifndef CbcOrClpParam_H
11#define CbcOrClpParam_H
12/**
13   This has parameter handling stuff which can be shared between Cbc and Clp (and Dylp etc).
14
15   This (and .cpp) should be copied so that it is the same in Cbc/Test and Clp/Test.
16   I know this is not elegant but it seems simplest.
17   
18   It uses COIN_HAS_CBC for parameters wanted by CBC
19   It uses COIN_HAS_CLP for parameters wanted by CLP (or CBC using CLP)
20   It could use COIN_HAS_DYLP for parameters wanted by DYLP
21   It could use COIN_HAS_DYLP_OR_CLP for parameters wanted by DYLP or CLP etc etc
22
23 */
24class OsiSolverInterface;
25class CbcModel;
26class ClpSimplex;
27/*! \brief Parameter codes
28
29  Parameter type ranges are allocated as follows
30  <ul>
31    <li>   1 -- 100     double parameters
32    <li> 101 -- 200     integer parameters
33    <li> 201 -- 250     string parameters
34    <li> 251 -- 300     cuts etc(string but broken out for clarity)
35    <li> 301 -- 400     `actions'
36  </ul>
37
38  `Actions' do not necessarily invoke an immediate action; it's just that they
39  don't fit neatly into the parameters array.
40 
41  This coding scheme is in flux.
42*/
43
44enum CbcOrClpParameterType
45
46  { GENERALQUERY = -100,FULLGENERALQUERY,
47   
48    PRIMALTOLERANCE = 1, DUALTOLERANCE, TIMELIMIT,
49    DUALBOUND, PRIMALWEIGHT,  OBJSCALE, RHSSCALE,
50   
51    INFEASIBILITYWEIGHT = 51, CUTOFF, INTEGERTOLERANCE,INCREMENT,ALLOWABLEGAP,
52    TIMELIMIT_BAB,
53   
54    DJFIX = 81, GAPRATIO,TIGHTENFACTOR,PRESOLVETOLERANCE,OBJSCALE2,
55    DEXTRA1, DEXTRA2, DEXTRA3, DEXTRA4,
56
57    SOLVERLOGLEVEL=101,
58#ifndef COIN_HAS_CBC
59    LOGLEVEL = 101, 
60#endif
61    MAXFACTOR,PERTVALUE,MAXITERATION,PRESOLVEPASS,IDIOT,SPRINT,
62    OUTPUTFORMAT,SLPVALUE,PRESOLVEOPTIONS,PRINTOPTIONS,SPECIALOPTIONS,
63    SUBSTITUTION,DUALIZE,VERBOSE,CPP,PROCESSTUNE,USESOLUTION,
64
65    STRONGBRANCHING=151,CUTDEPTH, MAXNODES,NUMBERBEFORE,NUMBERANALYZE,
66    NUMBERMINI,MIPOPTIONS,MOREMIPOPTIONS,MAXHOTITS,FPUMPITS,MAXSOLS,
67    FPUMPTUNE,TESTOSI,EXTRA1,EXTRA2,EXTRA3,EXTRA4,CUTPASSINTREE,
68    THREADS,CUTPASS,VUBTRY,
69#ifdef COIN_HAS_CBC
70    LOGLEVEL , 
71#endif
72 
73    DIRECTION=201,DUALPIVOT,SCALING,ERRORSALLOWED,KEEPNAMES,SPARSEFACTOR,
74    PRIMALPIVOT,PRESOLVE,CRASH,BIASLU,PERTURBATION,MESSAGES,AUTOSCALE,
75    CHOLESKY,KKT,BARRIERSCALE,GAMMA,CROSSOVER,PFI,INTPRINT,VECTOR,
76   
77    NODESTRATEGY = 251,BRANCHSTRATEGY,CUTSSTRATEGY,HEURISTICSTRATEGY,
78    GOMORYCUTS,PROBINGCUTS,KNAPSACKCUTS,REDSPLITCUTS,
79    ROUNDING,SOLVER,CLIQUECUTS,COSTSTRATEGY,FLOWCUTS,MIXEDCUTS,
80    TWOMIRCUTS,PREPROCESS,FPUMP,GREEDY,COMBINE,LOCALTREE,SOS,
81    LANDPCUTS,RINS,RESIDCUTS,RENS,
82   
83    DIRECTORY=301,DIRSAMPLE,DIRNETLIB,DIRMIPLIB,IMPORT,EXPORT,RESTORE,SAVE,DUALSIMPLEX,PRIMALSIMPLEX,EITHERSIMPLEX,
84    MAXIMIZE,MINIMIZE,EXIT,STDIN,UNITTEST,NETLIB_EITHER,NETLIB_DUAL,NETLIB_PRIMAL,SOLUTION,SAVESOL,
85    TIGHTEN,FAKEBOUND,HELP,PLUSMINUS,NETWORK,ALLSLACK,REVERSE,BARRIER,NETLIB_BARRIER,NETLIB_TUNE,
86    REALLY_SCALE,BASISIN,BASISOUT,SOLVECONTINUOUS,CLEARCUTS,VERSION,STATISTICS,DEBUG,DUMMY,PRINTMASK,
87    OUTDUPROWS,USERCLP,MODELIN,
88
89    BAB=351,MIPLIB,STRENGTHEN,PRIORITYIN,USERCBC,DOHEURISTIC,
90
91    OSLSTUFF = 401,CBCSTUFF,
92
93    INVALID = 1000 } ;
94#include <vector>
95#include <string>
96
97/// Very simple class for setting parameters
98
99class CbcOrClpParam
100{
101public:
102  /**@name Constructor and destructor */
103  //@{
104  /// Constructors
105  CbcOrClpParam (  );
106  CbcOrClpParam (std::string name, std::string help,
107           double lower, double upper, CbcOrClpParameterType type,bool display=true);
108  CbcOrClpParam (std::string name, std::string help,
109           int lower, int upper, CbcOrClpParameterType type,bool display=true);
110  // Other strings will be added by insert
111  CbcOrClpParam (std::string name, std::string help, std::string firstValue,
112           CbcOrClpParameterType type,int whereUsed=7,bool display=true);
113  // Action
114  CbcOrClpParam (std::string name, std::string help,
115           CbcOrClpParameterType type,int whereUsed=7,bool display=true);
116  /// Copy constructor.
117  CbcOrClpParam(const CbcOrClpParam &);
118  /// Assignment operator. This copies the data
119    CbcOrClpParam & operator=(const CbcOrClpParam & rhs);
120  /// Destructor
121  ~CbcOrClpParam (  );
122  //@}
123
124  /**@name stuff */
125  //@{
126  /// Insert string (only valid for keywords)
127  void append(std::string keyWord);
128  /// Adds one help line
129  void addHelp(std::string keyWord);
130  /// Returns name
131  inline std::string  name(  ) const {
132    return name_;
133  }
134  /// Returns short help
135  inline std::string  shortHelp(  ) const {
136    return shortHelp_;
137  }
138  /// Sets a double parameter (nonzero code if error)
139  int setDoubleParameter(CbcModel & model, double value) ;
140  /// Sets double parameter and returns printable string and error code
141  const char * setDoubleParameterWithMessage ( CbcModel & model, double  value ,int & returnCode);
142  /// Gets a double parameter
143  double doubleParameter(CbcModel & model) const;
144  /// Sets a int parameter (nonzero code if error)
145  int setIntParameter(CbcModel & model, int value) ;
146  /// Sets int parameter and returns printable string and error code
147  const char * setIntParameterWithMessage ( CbcModel & model, int value ,int & returnCode);
148  /// Gets a int parameter
149  int intParameter(CbcModel & model) const;
150  /// Sets a double parameter (nonzero code if error)
151  int setDoubleParameter(ClpSimplex * model, double value) ;
152  /// Gets a double parameter
153  double doubleParameter(ClpSimplex * model) const;
154  /// Sets double parameter and returns printable string and error code
155  const char * setDoubleParameterWithMessage ( ClpSimplex * model, double  value ,int & returnCode);
156  /// Sets a int parameter (nonzero code if error)
157  int setIntParameter(ClpSimplex * model, int value) ;
158  /// Sets int parameter and returns printable string and error code
159  const char * setIntParameterWithMessage ( ClpSimplex * model, int  value ,int & returnCode);
160  /// Gets a int parameter
161  int intParameter(ClpSimplex * model) const;
162  /// Sets a double parameter (nonzero code if error)
163  int setDoubleParameter(OsiSolverInterface * model, double value) ;
164  /// Sets double parameter and returns printable string and error code
165  const char * setDoubleParameterWithMessage ( OsiSolverInterface * model, double  value ,int & returnCode);
166  /// Gets a double parameter
167  double doubleParameter(OsiSolverInterface * model) const;
168  /// Sets a int parameter (nonzero code if error)
169  int setIntParameter(OsiSolverInterface * model, int value) ;
170  /// Sets int parameter and returns printable string and error code
171  const char * setIntParameterWithMessage ( OsiSolverInterface * model, int  value ,int & returnCode);
172  /// Gets a int parameter
173  int intParameter(OsiSolverInterface * model) const;
174  /// Checks a double parameter (nonzero code if error)
175  int checkDoubleParameter(double value) const;
176  /// Returns name which could match
177  std::string matchName (  ) const;
178  /// Returns parameter option which matches (-1 if none)
179  int parameterOption ( std::string check ) const;
180  /// Prints parameter options
181  void printOptions (  ) const;
182  /// Returns current parameter option
183  inline std::string currentOption (  ) const
184  { return definedKeyWords_[currentKeyWord_]; }
185  /// Sets current parameter option
186  void setCurrentOption ( int value , bool printIt=false);
187  /// Sets current parameter option and returns printable string
188  const char * setCurrentOptionWithMessage ( int value );
189  /// Sets current parameter option using string
190  void setCurrentOption (const std::string value );
191  /// Returns current parameter option position
192  inline int currentOptionAsInteger (  ) const
193  { return currentKeyWord_; }
194  /// Sets int value
195  void setIntValue ( int value );
196    inline int intValue () const
197  { return intValue_; }
198  /// Sets double value
199  void setDoubleValue ( double value );
200  inline double doubleValue () const
201  { return doubleValue_; }
202  /// Sets string value
203  void setStringValue ( std::string value );
204  inline std::string stringValue () const
205  { return stringValue_; }
206  /// Returns 1 if matches minimum, 2 if matches less, 0 if not matched
207  int matches (std::string input) const;
208  /// type
209  inline CbcOrClpParameterType type() const
210  { return type_;}
211  /// whether to display
212  inline bool displayThis() const
213  { return display_;}
214  /// Set Long help
215  inline void setLonghelp(const std::string help) 
216  {longHelp_=help;}
217  /// Print Long help
218  void printLongHelp() const;
219  /// Print action and string
220  void printString() const;
221  /** 7 if used everywhere,
222      1 - used by clp
223      2 - used by cbc
224      4 - used by ampl
225  */
226  inline int whereUsed() const
227  { return whereUsed_;}
228 
229private:
230  /// gutsOfConstructor
231  void gutsOfConstructor();
232  //@}
233////////////////// data //////////////////
234private:
235
236  /**@name data
237   We might as well throw all type data in - could derive?
238  */
239  //@{
240  // Type see CbcOrClpParameterType
241  CbcOrClpParameterType type_;
242  /// If double == okay
243  double lowerDoubleValue_;
244  double upperDoubleValue_;
245  /// If int == okay
246  int lowerIntValue_;
247  int upperIntValue_;
248  // Length of name
249  unsigned int lengthName_;
250  // Minimum match
251  unsigned int lengthMatch_;
252  /// set of valid strings
253  std::vector<std::string> definedKeyWords_;
254  /// Name
255  std::string name_;
256  /// Short help
257  std::string shortHelp_;
258  /// Long help
259  std::string longHelp_;
260  /// Action
261  CbcOrClpParameterType action_;
262  /// Current keyWord (if a keyword parameter)
263  int currentKeyWord_;
264  /// Display on ?
265  bool display_;
266  /// Integer parameter - current value
267  int intValue_;
268  /// Double parameter - current value
269  double doubleValue_;
270  /// String parameter - current value
271  std::string stringValue_;
272  /** 7 if used everywhere,
273      1 - used by clp
274      2 - used by cbc
275      4 - used by ampl
276  */
277  int whereUsed_;
278  //@}
279};
280/// Simple read stuff
281std::string CoinReadNextField();
282
283std::string CoinReadGetCommand(int argc, const char *argv[]);
284std::string CoinReadGetString(int argc, const char *argv[]);
285// valid 0 - okay, 1 bad, 2 not there
286int CoinReadGetIntField(int argc, const char *argv[],int * valid);
287double CoinReadGetDoubleField(int argc, const char *argv[],int * valid);
288void CoinReadPrintit(const char * input);
289void setCbcOrClpPrinting(bool yesNo);
290#define CBCMAXPARAMETERS 200
291/*
292  Subroutine to establish the cbc parameter array. See the description of
293  class CbcOrClpParam for details. Pulled from C..Main() for clarity.
294*/
295void establishParams (int &numberParameters, CbcOrClpParam *const parameters);
296// Given a parameter type - returns its number in list
297int whichParam (CbcOrClpParameterType name, 
298                int numberParameters, CbcOrClpParam *const parameters);
299// Dump a solution to file
300void saveSolution(const ClpSimplex * lpSolver,std::string fileName);
301#endif  /* CbcOrClpParam_H */
Note: See TracBrowser for help on using the repository browser.