source: trunk/Cbc/src/CbcGenParamUtils.cpp @ 958

Last change on this file since 958 was 958, checked in by lou, 11 years ago

Bare INT_MAX fails under GCC 4.3. Change to COIN_INT_MAX.

File size: 48.6 KB
Line 
1/*
2  Copyright (C) 2007, Lou Hafer, International Business Machines Corporation
3  and others.  All Rights Reserved.
4
5  This file is part of cbc-generic.
6*/
7
8#if defined(_MSC_VER)
9// Turn off compiler warning about long names
10#  pragma warning(disable:4786)
11#endif
12
13#include <string>
14#include <cassert>
15
16#include "CoinFileIO.hpp"
17
18#include "CoinFinite.hpp"
19#include "CoinParam.hpp"
20
21#include "CbcModel.hpp"
22
23#include "CbcGenParam.hpp"
24#include "CbcGenCtlBlk.hpp"
25
26/*! \file CbcGenParamUtils
27    \brief Implementation functions for CbcGenParam parameters.
28*/
29
30namespace {
31
32  char svnid[] = "$Id$" ;
33
34}
35
36namespace CbcGenSolvers
37{
38  void setupSolverParam(CbcGenParam &solverParam) ;
39}
40
41namespace CbcGenParamUtils
42{
43
44/*
45  Function to add cbc-generic control parameters to the cbc-generic parameter
46  vector. Were needed, defaults are drawn from ctlBlk-> This function is a
47  friend of CbcGenCtlBlk.
48*/
49
50void addCbcGenParams (int &numberParameters, CoinParamVec &parameters,
51                      CbcGenCtlBlk *ctlBlk)
52
53{ CbcGenParam *param ;
54  std::string empty = "" ;
55
56  param = new CbcGenParam(CbcGenParam::GENERALQUERY,"?",
57        "Print a list of commands",false) ;
58  param->setPushFunc(doHelpParam) ;
59  param->setObj(ctlBlk) ;
60  parameters.push_back(param) ;
61
62  param = new CbcGenParam(CbcGenParam::FULLGENERALQUERY,"???",
63        "Print a list with *all* commands, even those hidden with `?'",false) ;
64  param->setPushFunc(doHelpParam) ;
65  param->setObj(ctlBlk) ;
66  parameters.push_back(param) ;
67
68  param = new CbcGenParam(CbcGenParam::PRINTVERSION,
69                          "version","Print version") ;
70  param->setPushFunc(doVersionParam) ;
71  param->setObj(ctlBlk) ;
72  parameters.push_back(param) ;
73
74/*
75  Built into CoinParam parsing. No additional actions required. doNothingParam
76  simply prevents them from being reported as unimplemented.
77*/
78  param = new CbcGenParam(CbcGenParam::STDIN,"-",
79        "Switch to interactive command line mode",false) ;
80  param->setPushFunc(doNothingParam) ;
81  parameters.push_back(param) ;
82  param = new CbcGenParam(CbcGenParam::STDIN,"stdin",
83        "Switch to interactive command line mode",false) ;
84  param->setPushFunc(doNothingParam) ;
85  param->setObj(ctlBlk) ;
86  parameters.push_back(param) ;
87
88  param = new CbcGenParam(CbcGenParam::BAB,
89        "branch!AndCut","Do Branch and Cut") ;
90  param->setPushFunc(doBaCParam) ;
91  param->setObj(ctlBlk) ;
92  param->setLongHelp(
93        "This does branch and cut. There are many parameters which can affect the performance.  First just try with default settings and look carefully at the log file.  Did cuts help?  Did they take too long?  Look at output to see which cuts were effective and then do some tuning.  You will see that the options for cuts are off, on, root and ifmove.  Off is obvious, on means that this cut generator will be tried in the branch and cut tree (you can fine tune using 'depth').  Root means just at the root node while 'ifmove' means that cuts will be used in the tree if they look as if they are doing some good and moving the objective value.  If pre-processing reduced the size of the problem or strengthened many coefficients then it is probably wise to leave it on.  Switch off heuristics which did not provide solutions.  The other major area to look at is the search.  Hopefully good solutions were obtained fairly early in the search so the important point is to select the best variable to branch on.  See whether strong branching did a good job - or did it just take a lot of iterations.  Adjust the strongBranching and trustPseudoCosts parameters."
94        ) ;
95  parameters.push_back(param) ;
96
97  param = new CbcGenParam(CbcGenParam::CPP,
98                          "cpp!Generate","Generates C++ code",-1,50000) ;
99  param->setObj(ctlBlk) ;
100  param->setLongHelp(
101        "Once you like what the stand-alone solver does then this allows you to generate user_driver.cpp which approximates the code.  0 gives simplest driver, 1 generates saves and restores, 2 generates saves and restores even for variables at default value. 4 bit in cbc generates size dependent code rather than computed values."
102        ) ;
103  parameters.push_back(param) ;
104
105  param = new CbcGenParam(CbcGenParam::CLIQUECUTS,
106        "clique!Cuts","Whether to use clique cuts","off",
107        ctlBlk->clique_.action_) ;
108  param->appendKwd("on") ;
109  param->appendKwd("root") ;
110  param->appendKwd("ifmove") ;
111  param->appendKwd("forceOn") ;
112  param->setObj(ctlBlk) ;
113  param->setPushFunc(pushCbcGenCutParam) ;
114  param->setLongHelp(
115        "This switches on clique cuts (either at root or in entire tree). See branchAndCut for information on options."
116        ) ;
117  parameters.push_back(param) ;
118
119  param = new CbcGenParam(CbcGenParam::CUTDEPTH,
120        "cutD!epth","Depth in tree at which to do cuts",
121        -1,999999,ctlBlk->cutDepth_) ;
122  param->setObj(ctlBlk) ;
123  param->setPushFunc(pushCbcGenIntParam) ;
124  param->setLongHelp(
125        "Cut generators may be off, on only at the root, on if they look useful, and on at some interval.  If they are done every node then that is that, but it may be worth doing them every so often.  The original method was every so many nodes but it is more logical to do it whenever depth in tree is a multiple of K.  This option does that and defaults to -1 (off)."
126        ) ;
127  parameters.push_back(param) ;
128
129
130  param = new CbcGenParam(CbcGenParam::CUTSTRATEGY,
131        "cuts!OnOff","Switches all cuts on or off","off",0) ;
132  param->appendKwd("on") ;
133  param->appendKwd("root") ;
134  param->appendKwd("ifmove") ;
135  param->appendKwd("forceOn") ;
136  param->setObj(ctlBlk) ;
137  param->setLongHelp(
138        "This can be used to switch on or off all cuts (apart from Reduce and Split).  Then you can set individual ones off or on.  See branchAndCut for information on options."
139        ) ;
140  parameters.push_back(param) ;
141
142  param = new CbcGenParam(CbcGenParam::COMBINE,
143        "combine!Solutions",
144        "Whether to use combine solution heuristic","off",
145        ctlBlk->combine_.action_) ;
146  param->appendKwd("on") ;
147  param->setObj(ctlBlk) ;
148  param->setLongHelp(
149        "This switches on a heuristic which does branch and cut on the problem given by just using variables which have appeared in one or more solutions. It is obviously only tried after two or more solutions."
150        ) ;
151  parameters.push_back(param) ;
152
153  param = new CbcGenParam(CbcGenParam::COSTSTRATEGY,
154        "cost!Strategy","Whether to use costs or column order as priorities",
155        "off",0) ;
156  param->appendKwd("pri!orities") ;
157  param->appendKwd("column!Order") ;
158  param->setObj(ctlBlk) ;
159  param->setLongHelp(
160        "This orders the variables in order of their absolute costs - with largest cost ones being branched on first.  This primitive strategy can be surprisingly effective.  The column order option is obviously not on costs but it's easy to implement."
161        ) ;
162  parameters.push_back(param) ;
163
164  param = new CbcGenParam(CbcGenParam::DEBUG,
165        "debug!In","Read/write valid solution from/to file","",false) ;
166  param->setObj(ctlBlk) ;
167  param->setPushFunc(doDebugParam) ;
168  param->setLongHelp(
169        "This will read a solution file from the given file name.  It will use the default directory given by 'directory'.  A name of '$' will use the previous value for the name.  This is initialized to '', i.e. it must be set.\n\nIf set to create it will create a file called debug.file after B&C search; if set to createAfterPre it will create the file before undoing preprocessing.\n\nThe idea is that if you suspect a bad cut generator and you did not use preprocessing you can do a good run with debug set to 'create' and then switch on the cuts you suspect and re-run with debug set to 'debug.file'  Similarly if you do use preprocessing, but use createAfterPre.  The create case has the same effect as saveSolution."
170        ) ;
171  parameters.push_back(param) ;
172
173  param = new CbcGenParam(CbcGenParam::DIRECTORY,
174        "directory","Set Default directory for import etc.",
175        ctlBlk->dfltDirectory_) ;
176  param->setObj(ctlBlk) ;
177  param->setLongHelp(
178        "This sets the directory which import, export, saveModel, restoreModel etc. will use. It is initialized to the current directory."
179        ) ;
180  param->setPushFunc(pushCbcGenStrParam) ;
181  parameters.push_back(param) ;
182
183  param = new CbcGenParam(CbcGenParam::EXIT,"end","Stops execution") ;
184  param->setPushFunc(doExitParam) ;
185  param->setObj(ctlBlk) ;
186  param->setLongHelp(
187        "This stops execution; end, exit, quit and stop are synonyms."
188        ) ;
189  parameters.push_back(param) ;
190
191  param = new CbcGenParam(CbcGenParam::ERRORSALLOWED,
192        "error!sAllowed","Whether to allow import errors","off",0) ;
193  param->appendKwd("on") ;
194  param->setObj(ctlBlk) ;
195  param->setLongHelp(
196        "The default is not to use any model which had errors when reading the mps file.  Setting this to 'on' will allow all errors from which the code can recover simply by ignoring the error.  There are some errors from which the code can not recover, e.g., no ENDATA.  This has to be set before import, i.e., -errorsAllowed on -import xxxxxx.mps."
197        ) ;
198  parameters.push_back(param) ;
199
200  param = new CbcGenParam(CbcGenParam::EXIT,"exit","Stops execution") ;
201  param->setPushFunc(doExitParam) ;
202  param->setObj(ctlBlk) ;
203  param->setLongHelp(
204        "This stops execution; end, exit, quit and stop are synonyms."
205        ) ;
206  parameters.push_back(param) ;
207
208  param = new CbcGenParam(CbcGenParam::EXPORT,
209                          "export","Export model as mps file",
210                          std::string("default.mps")) ;
211  param->setObj(ctlBlk) ;
212  param->setLongHelp(
213        "This will write an MPS format file to the given file name.  It will use the default directory given by 'directory'.  A name of '$' will use the previous value for the name.  This is initialized to 'default.mps'."
214     ) ;
215  parameters.push_back(param) ;
216
217  param = new CbcGenParam(CbcGenParam::DJFIX,"fix!OnDj",
218        "Try heuristic that fixes variables based on reduced costs",
219        -1.0e20,1.0e20,ctlBlk->djFix_.threshold_) ;
220  param->setPushFunc(pushCbcGenDblParam) ;
221  param->setObj(ctlBlk) ;
222  param->setLongHelp(
223        "If set, integer variables with reduced costs greater than the specified value will be fixed before branch and bound - use with extreme caution!"
224        ) ;
225  parameters.push_back(param) ;
226
227  param = new CbcGenParam(CbcGenParam::FPUMP,
228        "feas!ibilityPump","Whether to try Feasibility Pump","off",
229        ctlBlk->fpump_.action_) ;
230  param->appendKwd("on") ;
231  param->setObj(ctlBlk) ;
232  param->setLongHelp(
233        "This switches on feasibility pump heuristic at root. This is due to Fischetti and Lodi and uses a sequence of LPs to try and get an integer feasible solution.  Some fine tuning is available by passFeasibilityPump."
234        ) ; 
235  parameters.push_back(param) ;
236
237  param = new CbcGenParam(CbcGenParam::FPUMPITS,
238        "passF!easibilityPump","How many passes in feasibility pump",
239        0,10000,ctlBlk->fpump_.iters_) ;
240  param->setObj(ctlBlk) ;
241  param->setLongHelp(
242        "This fine tunes the Feasibility Pump heuristic by doing more or fewer passes."
243        ) ;
244  parameters.push_back(param) ;
245
246  param = new CbcGenParam(CbcGenParam::FLOWCUTS,
247        "flow!CoverCuts","Whether to use Flow Cover cuts","off",
248        ctlBlk->flow_.action_) ;
249  param->appendKwd("on") ;
250  param->appendKwd("root") ;
251  param->appendKwd("ifmove") ;
252  param->appendKwd("forceOn") ;
253  param->setObj(ctlBlk) ;
254  param->setPushFunc(pushCbcGenCutParam) ;
255  param->setLongHelp(
256        "This switches on flow cover cuts (either at root or in entire tree).  See branchAndCut for information on options."
257        ) ; 
258  parameters.push_back(param) ;
259
260  param = new CbcGenParam(CbcGenParam::GOMORYCUTS,"gomory!Cuts",
261        "Whether to use Gomory cuts","off",
262        ctlBlk->gomory_.action_) ;
263  param->appendKwd("on") ;
264  param->appendKwd("root") ;
265  param->appendKwd("ifmove") ;
266  param->appendKwd("forceOn") ;
267  param->setObj(ctlBlk) ;
268  param->setPushFunc(pushCbcGenCutParam) ;
269  param->setLongHelp(
270        "The original cuts - beware of imitations!  Having gone out of favor, they are now more fashionable as LP solvers are more robust and they interact well with other cuts.  They will almost always give cuts (although in this executable they are limited as to number of variables in cut).  However the cuts may be dense so it is worth experimenting. See branchAndCut for information on options."
271        ) ;
272  parameters.push_back(param) ;
273
274  param = new CbcGenParam(CbcGenParam::GREEDY,
275        "greedy!Heuristic","Whether to use a greedy heuristic","off",
276        ctlBlk->greedyCover_.action_) ;
277  param->appendKwd("on") ;
278  param->appendKwd("root") ;
279  param->setObj(ctlBlk) ;
280  param->setLongHelp(
281        "Switches on a pair of greedy heuristic which will try and obtain a solution.  It may just fix a percentage of variables and then try a small branch and cut run."
282        ) ;
283  parameters.push_back(param) ;
284
285  param = new CbcGenParam(CbcGenParam::HEURISTICSTRATEGY,
286        "heur!isticsOnOff","Switches most heuristics on or off","off",0) ;
287  param->appendKwd("on") ;
288  param->setObj(ctlBlk) ;
289  param->setLongHelp(
290        "This can be used to switch on or off all heuristics.  Then you can set individual ones off or on.  CbcTreeLocal is not included as it dramatically alters search."
291        ) ;
292  parameters.push_back(param) ;
293
294  param = new CbcGenParam(CbcGenParam::KNAPSACKCUTS,
295        "knapsack!Cuts","Whether to use Knapsack cuts","off",
296        ctlBlk->knapsack_.action_) ;
297  param->appendKwd("on") ;
298  param->appendKwd("root") ;
299  param->appendKwd("ifmove") ;
300  param->appendKwd("forceOn") ;
301  param->setObj(ctlBlk) ;
302  param->setPushFunc(pushCbcGenCutParam) ;
303  param->setLongHelp(
304        "This switches on knapsack cuts (either at root or in entire tree). See branchAndCut for information on options."
305        ) ;
306  parameters.push_back(param) ;
307
308/*
309  param = new CbcGenParam(CbcGenParam::LANDPCUTS,
310        "lift!AndProjectCuts","Whether to use lift-and-project cuts","off",
311        ctlBlk->landp_.action_) ;
312  param->appendKwd("on") ;
313  param->appendKwd("root") ;
314  param->appendKwd("ifmove") ;
315  param->appendKwd("forceOn") ;
316  param->setObj(ctlBlk) ;
317  param->setLongHelp(
318        "This switches on lift-and-project cuts (either at root or in entire tree). See branchAndCut for information on options."
319        ) ;
320  parameters.push_back(param) ;
321*/
322
323  param = new CbcGenParam(CbcGenParam::LOCALTREE,
324        "local!TreeSearch","Whether to use local tree search","off",
325        ctlBlk->localTree_.action_) ;
326  param->appendKwd("on") ;
327  param->setObj(ctlBlk) ;
328  param->setLongHelp(
329        "This switches on a local search algorithm when a solution is found.  This is from Fischetti and Lodi and is not really a heuristic although it can be used as one. When used from this program it has limited functionality.  It is not controlled by heuristicsOnOff."
330        ) ;
331  parameters.push_back(param) ;
332
333  param = new CbcGenParam(CbcGenParam::LOGLEVEL,
334        "log!Level","Level of detail in cbc-generic output.",
335        -1,999999,ctlBlk->logLvl_) ;
336  param->setObj(ctlBlk) ;
337  param->setPushFunc(pushCbcGenIntParam) ;
338  param->setLongHelp(
339        "If set to 0 then there should be no output in normal circumstances. A value of 1 is probably the best value for most uses, while 2 and 3 give more information."
340        ) ;
341  parameters.push_back(param) ;
342
343  param = new CbcGenParam(CbcGenParam::MIXEDCUTS,
344        "mixed!IntegerRoundingCuts",
345        "Whether to use Mixed Integer Rounding cuts","off",
346        ctlBlk->mir_.action_) ;
347  param->appendKwd("on") ;
348  param->appendKwd("root") ;
349  param->appendKwd("ifmove") ;
350  param->appendKwd("forceOn") ;
351  param->setObj(ctlBlk) ;
352  param->setPushFunc(pushCbcGenCutParam) ;
353  param->setLongHelp(
354        "This switches on mixed integer rounding cuts (either at root or in entire tree).  See branchAndCut for information on options."
355        ) ;
356  parameters.push_back(param) ;
357
358  param = new CbcGenParam(CbcGenParam::USESOLUTION,
359        "force!Solution",
360        "Whether to use given solution as crash for BAB","off",0) ;
361  param->appendKwd("on") ;
362  param->setObj(ctlBlk) ;
363  param->setLongHelp(
364        "If on then tries to branch to solution given by AMPL or priorities file."
365        ) ; 
366  parameters.push_back(param) ;
367
368  param = new CbcGenParam(CbcGenParam::HELP,"help",
369        "Print out version, non-standard options and some help") ;
370  param->setPushFunc(doHelpParam) ;
371  param->setObj(ctlBlk) ;
372  param->setLongHelp(
373        "This prints out some help to get a user started. If you're seeing this message, you should be past that stage."
374        ) ;
375  parameters.push_back(param) ;
376
377  param = new CbcGenParam(CbcGenParam::IMPORT,
378                          "import","Import model from mps file",
379                          ctlBlk->lastMpsIn_) ;
380  param->setPushFunc(doImportParam) ;
381  param->setObj(ctlBlk) ;
382  param->setLongHelp(
383        "This will read an MPS format file from the given file name.  It will use the default directory given by 'directory'.  A name of '$' will use the previous value for the name.  This is initialized to '', i.e., it must be set.  If you have libgz then it can read compressed files 'xxxxxxxx.gz'."
384        ) ;
385  parameters.push_back(param) ;
386
387  param = new CbcGenParam(CbcGenParam::SOLVECONTINUOUS,"initialS!olve",
388                          "Solve to continuous optimum") ;
389  param->setObj(ctlBlk) ;
390  param->setLongHelp(
391        "This just solves the problem to the continuous optimum, without adding any cuts."
392        ) ;
393  parameters.push_back(param) ;
394
395  param = new CbcGenParam(CbcGenParam::MESSAGES,"mess!ages",
396        "Controls whether standardised message prefix is printed","off",0) ;
397  param->appendKwd("on") ;
398  param->setObj(ctlBlk) ;
399  param->setLongHelp(
400        "By default, messages have a standard prefix, such as:\n   Clp0005 2261  Objective 109.024 Primal infeas 944413 (758)\nbut this program turns this off to make it look more friendly.  It can be useful to turn them back on if you want to be able to 'grep' for particular messages or if you intend to override the behavior of a particular message."
401        ) ;
402  parameters.push_back(param) ;
403
404  param = new CbcGenParam(CbcGenParam::MIPLIB,
405                          "miplib","Do some of miplib test set") ;
406  parameters.push_back(param) ;
407
408
409  param = new CbcGenParam(CbcGenParam::OUTDUPROWS,
410        "outDup!licates",
411        "Takes duplicate rows, etc., out of the integer model",false) ;
412  parameters.push_back(param) ;
413
414  param = new CbcGenParam(CbcGenParam::OUTPUTFORMAT,
415        "output!Format","Which output format to use",1,6,2) ;
416  param->setObj(ctlBlk) ;
417  param->setLongHelp(
418        "Normally export will be done using normal representation for numbers and two values per line.  You may want to do just one per line (for grep or suchlike) and you may wish to save with absolute accuracy using a coded version of the IEEE value. A value of 2 is normal. Otherwise, odd values give one value per line, even values two.  Values of 1 and 2 give normal format, 3 and 4 give greater precision, 5 and 6 give IEEE values.  When exporting a basis, 1 does not save values, 2 saves values, 3 saves with greater accuracy and 4 saves in IEEE format."
419        ) ;
420  parameters.push_back(param) ;
421
422/*
423  In order for initialisation to work properly, the order of the keywords here
424  must match the order of the enum IPPControl in CbcGenCtlBlk.hpp.
425*/
426  param = new CbcGenParam(CbcGenParam::PREPROCESS,
427        "preprocess","Whether to use integer preprocessing","off",
428        ctlBlk->preProcess_) ;
429  param->appendKwd("on") ;
430  param->appendKwd("save") ;
431  param->appendKwd("equal") ;
432  param->appendKwd("sos") ;
433  param->appendKwd("trysos") ;
434  param->appendKwd("equalall") ;
435  param->appendKwd("strategy") ;
436  param->setObj(ctlBlk) ;
437  param->setPushFunc(pushCbcGenKwdParam) ;
438  param->setLongHelp(
439        "This tries to reduce size of the model in a similar way to presolve and it also tries to strengthen the model. This can be very useful and is worth trying.  save option saves on file presolved.mps.  equal will turn <= cliques into ==.  sos will create sos sets if all 0-1 in sets (well one extra is allowed) and no overlaps.  trysos is same but allows any number extra. equalall will turn all valid inequalities into equalities with integer slacks. strategy is as on but uses CbcStrategy."
440        ) ;
441  parameters.push_back(param) ;
442
443  param = new CbcGenParam(CbcGenParam::PRINTOPTIONS,
444        "pO!ptions","Dubious print options",0,COIN_INT_MAX,0,false) ;
445  param->setObj(ctlBlk) ;
446  param->setPushFunc(pushCbcGenIntParam) ;
447  param->setLongHelp(
448        "If this is greater than 0 then presolve will give more information and branch and cut will give statistics"
449        ) ; 
450  parameters.push_back(param) ;
451
452  param = new CbcGenParam(CbcGenParam::PROBINGCUTS,
453        "probing!Cuts","Whether to use Probing cuts","off",
454        ctlBlk->probing_.action_) ;
455  param->appendKwd("on") ;
456  param->appendKwd("root") ;
457  param->appendKwd("ifmove") ;
458  param->appendKwd("forceOn") ;
459  param->appendKwd("forceOnBut") ;
460  param->setObj(ctlBlk) ;
461  param->setPushFunc(pushCbcGenCutParam) ;
462  param->setLongHelp(
463        "This switches on probing cuts (either at root or in entire tree). See branchAndCut for information on options."
464        ) ;
465  parameters.push_back(param) ;
466
467  param = new CbcGenParam(CbcGenParam::INTPRINT,
468                          "printi!ngOptions","Print options","normal",0) ;
469  param->appendKwd("integer") ;
470  param->appendKwd("special") ;
471  param->appendKwd("rows") ;
472  param->appendKwd("all") ;
473  param->setPushFunc(pushCbcGenKwdParam) ;
474  param->setObj(ctlBlk) ;
475  param->setLongHelp(
476        "This changes the amount and format of printing a solution:\nnormal - nonzero column variables \ninteger - nonzero integer column variables\nspecial - in format suitable for OsiRowCutDebugger\nrows - nonzero column variables and row activities\nall - all column variables and row activities.\n\nFor non-integer problems 'integer' and 'special' act like 'normal'.  Also see printMask for controlling output."
477        ) ;
478  parameters.push_back(param) ;
479
480  param = new CbcGenParam(CbcGenParam::PRINTMASK,
481        "printM!ask",
482        "Control printing of solution with a regular expression",empty) ;
483  param->setPushFunc(doPrintMaskParam) ;
484  param->setObj(ctlBlk) ;
485  param->setLongHelp(
486        "If set then only those names which match mask are printed in a solution. '?' matches any character and '*' matches any set of characters.  The default is '' (unset) so all variables are printed. This is only active if model has names."
487        ) ;
488  parameters.push_back(param) ;
489
490  param = new CbcGenParam(CbcGenParam::PRIORITYIN,
491        "prio!rityIn","Import priorities etc from file",empty) ;
492  param->setObj(ctlBlk) ;
493  param->setLongHelp(
494        "This will read a file with priorities from the given file name.  It will use the default directory given by 'directory'.  A name of '$' will use the previous value for the name.  This is initialized to '', i.e. it must be set.  This can not read from compressed files. File is in csv format with allowed headings - name, number, priority, direction, up, down, solution.  Exactly one of name and number must be given."
495        ) ;
496  parameters.push_back(param) ;
497
498  param = new CbcGenParam(CbcGenParam::REDSPLITCUTS,
499        "reduce!AndSplitCuts",
500        "Whether to use Reduce-and-Split cuts","off",
501        ctlBlk->redSplit_.action_) ;
502  param->appendKwd("on") ;
503  param->appendKwd("root") ;
504  param->appendKwd("ifmove") ;
505  param->appendKwd("forceOn") ;
506  param->setObj(ctlBlk) ;
507  param->setPushFunc(pushCbcGenCutParam) ;
508  param->setLongHelp(
509        "This switches on reduce and split cuts (either at root or in entire tree). See branchAndCut for information on options."
510        ) ;
511  parameters.push_back(param) ;
512
513  param = new CbcGenParam(CbcGenParam::ROUNDING,
514        "round!ingHeuristic","Whether to use Rounding heuristic","off",
515        ctlBlk->rounding_.action_) ;
516  param->appendKwd("on") ;
517  param->setObj(ctlBlk) ;
518  param->setLongHelp(
519        "This switches on a simple (but effective) rounding heuristic at each node of tree."
520        ) ;
521  parameters.push_back(param) ;
522
523
524  param = new CbcGenParam(CbcGenParam::EXIT,"quit","Stops execution") ;
525  param->setPushFunc(doExitParam) ;
526  param->setObj(ctlBlk) ;
527  param->setLongHelp(
528        "This stops execution; end, exit, quit and stop are synonyms."
529        ) ;
530  parameters.push_back(param) ;
531
532  param = new CbcGenParam(CbcGenParam::DUMMY,
533                          "sleep","for debug",0,9999,0,false) ;
534  param->setObj(ctlBlk) ;
535  param->setLongHelp(
536        "If passed to solver from ampl, then ampl will wait so that you can copy .nl file for debug."
537        ) ;
538  parameters.push_back(param) ;
539
540  param = new CbcGenParam(CbcGenParam::SOLUTION,
541                          "solu!tion","Prints solution to file",
542                          std::string("stdout")) ;
543  param->setPushFunc(doSolutionParam) ;
544  param->setObj(ctlBlk) ;
545  param->setLongHelp(
546        "This will write a primitive solution file to the given file name.  It will use the default directory given by 'directory'.  A name of '$' will use the previous value for the name.  This is initialized to 'stdout'.  The amount of output can be varied using printi!ngOptions or printMask."
547        ) ;
548  parameters.push_back(param) ;
549
550  param = new CbcGenParam ;
551  CbcGenSolvers::setupSolverParam(*param) ;
552  param->setObj(ctlBlk) ;
553  parameters.push_back(param) ;
554
555  param = new CbcGenParam(CbcGenParam::SOS,
556        "sos!Options","Whether to use SOS from AMPL","off",0) ;
557  param->appendKwd("on") ;
558  param->setObj(ctlBlk) ;
559  param->setLongHelp(
560        "Normally if AMPL says there are SOS variables they should be used, but sometimes they should be turned off - this does so."
561        ) ; 
562  parameters.push_back(param) ;
563
564  param = new CbcGenParam(CbcGenParam::EXIT,"stop","Stops execution") ;
565  param->setPushFunc(doExitParam) ;
566  param->setObj(ctlBlk) ;
567  param->setLongHelp(
568        "This stops execution; end, exit, quit and stop are synonyms."
569        ) ;
570  parameters.push_back(param) ;
571
572  param = new CbcGenParam(CbcGenParam::STRENGTHEN,
573                          "strengthen","Create strengthened problem") ;
574  param->setObj(ctlBlk) ;
575  param->setLongHelp(
576        "This creates a new problem by applying the root node cuts. All tight constraints will be in resulting problem."
577        ) ;
578  parameters.push_back(param) ;
579
580  param = new CbcGenParam(CbcGenParam::TIGHTENFACTOR,"tighten!Factor",
581        "Tighten bounds using value times largest activity at continuous solution",
582        1.0,1.0e20) ;
583  param->setObj(ctlBlk) ;
584  param->setLongHelp(
585        "This sleazy trick can help on some problems."
586        ) ;
587  parameters.push_back(param) ;
588
589  param = new CbcGenParam(CbcGenParam::TWOMIRCUTS,
590        "two!MirCuts",
591        "Whether to use Two phase Mixed Integer Rounding cuts","off",
592        ctlBlk->twomir_.action_) ;
593  param->appendKwd("on") ;
594  param->appendKwd("root") ;
595  param->appendKwd("ifmove") ;
596  param->appendKwd("forceOn") ;
597  param->setObj(ctlBlk) ;
598  param->setPushFunc(pushCbcGenCutParam) ;
599  param->setLongHelp(
600        "This switches on two phase mixed integer rounding cuts (either at root or in entire tree). See branchAndCut for information on options."
601        ) ;
602  parameters.push_back(param) ;
603
604  param = new CbcGenParam(CbcGenParam::UNITTEST,"unitTest","Do unit test") ;
605  param->setObj(ctlBlk) ;
606  param->setLongHelp(
607        "This exercises the unit test."
608        ) ;
609  parameters.push_back(param) ;
610
611  param = new CbcGenParam(CbcGenParam::USERCBC,
612                          "userCbc","Hand coded Cbc stuff",0,COIN_INT_MAX,0,false) ;
613  param->setObj(ctlBlk) ;
614  param->setLongHelp(
615        "There are times (e.g., when using AMPL interface) when you may wish to do something unusual.  Look for USERCBC in main driver and modify sample code."
616        ) ;
617  parameters.push_back(param) ;
618
619  param = new CbcGenParam(CbcGenParam::VERBOSE,
620        "verbose","Switches on longer help on single ?",
621        0,15,ctlBlk->verbose_,false) ;
622  param->setPushFunc(pushCbcGenIntParam) ;
623  param->setObj(ctlBlk) ;
624  param->setLongHelp(
625        "Set to 1 to get short help with ? list, 2 to get long help."
626        ) ;
627  parameters.push_back(param) ;
628
629  param = new CbcGenParam(CbcGenParam::SHOWUNIMP,
630        "unimp!lemented","Report unimplemented commands.",false) ;
631  param->setPushFunc(doUnimplementedParam) ;
632  param->setObj(ctlBlk) ;
633  parameters.push_back(param) ;
634
635  numberParameters = parameters.size() ;
636  assert (((unsigned) numberParameters) <= parameters.capacity()) ;
637
638  return ; }
639
640
641void loadGenParamObj (const CoinParamVec paramVec, int first, int last,
642                      CbcGenCtlBlk *ctlBlk)
643
644{ int i ;
645/*
646  Load the cbc-generic object into the parameters
647*/
648  for (i = first ; i <= last ; i++)
649  { CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(paramVec[i]) ;
650    assert (genParam != 0) ;
651    genParam->setObj(ctlBlk) ; }
652
653  return ; }
654
655
656/* Functions to implement  cbc-generic (CbcGenParam) parameters */
657
658/*
659  Maintainer's utility, scan the parameters and report the ones that are
660  unimplemented (i.e., have no pushFunc).
661*/
662
663int doUnimplementedParam (CoinParam *param)
664
665{ assert (param != 0) ;
666
667  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
668  assert (genParam != 0) ;
669
670  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
671  assert (ctlBlk != 0) ;
672
673  assert (ctlBlk->paramVec_ != 0) ;
674  CoinParamVec &paramVec = *ctlBlk->paramVec_ ;
675
676  int unimpCnt = 0 ;
677  int maxAcross = 5 ;
678  for (unsigned i = 0 ; i < paramVec.size() ; i++)
679  { CoinParam *param = paramVec[i] ;
680    if (param->pushFunc() == 0)
681    { if (unimpCnt%maxAcross == 0)
682      { std::cout << std::endl ; }
683      else
684      { std::cout << " " ; }
685      std::cout << param->name() ;
686      unimpCnt++ ; } }
687  if (unimpCnt%maxAcross != 1)
688  { std::cout << std::endl ; }
689  std::cout << unimpCnt << " unimplemented parameters." << std::endl ;
690
691  return (0) ; }
692
693
694/*
695  Noop function. Mainly to eliminate commands from the list returned by
696  doUnimplmentedParam.
697*/
698
699int doNothingParam (CoinParam *param)
700{
701  return (0) ;
702}
703
704/*
705  Function to terminate command parsing by returning -1.
706*/
707
708int doExitParam (CoinParam *param)
709
710{
711  return (-1) ;
712}
713
714/*
715  Function to print the current version.
716*/
717
718int doVersionParam (CoinParam *param)
719
720{ assert (param != 0) ;
721  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
722  assert (genParam != 0) ;
723  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
724  assert (ctlBlk != 0) ;
725
726  std::cout << "cbc-generic version " << ctlBlk->version_ << std::endl ;
727  std::cout
728    << "cbc-generic is experimental software. If you want a stable MIP "
729    << "solver, please" << std::endl
730    << "use cbc. If you discover bugs while using cbc-generic "
731    << "please specify" << std::endl
732    << "cbc-generic in the ticket description or email subject line."
733    << std::endl ;
734
735  return (0) ; }
736
737/*
738  Function to handle help (HELP), `?' (GENERALQUERY), and `???'
739  (FULLGENERALQUERY).
740*/
741
742int doHelpParam (CoinParam *param)
743
744{ assert (param != 0) ;
745  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
746  assert (genParam != 0) ;
747  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
748  assert (ctlBlk != 0) ;
749
750  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
751
752  int verbose = ctlBlk->verbose_ ;
753  bool shortHelp = ((verbose&0x01)?true:false) ;
754  bool longHelp = ((verbose&0x02)?true:false) ;
755  bool hidden = ((verbose&0x08)?true:false) ;
756
757  CoinParamVec *paramVec = ctlBlk->paramVec_ ;
758  assert (paramVec != 0) ;
759/*
760  Tune up the initial settings. FULLGENERALQUERY will print normally hidden
761  params, and a request for long help overrules a request for short help.
762*/
763  if (code == CbcGenParam::FULLGENERALQUERY)
764  { hidden = true ; }
765  if (longHelp)
766  { shortHelp = false ; }
767
768  CoinParamUtils::printGenericHelp() ;
769
770  std::cout << "\nAvailable commands are:" ;
771  std::string pfx("  ") ;
772  CoinParamUtils::printHelp(*paramVec,0,paramVec->size()-1,pfx,
773                            shortHelp,longHelp,hidden) ;
774 
775  return (0) ; }
776
777/*
778  Function to push a double-valued parameter.
779*/
780
781int pushCbcGenDblParam (CoinParam *param)
782
783{ assert (param != 0) ;
784  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
785  assert (genParam != 0) ;
786  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
787  assert (ctlBlk != 0) ;
788
789  double val = genParam->dblVal() ;
790  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
791
792  int retval = 0 ;
793/*
794  Figure out what we're doing and set the relevant field.
795*/
796  switch (code)
797  { case CbcGenParam::DJFIX:
798    { ctlBlk->djFix_.action_ = true ;
799      ctlBlk->djFix_.threshold_ = val ;
800      break ; }
801    default:
802    { std::cerr << "pushCbcGenDbl: no equivalent CbcGenCtlBlk field for "
803                << "parameter code `" << code << "'." << std::endl ;
804      retval = -1 ;
805      break ; } }
806
807  return (retval) ; }
808
809/*
810  Function to push an integer-valued parameter.
811*/
812
813int pushCbcGenIntParam (CoinParam *param)
814
815{ assert (param != 0) ;
816  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
817  assert (genParam != 0) ;
818  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
819  assert (ctlBlk != 0) ;
820
821  int val = genParam->intVal() ;
822  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
823
824  int retval = 0 ;
825/*
826  Figure out what we're doing and set the relevant field.
827*/
828  switch (code)
829  { case CbcGenParam::CUTDEPTH:
830    { ctlBlk->setCutDepth(val) ;
831      break ; }
832    case CbcGenParam::LOGLEVEL:
833    { ctlBlk->setLogLevel(val) ;
834      break ; }
835    case CbcGenParam::PRINTOPTIONS:
836    { ctlBlk->printOpt_ = val ;
837      break ; }
838    case CbcGenParam::VERBOSE:
839    { ctlBlk->verbose_ = val ;
840      break ; }
841    default:
842    { std::cerr << "pushCbcGenInt: no equivalent CbcGenCtlBlk field for "
843                << "parameter code `" << code << "'." << std::endl ;
844      retval = -1 ;
845      break ; } }
846
847  return (retval) ; }
848
849
850/*
851  Function to push a keyword-valued parameter. This is the catch-all function
852  for keyword parameters that don't belong to any other useful grouping.
853*/
854
855int pushCbcGenKwdParam (CoinParam *param)
856
857{ assert (param != 0) ;
858  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
859  assert (genParam != 0) ;
860  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
861  assert (ctlBlk != 0) ;
862
863  std::string str = genParam->kwdVal() ;
864  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
865
866  int retval = 0 ;
867/*
868  Figure out what we're doing and set the relevant field.
869*/
870  switch (code)
871  { case CbcGenParam::PREPROCESS:
872    { if (str == "off")
873      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPOff) ; }
874      else
875      if (str == "on")
876      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPOn) ; }
877      else
878      if (str == "save")
879      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPSave) ; }
880      else
881      if (str == "equal")
882      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPEqual) ; }
883      else
884      if (str == "sos")
885      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPSOS) ; }
886      else
887      if (str == "trysos")
888      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPTrySOS) ; }
889      else
890      if (str == "equalall")
891      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPEqualAll) ; }
892      else
893      if (str == "strategy")
894      { ctlBlk->setIPPAction(CbcGenCtlBlk::IPPStrategy) ; }
895      else
896      { std::cerr
897          << "pushCbcGenKwdParam(PREPROCESS): unrecognised keyword `"
898          << str << "'." << std::endl ;
899        retval = -1 ; }
900      break ; }
901    case CbcGenParam::COSTSTRATEGY:
902    { if (str == "off")
903      { ctlBlk->priorityAction_ = CbcGenCtlBlk::BPOff ; }
904      else
905      if (str == "priorities")
906      { ctlBlk->priorityAction_ = CbcGenCtlBlk::BPCost ; }
907      if (str == "columnOrder")
908      { ctlBlk->priorityAction_ = CbcGenCtlBlk::BPOrder ; }
909      else
910      { std::cerr
911          << "pushCbcGenKwdParam(COSTSTRATEGY): unrecognised keyword `"
912          << str << "'." << std::endl ;
913        retval = -1 ; }
914      break ; }
915    case CbcGenParam::INTPRINT:
916    { if (str == "normal")
917      { ctlBlk->printMode_ = 0 ; }
918      else
919      if (str == "integer")
920      { ctlBlk->printMode_ = 1 ; }
921      else
922      if (str == "special")
923      { ctlBlk->printMode_ = 2 ; }
924      else
925      if (str == "rows")
926      { ctlBlk->printMode_ = 3 ; }
927      else
928      if (str == "all")
929      { ctlBlk->printMode_ = 4 ; }
930      else
931      { std::cerr
932          << "pushCbcGenKwdParam(INTPRINT): unrecognised keyword `"
933          << str << "'." << std::endl ;
934        retval = -1 ; }
935      break ; }
936    default:
937    { std::cerr
938        << "pushCbcGenKwdParam: unrecognised parameter code `"
939        << code << "'." << std::endl ;
940      retval = -1 ;
941      break ; } }
942
943  return (retval) ; }
944
945/*
946  Function to push a string-valued parameter
947*/
948
949int pushCbcGenStrParam (CoinParam *param)
950
951{ assert (param != 0) ;
952  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
953  assert (genParam != 0) ;
954  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
955  assert (ctlBlk != 0) ;
956
957  std::string str = genParam->strVal() ;
958  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
959
960  int retval = 0 ;
961/*
962  Figure out what we're doing and set the relevant field.
963*/
964  switch (code)
965  { case CbcGenParam::DIRECTORY:
966    { char dirSep = CoinFindDirSeparator() ;
967      if (str[str.length()-1] != dirSep)
968      { str += dirSep ; }
969      ctlBlk->dfltDirectory_ = str ;
970      break ; }
971    default:
972    { std::cerr << "pushCbcGenStr: no equivalent CbcGenCtlBlk field for "
973                << "parameter code `" << code << "'." << std::endl ;
974      retval = -1 ;
975      break ; } }
976
977  return (retval) ; }
978
979/*
980  The various parameters to control cut generators can be
981  grouped, as they all use the same set of keywords.
982*/
983int pushCbcGenCutParam (CoinParam *param)
984
985{ assert (param != 0) ;
986  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
987  assert (genParam != 0) ;
988  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
989  assert (ctlBlk != 0) ;
990
991  std::string str = genParam->kwdVal() ;
992  CbcGenParam::CbcGenParamCode code = genParam->paramCode() ;
993/*
994  Setup to return nonfatal/fatal error (1/-1) by default, so that all we need
995  to do is correct to 0 (no error) if we're successful.
996*/
997  int retval ;
998  if (CoinParamUtils::isInteractive())
999  { retval = 1 ; }
1000  else
1001  { retval = -1 ; }
1002/*
1003  First translate the keyword into the correct CGControl enum value.
1004*/
1005  CbcGenCtlBlk::CGControl action ;
1006  if (str == "off")
1007  { action = CbcGenCtlBlk::CGOff ; }
1008  else
1009  if (str == "on")
1010  { action = CbcGenCtlBlk::CGOn ; }
1011  else
1012  if (str == "root")
1013  { action = CbcGenCtlBlk::CGRoot ; }
1014  else
1015  if (str == "ifmove")
1016  { action = CbcGenCtlBlk::CGIfMove ; }
1017  else
1018  if (str == "forceOn")
1019  { action = CbcGenCtlBlk::CGForceOn ; }
1020  else
1021  if (str == "forceOnBut")
1022  { action = CbcGenCtlBlk::CGForceBut ; }
1023  else
1024  { std::cerr
1025      << "pushCbcGenCutParam: unrecognised keyword `"
1026      << str << "'." << std::endl ;
1027    return (retval) ; }
1028/*
1029  Validate the parameter code and set a variable to separate cuts from
1030  heuristics.
1031*/
1032  bool isCut = false ;
1033  bool isHeuristic = false ;
1034  switch (code)
1035  { case CbcGenParam::CLIQUECUTS:
1036    case CbcGenParam::FLOWCUTS:
1037    case CbcGenParam::GOMORYCUTS:
1038    case CbcGenParam::KNAPSACKCUTS:
1039    case CbcGenParam::MIXEDCUTS:
1040    case CbcGenParam::PROBINGCUTS:
1041    case CbcGenParam::REDSPLITCUTS:
1042    case CbcGenParam::TWOMIRCUTS:
1043    case CbcGenParam::CUTSTRATEGY:
1044    { isCut = true ; 
1045      break ; }
1046    case CbcGenParam::COMBINE:
1047    case CbcGenParam::FPUMP:
1048    case CbcGenParam::ROUNDING:
1049    case CbcGenParam::LOCALTREE:
1050    case CbcGenParam::HEURISTICSTRATEGY:
1051    { isHeuristic = true ; 
1052      break ; }
1053    default:
1054    { std::cerr
1055        << "pushCbcGenCutParam: unrecognised parameter code `"
1056        << code << "'." << std::endl ;
1057      return (retval) ; } }
1058/*
1059  See if the action is valid for the specified type. Heuristics are on or
1060  off; cuts can be any of the other codes. Only probing can use forceOnBut.
1061*/
1062  if (isHeuristic)
1063  { if (!(action == CbcGenCtlBlk::CGOff || action == CbcGenCtlBlk::CGOn))
1064    { std::cerr
1065        << "pushCbcGenCutParam: only on or off is valid for a heuristic."
1066        << std::endl ;
1067      return (retval) ; } }
1068  else
1069  if (isCut)
1070  { if (action == CbcGenCtlBlk::CGForceBut &&
1071        code != CbcGenParam::PROBINGCUTS)
1072    { std::cerr
1073        << "pushCbcGenCutParam: forceOnBut is valid only for probing."
1074        << std::endl ;
1075      return (retval) ; } }
1076/*
1077  We've done the basic checks; go ahead and set the relevant field in the
1078  control block. We shouldn't need the default case, but some compilers will
1079  complain if it's missing.
1080*/
1081  switch (code)
1082  { case CbcGenParam::CLIQUECUTS:
1083    { ctlBlk->setCliqueAction(action) ;
1084      break ; }
1085    case CbcGenParam::FLOWCUTS:
1086    { ctlBlk->setFlowAction(action) ;
1087      break ; }
1088    case CbcGenParam::GOMORYCUTS:
1089    { ctlBlk->setGomoryAction(action) ;
1090      break ; }
1091    case CbcGenParam::KNAPSACKCUTS:
1092    { ctlBlk->setKnapsackAction(action) ;
1093      break ; }
1094    case CbcGenParam::MIXEDCUTS:
1095    { ctlBlk->setMirAction(action) ;
1096      break ; }
1097    case CbcGenParam::PROBINGCUTS:
1098    { ctlBlk->setProbingAction(action) ;
1099      break ; }
1100    case CbcGenParam::REDSPLITCUTS:
1101    { ctlBlk->setRedSplitAction(action) ;
1102      break ; }
1103    case CbcGenParam::TWOMIRCUTS:
1104    { ctlBlk->setTwomirAction(action) ;
1105      break ; }
1106    case CbcGenParam::CUTSTRATEGY:
1107    { ctlBlk->setCliqueAction(action) ;
1108      ctlBlk->setFlowAction(action) ;
1109      ctlBlk->setGomoryAction(action) ;
1110      ctlBlk->setKnapsackAction(action) ;
1111      ctlBlk->setMirAction(action) ;
1112      ctlBlk->setProbingAction(action) ;
1113      ctlBlk->setRedSplitAction(action) ;
1114      ctlBlk->setTwomirAction(action) ;
1115      break ; }
1116    case CbcGenParam::COMBINE:
1117    { ctlBlk->setCombineAction(action) ;
1118      break ; }
1119    case CbcGenParam::FPUMP:
1120    { ctlBlk->setFPumpAction(action) ;
1121      break ; }
1122    case CbcGenParam::GREEDY:
1123    { ctlBlk->setGreedyCoverAction(action) ;
1124      ctlBlk->setGreedyEqualityAction(action) ;
1125      break ; }
1126    case CbcGenParam::LOCALTREE:
1127    { ctlBlk->setTreeLocalAction(action) ;
1128      break ; }
1129    case CbcGenParam::ROUNDING:
1130    { ctlBlk->setRoundingAction(action) ;
1131      break ; }
1132    case CbcGenParam::HEURISTICSTRATEGY:
1133    { ctlBlk->setCombineAction(action) ;
1134      ctlBlk->setFPumpAction(action) ;
1135      ctlBlk->setGreedyCoverAction(action) ;
1136      ctlBlk->setRoundingAction(action) ;
1137      ctlBlk->setTreeLocalAction(action) ;
1138      break ; }
1139    default:
1140    { std::cerr
1141        << "pushCbcGenCutParam: internal confusion!" << std::endl ;
1142      return (-1) ; } }
1143
1144  return (0) ; }
1145
1146/*
1147  This routine imports a new constraint system into the solver.
1148*/
1149
1150int doImportParam (CoinParam *param)
1151
1152{ assert (param != 0) ;
1153  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
1154  assert (genParam != 0) ;
1155  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
1156  assert (ctlBlk != 0) ;
1157/*
1158  Setup to return nonfatal/fatal error (1/-1) by default, so that all we need
1159  to do is correct to 0 (no error) if we're successful.
1160*/
1161  int retval ;
1162  if (CoinParamUtils::isInteractive())
1163  { retval = 1 ; }
1164  else
1165  { retval = -1 ; }
1166/*
1167  Figure out where we're going to acquire this new model. As special cases,
1168  `$' says `use the previous input source' and `-' says `use stdin'.
1169*/
1170  std::string field = genParam->strVal() ;
1171  std::string fileName ;
1172  if (field == "$")
1173  { fileName = ctlBlk->lastMpsIn_ ;
1174    field = fileName ; }
1175  else
1176  if (field == "-")
1177  { fileName = "stdin" ;
1178    field = fileName ; }
1179  else
1180  { fileName = field ; }
1181/*
1182  See if we can open a file. fileCoinReadable understands a fair bit about
1183  platforms and compressed files and will try variations of the file name
1184  (see the doxygen doc'n for details). The file name returned in field wil
1185  be the one that actually worked.
1186*/
1187  bool canOpen = fileCoinReadable(fileName,ctlBlk->dfltDirectory_) ;
1188  if (canOpen == false)
1189  { std::cout
1190      << "Unable to open file `" << fileName
1191      << "', original name '" << genParam->strVal() <<"'." << std::endl ;
1192    return (retval) ; }
1193/*
1194  We can find the file. Record the name. This requires a little finesse: what
1195  we want is the base file name (and extension(s), if present) but not the
1196  prefix, unless it's an absolute path.
1197*/
1198  if (!fileAbsPath(fileName))
1199  { std::string::size_type pos = fileName.rfind(field) ;
1200    ctlBlk->lastMpsIn_ = fileName.substr(pos) ; }
1201  else
1202  { ctlBlk->lastMpsIn_ = fileName ; }
1203/*
1204  Try to read the file. Standard OSI doesn't support the Clp extensions for
1205  keepImportNames and allowImportErrors. It should at least support
1206  keepImportNames. Status will be zero for a successful read.
1207*/
1208  OsiSolverInterface *lpSolver = ctlBlk->model_->solver() ;
1209  int status = lpSolver->readMps(fileName.c_str(),"") ;
1210  if (status)
1211  { std::cout
1212      << "There were "<< status << " errors on input." << std::endl ;
1213    return (retval) ; }
1214/*
1215  We have a model! Return success.
1216*/
1217  ctlBlk->goodModel_ = true ;
1218
1219  return (0) ; }
1220
1221
1222/*
1223  This routine imports a debug file into the solver, or arranges for its
1224  creation. Import works in the standard way, using the file name provided
1225  with the command.
1226
1227  As special cases, if the file name is `create' or `createAfterPre', the
1228  action here sets up to cause a debug file containing the solution to be
1229  dumped after branch-and-cut is completed.  `createAfterPre' will dump the
1230  solution before undoing the presolve transforms.  `create' will dump the
1231  solution after integer presolve is backed out.
1232*/
1233
1234int doDebugParam (CoinParam *param)
1235
1236{ assert (param != 0) ;
1237  CbcGenParam *genParam = dynamic_cast<CbcGenParam *>(param) ;
1238  assert (genParam != 0) ;
1239  CbcGenCtlBlk *ctlBlk = genParam->obj() ;
1240  assert (ctlBlk != 0) ;
1241/*
1242  Setup to return nonfatal/fatal error (1/-1) by default, so that all we need
1243  to do is correct to 0 (no error) if we're successful.
1244*/
1245  int retval ;
1246  if (CoinParamUtils::isInteractive())
1247  { retval = 1 ; }
1248  else
1249  { retval = -1 ; }
1250/*
1251   If the file name is `create' or `createAfterPre', we're just setting up to
1252   make a debug file the next time we do branch-and-cut.
1253*/
1254  std::string field = genParam->strVal() ;
1255  if (field == "create" || field == "createAfterPre")
1256  { ctlBlk->debugCreate_ = field ;
1257    return (0) ; }
1258/*
1259  Figure out where we're going to acquire the debug file. As special cases,
1260  `$' says `use the previous input source' and `-' says `use stdin'.
1261*/
1262  std::string fileName ;
1263  if (field == "$")
1264  { fileName = ctlBlk->debugFile_ ;
1265    field = fileName ; }
1266  else
1267  if (field == "-")
1268  { fileName = "stdin" ;
1269    field = fileName ; }
1270  else
1271  { fileName = field ; }
1272/*
1273  See if we can open a file. fileCoinReadable understands a fair bit about
1274  platforms and compressed files and will try variations of the file name
1275  (see the doxygen doc'n for details). The file name returned in field wil be
1276  the one that actually worked. No default prefix --- a debug file is assumed
1277  to always be in the current directory.
1278*/
1279  bool canOpen = fileCoinReadable(fileName,ctlBlk->dfltDirectory_) ;
1280  if (canOpen == false)
1281  { std::cout
1282      << "Unable to open file `" << fileName
1283      << "', original name '" << genParam->strVal() <<"'." << std::endl ;
1284    return (retval) ; }
1285/*
1286  We can find the file. Record the name. This requires a little finesse: what
1287  we want is the base file name (and extension(s), if present) but not the
1288  prefix, unless it's an absolute path.
1289*/
1290  if (!fileAbsPath(fileName))
1291  { std::string::size_type pos = fileName.rfind(field) ;
1292    ctlBlk->lastMpsIn_ = fileName.substr(pos) ; }
1293  else
1294  { ctlBlk->lastMpsIn_ = fileName ; }
1295/*
1296  Load the primal variable values into the debug solution vector.
1297*/
1298  int intUnused,numCols ;
1299  double dblUnused ;
1300  double *primals ;
1301
1302  bool readOK = readSolution(fileName,
1303                             intUnused,numCols,dblUnused,0,0,&primals,0) ;
1304 
1305  if (readOK)
1306  { if (ctlBlk->debugSol_.values_)
1307    { delete[] ctlBlk->debugSol_.values_ ; }
1308    ctlBlk->debugSol_.numCols_ = numCols ;
1309    ctlBlk->debugSol_.values_ = primals ;
1310    retval = 0 ; }
1311  else
1312  { if (primals)
1313    { delete[] primals ; } }
1314
1315  return (retval) ; }
1316
1317
1318/*
1319  Utility routine to save the current solution to a file. No formatting, and
1320  not intended to be portable in any way, shape, or form.
1321*/
1322
1323void saveSolution (const OsiSolverInterface *osi, std::string fileName)
1324
1325{ FILE *fp = fopen(fileName.c_str(),"wb") ;
1326
1327  if (fp)
1328  { int numberRows = osi->getNumRows() ;
1329    int numberColumns = osi->getNumCols() ;
1330    double objectiveValue = osi->getObjValue() ;
1331
1332    fwrite(&numberRows,sizeof(int),1,fp) ;
1333    fwrite(&numberColumns,sizeof(int),1,fp) ;
1334    fwrite(&objectiveValue,sizeof(double),1,fp) ;
1335
1336    const double *primalRowSolution = osi->getRowActivity() ;
1337    const double *dualRowSolution = osi->getRowPrice() ;
1338    const double *primalColumnSolution = osi->getColSolution() ;
1339    const double *dualColumnSolution = osi->getReducedCost() ;
1340
1341    fwrite(primalRowSolution,sizeof(double),numberRows,fp) ;
1342    fwrite(dualRowSolution,sizeof(double),numberRows,fp) ;
1343    fwrite(primalColumnSolution,sizeof(double),numberColumns,fp) ;
1344    fwrite(dualColumnSolution,sizeof(double),numberColumns,fp) ;
1345
1346    fclose(fp) ; }
1347  else
1348  { std::cout
1349      << "saveSolution: Unable to open file `"
1350      << fileName << "'." << std::endl ; }
1351 
1352  return ; }
1353
1354/*
1355  Utility routine to read in a solution dump created by saveSolution. Generally
1356  we don't need all the info in this file, so the routine accepts a bunch of
1357  reference/pointer paramaters and fills in any that are non-null. It's the
1358  client's responsibility to dispose of space allocated for solution vectors.
1359  The parameters fileName, numRows, numCols, and objVal are mandatory. The rest
1360  can be null.
1361*/
1362bool readSolution (std::string fileName,
1363                   int &numRows, int &numCols, double &objVal,
1364                   double **rowActivity, double **dualVars,
1365                   double **primalVars, double **reducedCosts)
1366
1367{ FILE *fp = fopen(fileName.c_str(),"rb") ;
1368  bool retval = true ;
1369
1370  numRows = -1 ;
1371  numCols = -1 ;
1372  objVal = 0 ;
1373  *rowActivity = 0 ;
1374  *dualVars = 0 ;
1375  *primalVars = 0 ;
1376  *reducedCosts = 0 ;
1377
1378  if (fp)
1379  { fread(&numRows,sizeof(int),1,fp) ;
1380    fread(&numCols,sizeof(int),1,fp) ;
1381    fread(&objVal,sizeof(double),1,fp) ;
1382
1383    if (rowActivity != NULL)
1384    { *rowActivity = new double [numRows] ;
1385      fread(*rowActivity,sizeof(double),numRows,fp) ; }
1386    else
1387    { fseek(fp,numRows*sizeof(double),SEEK_CUR) ; }
1388
1389    if (dualVars != NULL)
1390    { *dualVars = new double [numRows] ;
1391      fread(*dualVars,sizeof(double),numRows,fp) ; }
1392    else
1393    { fseek(fp,numRows*sizeof(double),SEEK_CUR) ; }
1394
1395    if (primalVars != NULL)
1396    { *primalVars = new double [numCols] ;
1397      fread(*primalVars,sizeof(double),numCols,fp) ; }
1398    else
1399    { fseek(fp,numCols*sizeof(double),SEEK_CUR) ; }
1400
1401    if (reducedCosts != NULL)
1402    { *reducedCosts = new double [numCols] ;
1403      fread(*reducedCosts,sizeof(double),numCols,fp) ; }
1404    else
1405    { fseek(fp,numCols*sizeof(double),SEEK_CUR) ; }
1406
1407    fclose(fp) ; }
1408  else
1409  { std::cout
1410      << "readSolution: Unable to open file `"
1411      << fileName << "'." << std::endl ;
1412    retval = false ; }
1413
1414  return (retval) ; }
1415       
1416
1417} // end namespace CbcGenParamUtils
1418
1419
Note: See TracBrowser for help on using the repository browser.