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

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

moving sandbox stuff to trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.7 KB
Line 
1
2/* $Id: CbcOrClpParam.hpp 1502 2010-01-29 14:25:07Z forrest $ */
3// Copyright (C) 2002, International Business Machines
4// Corporation and others.  All Rights Reserved.
5
6#ifdef USE_CBCCONFIG
7# include "CbcConfig.h"
8#else
9# include "ClpConfig.h"
10#endif
11
12#ifndef CbcOrClpParam_H
13#define CbcOrClpParam_H
14/**
15   This has parameter handling stuff which can be shared between Cbc and Clp (and Dylp etc).
16
17   This (and .cpp) should be copied so that it is the same in Cbc/Test and Clp/Test.
18   I know this is not elegant but it seems simplest.
19
20   It uses COIN_HAS_CBC for parameters wanted by CBC
21   It uses COIN_HAS_CLP for parameters wanted by CLP (or CBC using CLP)
22   It could use COIN_HAS_DYLP for parameters wanted by DYLP
23   It could use COIN_HAS_DYLP_OR_CLP for parameters wanted by DYLP or CLP etc etc
24
25 */
26class OsiSolverInterface;
27class CbcModel;
28class ClpSimplex;
29/*! \brief Parameter codes
30
31  Parameter type ranges are allocated as follows
32  <ul>
33    <li>   1 -- 100     double parameters
34    <li> 101 -- 200     integer parameters
35    <li> 201 -- 250     string parameters
36    <li> 251 -- 300     cuts etc(string but broken out for clarity)
37    <li> 301 -- 400     `actions'
38  </ul>
39
40  `Actions' do not necessarily invoke an immediate action; it's just that they
41  don't fit neatly into the parameters array.
42
43  This coding scheme is in flux.
44*/
45
46enum CbcOrClpParameterType
47
48{ CBC_PARAM_GENERALQUERY = -100,
49  CBC_PARAM_FULLGENERALQUERY,
50
51  CLP_PARAM_DBL_PRIMALTOLERANCE = 1,
52  CLP_PARAM_DBL_DUALTOLERANCE,
53  CLP_PARAM_DBL_TIMELIMIT,
54  CLP_PARAM_DBL_DUALBOUND,
55  CLP_PARAM_DBL_PRIMALWEIGHT,
56  CLP_PARAM_DBL_OBJSCALE,
57  CLP_PARAM_DBL_RHSSCALE,
58
59  CBC_PARAM_DBL_INFEASIBILITYWEIGHT = 51,
60  CBC_PARAM_DBL_CUTOFF,
61  CBC_PARAM_DBL_INTEGERTOLERANCE,
62  CBC_PARAM_DBL_INCREMENT,
63  CBC_PARAM_DBL_ALLOWABLEGAP,
64  CBC_PARAM_DBL_TIMELIMIT_BAB,
65  CBC_PARAM_DBL_GAPRATIO,
66
67  CBC_PARAM_DBL_DJFIX = 81,
68  CBC_PARAM_DBL_TIGHTENFACTOR,
69  CLP_PARAM_DBL_PRESOLVETOLERANCE,
70  CLP_PARAM_DBL_OBJSCALE2,
71  CBC_PARAM_DBL_FAKEINCREMENT,
72  CBC_PARAM_DBL_FAKECUTOFF,
73  CBC_PARAM_DBL_ARTIFICIALCOST,
74  CBC_PARAM_DBL_DEXTRA3,
75  CBC_PARAM_DBL_SMALLBAB,
76  CBC_PARAM_DBL_DEXTRA4,
77  CBC_PARAM_DBL_DEXTRA5,
78
79  CLP_PARAM_INT_SOLVERLOGLEVEL = 101,
80#ifndef COIN_HAS_CBC
81  CLP_PARAM_INT_LOGLEVEL = 101,
82#endif
83  CLP_PARAM_INT_MAXFACTOR,
84  CLP_PARAM_INT_PERTVALUE,
85  CLP_PARAM_INT_MAXITERATION,
86  CLP_PARAM_INT_PRESOLVEPASS,
87  CLP_PARAM_INT_IDIOT,
88  CLP_PARAM_INT_SPRINT,
89  CLP_PARAM_INT_OUTPUTFORMAT,
90  CLP_PARAM_INT_SLPVALUE,
91  CLP_PARAM_INT_PRESOLVEOPTIONS,
92  CLP_PARAM_INT_PRINTOPTIONS,
93  CLP_PARAM_INT_SPECIALOPTIONS,
94  CLP_PARAM_INT_SUBSTITUTION,
95  CLP_PARAM_INT_DUALIZE,
96  CLP_PARAM_INT_VERBOSE,
97  CLP_PARAM_INT_CPP,
98  CLP_PARAM_INT_PROCESSTUNE,
99  CLP_PARAM_INT_USESOLUTION,
100
101  CBC_PARAM_INT_STRONGBRANCHING = 151,
102  CBC_PARAM_INT_CUTDEPTH,
103  CBC_PARAM_INT_MAXNODES,
104  CBC_PARAM_INT_NUMBERBEFORE,
105  CBC_PARAM_INT_NUMBERANALYZE,
106  CBC_PARAM_INT_MIPOPTIONS,
107  CBC_PARAM_INT_MOREMIPOPTIONS,
108  CBC_PARAM_INT_MAXHOTITS,
109  CBC_PARAM_INT_FPUMPITS,
110  CBC_PARAM_INT_MAXSOLS,
111  CBC_PARAM_INT_FPUMPTUNE,
112  CBC_PARAM_INT_TESTOSI,
113  CBC_PARAM_INT_EXTRA1,
114  CBC_PARAM_INT_EXTRA2,
115  CBC_PARAM_INT_EXTRA3,
116  CBC_PARAM_INT_EXTRA4,
117  CBC_PARAM_INT_DEPTHMINIBAB,
118  CBC_PARAM_INT_CUTPASSINTREE,
119  CBC_PARAM_INT_THREADS,
120  CBC_PARAM_INT_CUTPASS,
121  CBC_PARAM_INT_VUBTRY,
122  CBC_PARAM_INT_DENSE,
123  CBC_PARAM_INT_EXPERIMENT,
124  CBC_PARAM_INT_DIVEOPT,
125  CBC_PARAM_INT_STRATEGY,
126  CBC_PARAM_INT_SMALLFACT,
127  CBC_PARAM_INT_HOPTIONS,
128  CBC_PARAM_INT_CUTLENGTH,
129  CBC_PARAM_INT_FPUMPTUNE2,
130#ifdef COIN_HAS_CBC
131  CLP_PARAM_INT_LOGLEVEL ,
132#endif
133
134  CLP_PARAM_STR_DIRECTION = 201,
135  CLP_PARAM_STR_DUALPIVOT,
136  CLP_PARAM_STR_SCALING,
137  CLP_PARAM_STR_ERRORSALLOWED,
138  CLP_PARAM_STR_KEEPNAMES,
139  CLP_PARAM_STR_SPARSEFACTOR,
140  CLP_PARAM_STR_PRIMALPIVOT,
141  CLP_PARAM_STR_PRESOLVE,
142  CLP_PARAM_STR_CRASH,
143  CLP_PARAM_STR_BIASLU,
144  CLP_PARAM_STR_PERTURBATION,
145  CLP_PARAM_STR_MESSAGES,
146  CLP_PARAM_STR_AUTOSCALE,
147  CLP_PARAM_STR_CHOLESKY,
148  CLP_PARAM_STR_KKT,
149  CLP_PARAM_STR_BARRIERSCALE,
150  CLP_PARAM_STR_GAMMA,
151  CLP_PARAM_STR_CROSSOVER,
152  CLP_PARAM_STR_PFI,
153  CLP_PARAM_STR_INTPRINT,
154  CLP_PARAM_STR_VECTOR,
155  CLP_PARAM_STR_FACTORIZATION,
156  CLP_PARAM_STR_ALLCOMMANDS,
157
158  CBC_PARAM_STR_NODESTRATEGY = 251,
159  CBC_PARAM_STR_BRANCHSTRATEGY,
160  CBC_PARAM_STR_CUTSSTRATEGY,
161  CBC_PARAM_STR_HEURISTICSTRATEGY,
162  CBC_PARAM_STR_GOMORYCUTS,
163  CBC_PARAM_STR_PROBINGCUTS,
164  CBC_PARAM_STR_KNAPSACKCUTS,
165  CBC_PARAM_STR_REDSPLITCUTS,
166  CBC_PARAM_STR_ROUNDING,
167  CBC_PARAM_STR_SOLVER,
168  CBC_PARAM_STR_CLIQUECUTS,
169  CBC_PARAM_STR_COSTSTRATEGY,
170  CBC_PARAM_STR_FLOWCUTS,
171  CBC_PARAM_STR_MIXEDCUTS,
172  CBC_PARAM_STR_TWOMIRCUTS,
173  CBC_PARAM_STR_PREPROCESS,
174  CBC_PARAM_STR_FPUMP,
175  CBC_PARAM_STR_GREEDY,
176  CBC_PARAM_STR_COMBINE,
177  CBC_PARAM_STR_LOCALTREE,
178  CBC_PARAM_STR_SOS,
179  CBC_PARAM_STR_LANDPCUTS,
180  CBC_PARAM_STR_RINS,
181  CBC_PARAM_STR_RESIDCUTS,
182  CBC_PARAM_STR_RENS,
183  CBC_PARAM_STR_DIVINGS,
184  CBC_PARAM_STR_DIVINGC,
185  CBC_PARAM_STR_DIVINGF,
186  CBC_PARAM_STR_DIVINGG,
187  CBC_PARAM_STR_DIVINGL,
188  CBC_PARAM_STR_DIVINGP,
189  CBC_PARAM_STR_DIVINGV,
190  CBC_PARAM_STR_DINS,
191  CBC_PARAM_STR_PIVOTANDFIX,
192  CBC_PARAM_STR_RANDROUND,
193  CBC_PARAM_STR_NAIVE,
194  CBC_PARAM_STR_ZEROHALFCUTS,
195  CBC_PARAM_STR_CPX,
196  CBC_PARAM_STR_CROSSOVER2,
197  CBC_PARAM_STR_PIVOTANDCOMPLEMENT,
198  CBC_PARAM_STR_VND,
199
200  CLP_PARAM_ACTION_DIRECTORY = 301,
201  CLP_PARAM_ACTION_DIRSAMPLE,
202  CLP_PARAM_ACTION_DIRNETLIB,
203  CBC_PARAM_ACTION_DIRMIPLIB,
204  CLP_PARAM_ACTION_IMPORT,
205  CLP_PARAM_ACTION_EXPORT,
206  CLP_PARAM_ACTION_RESTORE,
207  CLP_PARAM_ACTION_SAVE,
208  CLP_PARAM_ACTION_DUALSIMPLEX,
209  CLP_PARAM_ACTION_PRIMALSIMPLEX,
210  CLP_PARAM_ACTION_EITHERSIMPLEX,
211  CLP_PARAM_ACTION_MAXIMIZE,
212  CLP_PARAM_ACTION_MINIMIZE,
213  CLP_PARAM_ACTION_EXIT,
214  CLP_PARAM_ACTION_STDIN,
215  CLP_PARAM_ACTION_UNITTEST,
216  CLP_PARAM_ACTION_NETLIB_EITHER,
217  CLP_PARAM_ACTION_NETLIB_DUAL,
218  CLP_PARAM_ACTION_NETLIB_PRIMAL,
219  CLP_PARAM_ACTION_SOLUTION,
220  CLP_PARAM_ACTION_SAVESOL,
221  CLP_PARAM_ACTION_TIGHTEN,
222  CLP_PARAM_ACTION_FAKEBOUND,
223  CLP_PARAM_ACTION_HELP,
224  CLP_PARAM_ACTION_PLUSMINUS,
225  CLP_PARAM_ACTION_NETWORK,
226  CLP_PARAM_ACTION_ALLSLACK,
227  CLP_PARAM_ACTION_REVERSE,
228  CLP_PARAM_ACTION_BARRIER,
229  CLP_PARAM_ACTION_NETLIB_BARRIER,
230  CLP_PARAM_ACTION_NETLIB_TUNE,
231  CLP_PARAM_ACTION_REALLY_SCALE,
232  CLP_PARAM_ACTION_BASISIN,
233  CLP_PARAM_ACTION_BASISOUT,
234  CLP_PARAM_ACTION_SOLVECONTINUOUS,
235  CLP_PARAM_ACTION_CLEARCUTS,
236  CLP_PARAM_ACTION_VERSION,
237  CLP_PARAM_ACTION_STATISTICS,
238  CLP_PARAM_ACTION_DEBUG,
239  CLP_PARAM_ACTION_DUMMY,
240  CLP_PARAM_ACTION_PRINTMASK,
241  CLP_PARAM_ACTION_OUTDUPROWS,
242  CLP_PARAM_ACTION_USERCLP,
243  CLP_PARAM_ACTION_MODELIN,
244  CLP_PARAM_ACTION_CSVSTATISTICS,
245  CLP_PARAM_ACTION_STOREDFILE,
246  CLP_PARAM_ACTION_ENVIRONMENT,
247
248  CBC_PARAM_ACTION_BAB = 351,
249  CBC_PARAM_ACTION_MIPLIB,
250  CBC_PARAM_ACTION_STRENGTHEN,
251  CBC_PARAM_ACTION_PRIORITYIN,
252  CBC_PARAM_ACTION_USERCBC,
253  CBC_PARAM_ACTION_DOHEURISTIC,
254
255  CBC_PARAM_NOTUSED_OSLSTUFF = 401,
256  CBC_PARAM_NOTUSED_CBCSTUFF,
257
258  CBC_PARAM_NOTUSED_INVALID = 1000
259} ;
260#include <vector>
261#include <string>
262
263/// Very simple class for setting parameters
264
265class CbcOrClpParam {
266public:
267    /**@name Constructor and destructor */
268    //@{
269    /// Constructors
270    CbcOrClpParam (  );
271    CbcOrClpParam (std::string name, std::string help,
272                   double lower, double upper, CbcOrClpParameterType type, int display = 2);
273    CbcOrClpParam (std::string name, std::string help,
274                   int lower, int upper, CbcOrClpParameterType type, int display = 2);
275    // Other strings will be added by insert
276    CbcOrClpParam (std::string name, std::string help, std::string firstValue,
277                   CbcOrClpParameterType type, int whereUsed = 7, int display = 2);
278    // Action
279    CbcOrClpParam (std::string name, std::string help,
280                   CbcOrClpParameterType type, int whereUsed = 7, int display = 2);
281    /// Copy constructor.
282    CbcOrClpParam(const CbcOrClpParam &);
283    /// Assignment operator. This copies the data
284    CbcOrClpParam & operator=(const CbcOrClpParam & rhs);
285    /// Destructor
286    ~CbcOrClpParam (  );
287    //@}
288
289    /**@name stuff */
290    //@{
291    /// Insert string (only valid for keywords)
292    void append(std::string keyWord);
293    /// Adds one help line
294    void addHelp(std::string keyWord);
295    /// Returns name
296    inline std::string  name(  ) const {
297        return name_;
298    }
299    /// Returns short help
300    inline std::string  shortHelp(  ) const {
301        return shortHelp_;
302    }
303    /// Sets a double parameter (nonzero code if error)
304    int setDoubleParameter(CbcModel & model, double value) ;
305    /// Sets double parameter and returns printable string and error code
306    const char * setDoubleParameterWithMessage ( CbcModel & model, double  value , int & returnCode);
307    /// Gets a double parameter
308    double doubleParameter(CbcModel & model) const;
309    /// Sets a int parameter (nonzero code if error)
310    int setIntParameter(CbcModel & model, int value) ;
311    /// Sets int parameter and returns printable string and error code
312    const char * setIntParameterWithMessage ( CbcModel & model, int value , int & returnCode);
313    /// Gets a int parameter
314    int intParameter(CbcModel & model) const;
315    /// Sets a double parameter (nonzero code if error)
316    int setDoubleParameter(ClpSimplex * model, double value) ;
317    /// Gets a double parameter
318    double doubleParameter(ClpSimplex * model) const;
319    /// Sets double parameter and returns printable string and error code
320    const char * setDoubleParameterWithMessage ( ClpSimplex * model, double  value , int & returnCode);
321    /// Sets a int parameter (nonzero code if error)
322    int setIntParameter(ClpSimplex * model, int value) ;
323    /// Sets int parameter and returns printable string and error code
324    const char * setIntParameterWithMessage ( ClpSimplex * model, int  value , int & returnCode);
325    /// Gets a int parameter
326    int intParameter(ClpSimplex * model) const;
327    /// Sets a double parameter (nonzero code if error)
328    int setDoubleParameter(OsiSolverInterface * model, double value) ;
329    /// Sets double parameter and returns printable string and error code
330    const char * setDoubleParameterWithMessage ( OsiSolverInterface * model, double  value , int & returnCode);
331    /// Gets a double parameter
332    double doubleParameter(OsiSolverInterface * model) const;
333    /// Sets a int parameter (nonzero code if error)
334    int setIntParameter(OsiSolverInterface * model, int value) ;
335    /// Sets int parameter and returns printable string and error code
336    const char * setIntParameterWithMessage ( OsiSolverInterface * model, int  value , int & returnCode);
337    /// Gets a int parameter
338    int intParameter(OsiSolverInterface * model) const;
339    /// Checks a double parameter (nonzero code if error)
340    int checkDoubleParameter(double value) const;
341    /// Returns name which could match
342    std::string matchName (  ) const;
343    /// Returns length of name for ptinting
344    int lengthMatchName (  ) const;
345    /// Returns parameter option which matches (-1 if none)
346    int parameterOption ( std::string check ) const;
347    /// Prints parameter options
348    void printOptions (  ) const;
349    /// Returns current parameter option
350    inline std::string currentOption (  ) const {
351        return definedKeyWords_[currentKeyWord_];
352    }
353    /// Sets current parameter option
354    void setCurrentOption ( int value , bool printIt = false);
355    /// Sets current parameter option and returns printable string
356    const char * setCurrentOptionWithMessage ( int value );
357    /// Sets current parameter option using string
358    void setCurrentOption (const std::string value );
359    /// Returns current parameter option position
360    inline int currentOptionAsInteger (  ) const {
361        return currentKeyWord_;
362    }
363    /// Sets int value
364    void setIntValue ( int value );
365    inline int intValue () const {
366        return intValue_;
367    }
368    /// Sets double value
369    void setDoubleValue ( double value );
370    inline double doubleValue () const {
371        return doubleValue_;
372    }
373    /// Sets string value
374    void setStringValue ( std::string value );
375    inline std::string stringValue () const {
376        return stringValue_;
377    }
378    /// Returns 1 if matches minimum, 2 if matches less, 0 if not matched
379    int matches (std::string input) const;
380    /// type
381    inline CbcOrClpParameterType type() const {
382        return type_;
383    }
384    /// whether to display
385    inline int displayThis() const {
386        return display_;
387    }
388    /// Set Long help
389    inline void setLonghelp(const std::string help) {
390        longHelp_ = help;
391    }
392    /// Print Long help
393    void printLongHelp() const;
394    /// Print action and string
395    void printString() const;
396    /** 7 if used everywhere,
397        1 - used by clp
398        2 - used by cbc
399        4 - used by ampl
400    */
401    inline int whereUsed() const {
402        return whereUsed_;
403    }
404
405private:
406    /// gutsOfConstructor
407    void gutsOfConstructor();
408    //@}
409////////////////// data //////////////////
410private:
411
412    /**@name data
413     We might as well throw all type data in - could derive?
414    */
415    //@{
416    // Type see CbcOrClpParameterType
417    CbcOrClpParameterType type_;
418    /// If double == okay
419    double lowerDoubleValue_;
420    double upperDoubleValue_;
421    /// If int == okay
422    int lowerIntValue_;
423    int upperIntValue_;
424    // Length of name
425    unsigned int lengthName_;
426    // Minimum match
427    unsigned int lengthMatch_;
428    /// set of valid strings
429    std::vector<std::string> definedKeyWords_;
430    /// Name
431    std::string name_;
432    /// Short help
433    std::string shortHelp_;
434    /// Long help
435    std::string longHelp_;
436    /// Action
437    CbcOrClpParameterType action_;
438    /// Current keyWord (if a keyword parameter)
439    int currentKeyWord_;
440    /// Display on ?
441    int display_;
442    /// Integer parameter - current value
443    int intValue_;
444    /// Double parameter - current value
445    double doubleValue_;
446    /// String parameter - current value
447    std::string stringValue_;
448    /** 7 if used everywhere,
449        1 - used by clp
450        2 - used by cbc
451        4 - used by ampl
452    */
453    int whereUsed_;
454    //@}
455};
456/// Simple read stuff
457std::string CoinReadNextField();
458
459std::string CoinReadGetCommand(int argc, const char *argv[]);
460std::string CoinReadGetString(int argc, const char *argv[]);
461// valid 0 - okay, 1 bad, 2 not there
462int CoinReadGetIntField(int argc, const char *argv[], int * valid);
463double CoinReadGetDoubleField(int argc, const char *argv[], int * valid);
464void CoinReadPrintit(const char * input);
465void setCbcOrClpPrinting(bool yesNo);
466#define CBCMAXPARAMETERS 200
467/*
468  Subroutine to establish the cbc parameter array. See the description of
469  class CbcOrClpParam for details. Pulled from C..Main() for clarity.
470*/
471void establishParams (int &numberParameters, CbcOrClpParam *const parameters);
472// Given a parameter type - returns its number in list
473int whichParam (CbcOrClpParameterType name,
474                int numberParameters, CbcOrClpParam *const parameters);
475// Dump a solution to file
476void saveSolution(const ClpSimplex * lpSolver, std::string fileName);
477#endif  /* CbcOrClpParam_H */
Note: See TracBrowser for help on using the repository browser.