source: trunk/Clp/src/ClpSolve.hpp @ 1402

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

add ids

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1/* $Id: ClpSolve.hpp 1370 2009-06-04 09:37:13Z forrest $ */
2// Copyright (C) 2003, International Business Machines
3// Corporation and others.  All Rights Reserved.
4
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
620      4 - use crash (default allslack in dual, idiot in primal)
63      8 - all slack basis in primal
642      16 - switch off interrupt handling
653      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  /// Whether we want to do dual part of presolve
122  inline bool doDual() const
123  { return (independentOptions_[1]&1)==0;}
124  inline void setDoDual(bool doDual)
125  { if (doDual) independentOptions_[1]  &= ~1; else independentOptions_[1] |= 1;}
126  /// Whether we want to do singleton part of presolve
127  inline bool doSingleton() const
128  { return (independentOptions_[1]&2)==0;}
129  inline void setDoSingleton(bool doSingleton)
130  { if (doSingleton) independentOptions_[1]  &= ~2; else independentOptions_[1] |= 2;}
131  /// Whether we want to do doubleton part of presolve
132  inline bool doDoubleton() const
133  { return (independentOptions_[1]&4)==0;}
134  inline void setDoDoubleton(bool doDoubleton)
135  { if (doDoubleton) independentOptions_[1]  &= ~4; else independentOptions_[1] |= 4;}
136  /// Whether we want to do tripleton part of presolve
137  inline bool doTripleton() const
138  { return (independentOptions_[1]&8)==0;}
139  inline void setDoTripleton(bool doTripleton)
140  { if (doTripleton) independentOptions_[1]  &= ~8; else independentOptions_[1] |= 8;}
141  /// Whether we want to do tighten part of presolve
142  inline bool doTighten() const
143  { return (independentOptions_[1]&16)==0;}
144  inline void setDoTighten(bool doTighten)
145  { if (doTighten) independentOptions_[1]  &= ~16; else independentOptions_[1] |= 16;}
146  /// Whether we want to do forcing part of presolve
147  inline bool doForcing() const
148  { return (independentOptions_[1]&32)==0;}
149  inline void setDoForcing(bool doForcing)
150  { if (doForcing) independentOptions_[1]  &= ~32; else independentOptions_[1] |= 32;}
151  /// Whether we want to do impliedfree part of presolve
152  inline bool doImpliedFree() const
153  { return (independentOptions_[1]&64)==0;}
154  inline void setDoImpliedFree(bool doImpliedfree)
155  { if (doImpliedfree) independentOptions_[1]  &= ~64; else independentOptions_[1] |= 64;}
156  /// Whether we want to do dupcol part of presolve
157  inline bool doDupcol() const
158  { return (independentOptions_[1]&128)==0;}
159  inline void setDoDupcol(bool doDupcol)
160  { if (doDupcol) independentOptions_[1]  &= ~128; else independentOptions_[1] |= 128;}
161  /// Whether we want to do duprow part of presolve
162  inline bool doDuprow() const
163  { return (independentOptions_[1]&256)==0;}
164  inline void setDoDuprow(bool doDuprow)
165  { if (doDuprow) independentOptions_[1]  &= ~256; else independentOptions_[1] |= 256;}
166  /// Whether we want to do singleton column part of presolve
167  inline bool doSingletonColumn() const
168  { return (independentOptions_[1]&512)==0;}
169  inline void setDoSingletonColumn(bool doSingleton)
170  { if (doSingleton) independentOptions_[1]  &= ~512; else independentOptions_[1] |= 512;}
171  /// Set whole group
172  inline int presolveActions() const
173  { return independentOptions_[1]&0xffff;}
174  inline void setPresolveActions(int action)
175  { independentOptions_[1]  = (independentOptions_[1]&0xffff0000)|(action&0xffff);}
176  /// Largest column for substitution (normally 3)
177  inline int substitution() const
178  { return independentOptions_[2];}
179  inline void setSubstitution(int value)
180  { independentOptions_[2] = value;}
181  //@}
182
183////////////////// data //////////////////
184private:
185
186  /**@name data.
187  */
188  //@{
189  /// Solve type
190  SolveType method_;
191  /// Presolve type
192  PresolveType presolveType_;
193  /// Amount of presolve
194  int numberPasses_;
195  /// Options - last is switch for OsiClp
196  int options_[7];
197  /// Extra information
198  int extraInfo_[7];
199  /** Extra algorithm dependent options
200      0 - if set return from clpsolve if infeasible
201      1 - To be copied over to presolve options
202      2 - max substitution level
203  */
204  int independentOptions_[3];
205  //@}
206};
207
208/// For saving extra information to see if looping.
209class ClpSimplexProgress {
210
211public:
212
213
214  /**@name Constructors and destructor and copy */
215  //@{
216  /// Default constructor
217    ClpSimplexProgress (  );
218
219  /// Constructor from model
220    ClpSimplexProgress ( ClpSimplex * model );
221
222  /// Copy constructor.
223  ClpSimplexProgress(const ClpSimplexProgress &);
224
225  /// Assignment operator. This copies the data
226    ClpSimplexProgress & operator=(const ClpSimplexProgress & rhs);
227  /// Destructor
228   ~ClpSimplexProgress (  );
229  /// Resets as much as possible
230   void reset();
231  /// Fill from model
232    void fillFromModel ( ClpSimplex * model );
233
234  //@}
235
236  /**@name Check progress */
237  //@{
238  /** Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken,
239      >=0 if give up and use as problem status
240  */
241    int looping (  );
242  /// Start check at beginning of whileIterating
243  void startCheck();
244  /// Returns cycle length in whileIterating
245  int cycle(int in, int out,int wayIn,int wayOut); 
246
247  /// Returns previous objective (if -1) - current if (0)
248  double lastObjective(int back=1) const;
249  /// Set real primal infeasibility and move back
250  void setInfeasibility(double value);
251  /// Returns real primal infeasibility (if -1) - current if (0)
252  double lastInfeasibility(int back=1) const;
253  /// Modify objective e.g. if dual infeasible in dual
254  void modifyObjective(double value);
255  /// Returns previous iteration number (if -1) - current if (0)
256  int lastIterationNumber(int back=1) const;
257  /// clears all iteration numbers (to switch off panic)
258  void clearIterationNumbers();
259  /// Odd state
260  inline void newOddState()
261  { oddState_= - oddState_-1;}
262  inline void endOddState()
263  { oddState_=abs(oddState_);}
264  inline void clearOddState() 
265  { oddState_=0;}
266  inline int oddState() const
267  { return oddState_;}
268  /// number of bad times
269  inline int badTimes() const
270  { return numberBadTimes_;}
271  inline void clearBadTimes()
272  { numberBadTimes_=0;}
273  /// number of really bad times
274  inline int reallyBadTimes() const
275  { return numberReallyBadTimes_;}
276  inline void incrementReallyBadTimes()
277  { numberReallyBadTimes_++;}
278  /// number of times flagged
279  inline int timesFlagged() const
280  { return numberTimesFlagged_;}
281  inline void clearTimesFlagged()
282  { numberTimesFlagged_=0;}
283  inline void incrementTimesFlagged()
284  { numberTimesFlagged_++;}
285
286  //@}
287  /**@name Data  */
288#define CLP_PROGRESS 5
289  //#define CLP_PROGRESS_WEIGHT 10
290  //@{
291  /// Objective values
292  double objective_[CLP_PROGRESS];
293  /// Sum of infeasibilities for algorithm
294  double infeasibility_[CLP_PROGRESS];
295  /// Sum of real primal infeasibilities for primal
296  double realInfeasibility_[CLP_PROGRESS];
297#ifdef CLP_PROGRESS_WEIGHT
298  /// Objective values for weights
299  double objectiveWeight_[CLP_PROGRESS_WEIGHT];
300  /// Sum of infeasibilities for algorithm for weights
301  double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
302  /// Sum of real primal infeasibilities for primal for weights
303  double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
304  /// Drop  for weights
305  double drop_;
306  /// Best? for weights
307  double best_;
308#endif
309  /// Initial weight for weights
310  double initialWeight_;
311#define CLP_CYCLE 12
312  /// For cycle checking
313  //double obj_[CLP_CYCLE];
314  int in_[CLP_CYCLE];
315  int out_[CLP_CYCLE];
316  char way_[CLP_CYCLE];
317  /// Pointer back to model so we can get information
318  ClpSimplex * model_;
319  /// Number of infeasibilities
320  int numberInfeasibilities_[CLP_PROGRESS];
321  /// Iteration number at which occurred
322  int iterationNumber_[CLP_PROGRESS];
323#ifdef CLP_PROGRESS_WEIGHT
324  /// Number of infeasibilities for weights
325  int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
326  /// Iteration number at which occurred for weights
327  int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
328#endif
329  /// Number of times checked (so won't stop too early)
330  int numberTimes_;
331  /// Number of times it looked like loop
332  int numberBadTimes_;
333  /// Number really bad times
334  int numberReallyBadTimes_;
335  /// Number of times no iterations as flagged
336  int numberTimesFlagged_;
337  /// If things are in an odd state
338  int oddState_;
339  //@}
340};
341#endif
Note: See TracBrowser for help on using the repository browser.