source: trunk/Clp/src/CbcOrClpParam.hpp @ 1402

Last change on this file since 1402 was 1402, checked in by forrest, 10 years ago

get rid of compiler warnings

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