source: stable/1.15/Clp/src/ClpSolve.hpp @ 1989

Last change on this file since 1989 was 1928, checked in by stefan, 7 years ago

revert r1925 (so we can merge r1926) and sync with rev 1927

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.8 KB
Line 
1/* $Id: ClpSolve.hpp 1928 2013-04-06 12:54:16Z forrest $ */
2// Copyright (C) 2003, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5/*
6   Authors
7
8   John Forrest
9
10 */
11#ifndef ClpSolve_H
12#define ClpSolve_H
13
14/**
15    This is a very simple class to guide algorithms.  It is used to tidy up
16    passing parameters to initialSolve and maybe for output from that
17
18*/
19
20class ClpSolve  {
21
22public:
23
24     /** enums for solve function */
25     enum SolveType {
26          useDual = 0,
27          usePrimal,
28          usePrimalorSprint,
29          useBarrier,
30          useBarrierNoCross,
31          automatic,
32          notImplemented
33     };
34     enum PresolveType {
35          presolveOn = 0,
36          presolveOff,
37          presolveNumber,
38          presolveNumberCost
39     };
40
41     /**@name Constructors and destructor and copy */
42     //@{
43     /// Default constructor
44     ClpSolve (  );
45     /// Constructor when you really know what you are doing
46     ClpSolve ( SolveType method, PresolveType presolveType,
47                int numberPasses, int options[6],
48                int extraInfo[6], int independentOptions[3]);
49     /// Generates code for above constructor
50     void generateCpp(FILE * fp);
51     /// Copy constructor.
52     ClpSolve(const ClpSolve &);
53     /// Assignment operator. This copies the data
54     ClpSolve & operator=(const ClpSolve & rhs);
55     /// Destructor
56     ~ClpSolve (  );
57     //@}
58
59     /**@name Functions most useful to user */
60     //@{
61     /** Special options - bits
62     0      4 - use crash (default allslack in dual, idiot in primal)
63         8 - all slack basis in primal
64     2      16 - switch off interrupt handling
65     3      32 - do not try and make plus minus one matrix
66         64 - do not use sprint even if problem looks good
67      */
68     /** which translation is:
69         which:
70         0 - startup in Dual  (nothing if basis exists).:
71                      0 - no basis
72           1 - crash
73           2 - use initiative about idiot! but no crash
74         1 - startup in Primal (nothing if basis exists):
75                      0 - use initiative
76           1 - use crash
77           2 - use idiot and look at further info
78           3 - use sprint and look at further info
79           4 - use all slack
80           5 - use initiative but no idiot
81           6 - use initiative but no sprint
82           7 - use initiative but no crash
83                      8 - do allslack or idiot
84                      9 - do allslack or sprint
85           10 - slp before
86           11 - no nothing and primal(0)
87         2 - interrupt handling - 0 yes, 1 no (for threadsafe)
88         3 - whether to make +- 1matrix - 0 yes, 1 no
89         4 - for barrier
90                      0 - dense cholesky
91           1 - Wssmp allowing some long columns
92           2 - Wssmp not allowing long columns
93           3 - Wssmp using KKT
94                      4 - Using Florida ordering
95           8 - bit set to do scaling
96           16 - set to be aggressive with gamma/delta?
97                      32 - Use KKT
98         5 - for presolve
99                      1 - switch off dual stuff
100         6 - for detailed printout (initially just presolve)
101                      1 - presolve statistics
102     */
103     void setSpecialOption(int which, int value, int extraInfo = -1);
104     int getSpecialOption(int which) const;
105
106     /// Solve types
107     void setSolveType(SolveType method, int extraInfo = -1);
108     SolveType getSolveType();
109
110     // Presolve types
111     void setPresolveType(PresolveType amount, int extraInfo = -1);
112     PresolveType getPresolveType();
113     int getPresolvePasses() const;
114     /// Extra info for idiot (or sprint)
115     int getExtraInfo(int which) const;
116     /** Say to return at once if infeasible,
117         default is to solve */
118     void setInfeasibleReturn(bool trueFalse);
119     inline bool infeasibleReturn() const {
120          return independentOptions_[0] != 0;
121     }
122     /// Whether we want to do dual part of presolve
123     inline bool doDual() const {
124          return (independentOptions_[1] & 1) == 0;
125     }
126     inline void setDoDual(bool doDual_) {
127          if (doDual_) independentOptions_[1]  &= ~1;
128          else independentOptions_[1] |= 1;
129     }
130     /// Whether we want to do singleton part of presolve
131     inline bool doSingleton() const {
132          return (independentOptions_[1] & 2) == 0;
133     }
134     inline void setDoSingleton(bool doSingleton_) {
135          if (doSingleton_) independentOptions_[1]  &= ~2;
136          else independentOptions_[1] |= 2;
137     }
138     /// Whether we want to do doubleton part of presolve
139     inline bool doDoubleton() const {
140          return (independentOptions_[1] & 4) == 0;
141     }
142     inline void setDoDoubleton(bool doDoubleton_) {
143          if (doDoubleton_) independentOptions_[1]  &= ~4;
144          else independentOptions_[1] |= 4;
145     }
146     /// Whether we want to do tripleton part of presolve
147     inline bool doTripleton() const {
148          return (independentOptions_[1] & 8) == 0;
149     }
150     inline void setDoTripleton(bool doTripleton_) {
151          if (doTripleton_) independentOptions_[1]  &= ~8;
152          else independentOptions_[1] |= 8;
153     }
154     /// Whether we want to do tighten part of presolve
155     inline bool doTighten() const {
156          return (independentOptions_[1] & 16) == 0;
157     }
158     inline void setDoTighten(bool doTighten_) {
159          if (doTighten_) independentOptions_[1]  &= ~16;
160          else independentOptions_[1] |= 16;
161     }
162     /// Whether we want to do forcing part of presolve
163     inline bool doForcing() const {
164          return (independentOptions_[1] & 32) == 0;
165     }
166     inline void setDoForcing(bool doForcing_) {
167          if (doForcing_) independentOptions_[1]  &= ~32;
168          else independentOptions_[1] |= 32;
169     }
170     /// Whether we want to do impliedfree part of presolve
171     inline bool doImpliedFree() const {
172          return (independentOptions_[1] & 64) == 0;
173     }
174     inline void setDoImpliedFree(bool doImpliedfree) {
175          if (doImpliedfree) independentOptions_[1]  &= ~64;
176          else independentOptions_[1] |= 64;
177     }
178     /// Whether we want to do dupcol part of presolve
179     inline bool doDupcol() const {
180          return (independentOptions_[1] & 128) == 0;
181     }
182     inline void setDoDupcol(bool doDupcol_) {
183          if (doDupcol_) independentOptions_[1]  &= ~128;
184          else independentOptions_[1] |= 128;
185     }
186     /// Whether we want to do duprow part of presolve
187     inline bool doDuprow() const {
188          return (independentOptions_[1] & 256) == 0;
189     }
190     inline void setDoDuprow(bool doDuprow_) {
191          if (doDuprow_) independentOptions_[1]  &= ~256;
192          else independentOptions_[1] |= 256;
193     }
194     /// Whether we want to do singleton column part of presolve
195     inline bool doSingletonColumn() const {
196          return (independentOptions_[1] & 512) == 0;
197     }
198     inline void setDoSingletonColumn(bool doSingleton_) {
199          if (doSingleton_) independentOptions_[1]  &= ~512;
200          else independentOptions_[1] |= 512;
201     }
202     /// Whether we want to kill small substitutions
203     inline bool doKillSmall() const {
204          return (independentOptions_[1] & 1024) == 0;
205     }
206     inline void setDoKillSmall(bool doKill) {
207          if (doKill) independentOptions_[1]  &= ~1024;
208          else independentOptions_[1] |= 1024;
209     }
210     /// Set whole group
211     inline int presolveActions() const {
212          return independentOptions_[1] & 0xffff;
213     }
214     inline void setPresolveActions(int action) {
215          independentOptions_[1]  = (independentOptions_[1] & 0xffff0000) | (action & 0xffff);
216     }
217     /// Largest column for substitution (normally 3)
218     inline int substitution() const {
219          return independentOptions_[2];
220     }
221     inline void setSubstitution(int value) {
222          independentOptions_[2] = value;
223     }
224     //@}
225
226////////////////// data //////////////////
227private:
228
229     /**@name data.
230     */
231     //@{
232     /// Solve type
233     SolveType method_;
234     /// Presolve type
235     PresolveType presolveType_;
236     /// Amount of presolve
237     int numberPasses_;
238     /// Options - last is switch for OsiClp
239     int options_[7];
240     /// Extra information
241     int extraInfo_[7];
242     /** Extra algorithm dependent options
243         0 - if set return from clpsolve if infeasible
244         1 - To be copied over to presolve options
245         2 - max substitution level
246     */
247     int independentOptions_[3];
248     //@}
249};
250
251/// For saving extra information to see if looping.
252class ClpSimplexProgress {
253
254public:
255
256
257     /**@name Constructors and destructor and copy */
258     //@{
259     /// Default constructor
260     ClpSimplexProgress (  );
261
262     /// Constructor from model
263     ClpSimplexProgress ( ClpSimplex * model );
264
265     /// Copy constructor.
266     ClpSimplexProgress(const ClpSimplexProgress &);
267
268     /// Assignment operator. This copies the data
269     ClpSimplexProgress & operator=(const ClpSimplexProgress & rhs);
270     /// Destructor
271     ~ClpSimplexProgress (  );
272     /// Resets as much as possible
273     void reset();
274     /// Fill from model
275     void fillFromModel ( ClpSimplex * model );
276
277     //@}
278
279     /**@name Check progress */
280     //@{
281     /** Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken,
282         >=0 if give up and use as problem status
283     */
284     int looping (  );
285     /// Start check at beginning of whileIterating
286     void startCheck();
287     /// Returns cycle length in whileIterating
288     int cycle(int in, int out, int wayIn, int wayOut);
289
290     /// Returns previous objective (if -1) - current if (0)
291     double lastObjective(int back = 1) const;
292     /// Set real primal infeasibility and move back
293     void setInfeasibility(double value);
294     /// Returns real primal infeasibility (if -1) - current if (0)
295     double lastInfeasibility(int back = 1) const;
296     /// Modify objective e.g. if dual infeasible in dual
297     void modifyObjective(double value);
298     /// Returns previous iteration number (if -1) - current if (0)
299     int lastIterationNumber(int back = 1) const;
300     /// clears all iteration numbers (to switch off panic)
301     void clearIterationNumbers();
302     /// Odd state
303     inline void newOddState() {
304          oddState_ = - oddState_ - 1;
305     }
306     inline void endOddState() {
307          oddState_ = abs(oddState_);
308     }
309     inline void clearOddState() {
310          oddState_ = 0;
311     }
312     inline int oddState() const {
313          return oddState_;
314     }
315     /// number of bad times
316     inline int badTimes() const {
317          return numberBadTimes_;
318     }
319     inline void clearBadTimes() {
320          numberBadTimes_ = 0;
321     }
322     /// number of really bad times
323     inline int reallyBadTimes() const {
324          return numberReallyBadTimes_;
325     }
326     inline void incrementReallyBadTimes() {
327          numberReallyBadTimes_++;
328     }
329     /// number of times flagged
330     inline int timesFlagged() const {
331          return numberTimesFlagged_;
332     }
333     inline void clearTimesFlagged() {
334          numberTimesFlagged_ = 0;
335     }
336     inline void incrementTimesFlagged() {
337          numberTimesFlagged_++;
338     }
339
340     //@}
341     /**@name Data  */
342#define CLP_PROGRESS 5
343     //#define CLP_PROGRESS_WEIGHT 10
344     //@{
345     /// Objective values
346     double objective_[CLP_PROGRESS];
347     /// Sum of infeasibilities for algorithm
348     double infeasibility_[CLP_PROGRESS];
349     /// Sum of real primal infeasibilities for primal
350     double realInfeasibility_[CLP_PROGRESS];
351#ifdef CLP_PROGRESS_WEIGHT
352     /// Objective values for weights
353     double objectiveWeight_[CLP_PROGRESS_WEIGHT];
354     /// Sum of infeasibilities for algorithm for weights
355     double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
356     /// Sum of real primal infeasibilities for primal for weights
357     double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
358     /// Drop  for weights
359     double drop_;
360     /// Best? for weights
361     double best_;
362#endif
363     /// Initial weight for weights
364     double initialWeight_;
365#define CLP_CYCLE 12
366     /// For cycle checking
367     //double obj_[CLP_CYCLE];
368     int in_[CLP_CYCLE];
369     int out_[CLP_CYCLE];
370     char way_[CLP_CYCLE];
371     /// Pointer back to model so we can get information
372     ClpSimplex * model_;
373     /// Number of infeasibilities
374     int numberInfeasibilities_[CLP_PROGRESS];
375     /// Iteration number at which occurred
376     int iterationNumber_[CLP_PROGRESS];
377#ifdef CLP_PROGRESS_WEIGHT
378     /// Number of infeasibilities for weights
379     int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
380     /// Iteration number at which occurred for weights
381     int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
382#endif
383     /// Number of times checked (so won't stop too early)
384     int numberTimes_;
385     /// Number of times it looked like loop
386     int numberBadTimes_;
387     /// Number really bad times
388     int numberReallyBadTimes_;
389     /// Number of times no iterations as flagged
390     int numberTimesFlagged_;
391     /// If things are in an odd state
392     int oddState_;
393     //@}
394};
395
396#include "ClpConfig.h"
397#if CLP_HAS_ABC
398#include "AbcCommon.hpp"
399/// For saving extra information to see if looping.
400class AbcSimplexProgress : public ClpSimplexProgress {
401
402public:
403
404
405     /**@name Constructors and destructor and copy */
406     //@{
407     /// Default constructor
408     AbcSimplexProgress (  );
409
410     /// Constructor from model
411     AbcSimplexProgress ( ClpSimplex * model );
412
413     /// Copy constructor.
414     AbcSimplexProgress(const AbcSimplexProgress &);
415
416     /// Assignment operator. This copies the data
417     AbcSimplexProgress & operator=(const AbcSimplexProgress & rhs);
418     /// Destructor
419     ~AbcSimplexProgress (  );
420
421     //@}
422
423     /**@name Check progress */
424     //@{
425     /** Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken,
426         >=0 if give up and use as problem status
427     */
428     int looping (  );
429
430     //@}
431     /**@name Data  */
432     //@}
433};
434#endif
435#endif
Note: See TracBrowser for help on using the repository browser.