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

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

parameters osl

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.9 KB
Line 
1/* $Id: CbcOrClpParam.hpp 1401 2009-07-18 15:53:08Z 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,
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,bool display=true);
112  CbcOrClpParam (std::string name, std::string help,
113           int lower, int upper, CbcOrClpParameterType type,bool display=true);
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,bool display=true);
117  // Action
118  CbcOrClpParam (std::string name, std::string help,
119           CbcOrClpParameterType type,int whereUsed=7,bool display=true);
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 parameter option which matches (-1 if none)
183  int parameterOption ( std::string check ) const;
184  /// Prints parameter options
185  void printOptions (  ) const;
186  /// Returns current parameter option
187  inline std::string currentOption (  ) const
188  { return definedKeyWords_[currentKeyWord_]; }
189  /// Sets current parameter option
190  void setCurrentOption ( int value , bool printIt=false);
191  /// Sets current parameter option and returns printable string
192  const char * setCurrentOptionWithMessage ( int value );
193  /// Sets current parameter option using string
194  void setCurrentOption (const std::string value );
195  /// Returns current parameter option position
196  inline int currentOptionAsInteger (  ) const
197  { return currentKeyWord_; }
198  /// Sets int value
199  void setIntValue ( int value );
200    inline int intValue () const
201  { return intValue_; }
202  /// Sets double value
203  void setDoubleValue ( double value );
204  inline double doubleValue () const
205  { return doubleValue_; }
206  /// Sets string value
207  void setStringValue ( std::string value );
208  inline std::string stringValue () const
209  { return stringValue_; }
210  /// Returns 1 if matches minimum, 2 if matches less, 0 if not matched
211  int matches (std::string input) const;
212  /// type
213  inline CbcOrClpParameterType type() const
214  { return type_;}
215  /// whether to display
216  inline bool displayThis() const
217  { return display_;}
218  /// Set Long help
219  inline void setLonghelp(const std::string help) 
220  {longHelp_=help;}
221  /// Print Long help
222  void printLongHelp() const;
223  /// Print action and string
224  void printString() const;
225  /** 7 if used everywhere,
226      1 - used by clp
227      2 - used by cbc
228      4 - used by ampl
229  */
230  inline int whereUsed() const
231  { return whereUsed_;}
232 
233private:
234  /// gutsOfConstructor
235  void gutsOfConstructor();
236  //@}
237////////////////// data //////////////////
238private:
239
240  /**@name data
241   We might as well throw all type data in - could derive?
242  */
243  //@{
244  // Type see CbcOrClpParameterType
245  CbcOrClpParameterType type_;
246  /// If double == okay
247  double lowerDoubleValue_;
248  double upperDoubleValue_;
249  /// If int == okay
250  int lowerIntValue_;
251  int upperIntValue_;
252  // Length of name
253  unsigned int lengthName_;
254  // Minimum match
255  unsigned int lengthMatch_;
256  /// set of valid strings
257  std::vector<std::string> definedKeyWords_;
258  /// Name
259  std::string name_;
260  /// Short help
261  std::string shortHelp_;
262  /// Long help
263  std::string longHelp_;
264  /// Action
265  CbcOrClpParameterType action_;
266  /// Current keyWord (if a keyword parameter)
267  int currentKeyWord_;
268  /// Display on ?
269  bool display_;
270  /// Integer parameter - current value
271  int intValue_;
272  /// Double parameter - current value
273  double doubleValue_;
274  /// String parameter - current value
275  std::string stringValue_;
276  /** 7 if used everywhere,
277      1 - used by clp
278      2 - used by cbc
279      4 - used by ampl
280  */
281  int whereUsed_;
282  //@}
283};
284/// Simple read stuff
285std::string CoinReadNextField();
286
287std::string CoinReadGetCommand(int argc, const char *argv[]);
288std::string CoinReadGetString(int argc, const char *argv[]);
289// valid 0 - okay, 1 bad, 2 not there
290int CoinReadGetIntField(int argc, const char *argv[],int * valid);
291double CoinReadGetDoubleField(int argc, const char *argv[],int * valid);
292void CoinReadPrintit(const char * input);
293void setCbcOrClpPrinting(bool yesNo);
294#define CBCMAXPARAMETERS 200
295/*
296  Subroutine to establish the cbc parameter array. See the description of
297  class CbcOrClpParam for details. Pulled from C..Main() for clarity.
298*/
299void establishParams (int &numberParameters, CbcOrClpParam *const parameters);
300// Given a parameter type - returns its number in list
301int whichParam (CbcOrClpParameterType name, 
302                int numberParameters, CbcOrClpParam *const parameters);
303// Dump a solution to file
304void saveSolution(const ClpSimplex * lpSolver,std::string fileName);
305#endif  /* CbcOrClpParam_H */
Note: See TracBrowser for help on using the repository browser.