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

Last change on this file since 1883 was 1883, checked in by forrest, 7 years ago

allow setting of random seed

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