ClpSolve.hpp
Go to the documentation of this file.
1 /* $Id: ClpSolve.hpp 1525 2010-02-26 17:27:59Z mjs $ */
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 
20 class ClpSolve {
21 
22 public:
23 
25  enum SolveType {
26  useDual = 0,
33  };
34  enum PresolveType {
39  };
40 
43  ClpSolve ( );
46  ClpSolve ( SolveType method, PresolveType presolveType,
47  int numberPasses, int options[6],
48  int extraInfo[6], int independentOptions[3]);
50  void generateCpp(FILE * fp);
52  ClpSolve(const ClpSolve &);
54  ClpSolve & operator=(const ClpSolve & rhs);
56  ~ClpSolve ( );
58 
103  void setSpecialOption(int which, int value, int extraInfo = -1);
104  int getSpecialOption(int which) const;
105 
107  void setSolveType(SolveType method, int extraInfo = -1);
109 
110  // Presolve types
111  void setPresolveType(PresolveType amount, int extraInfo = -1);
113  int getPresolvePasses() const;
115  int getExtraInfo(int which) const;
118  void setInfeasibleReturn(bool trueFalse);
119  inline bool infeasibleReturn() const {
120  return independentOptions_[0] != 0;
121  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
203  inline int presolveActions() const {
204  return independentOptions_[1] & 0xffff;
205  }
206  inline void setPresolveActions(int action) {
207  independentOptions_[1] = (independentOptions_[1] & 0xffff0000) | (action & 0xffff);
208  }
210  inline int substitution() const {
211  return independentOptions_[2];
212  }
213  inline void setSubstitution(int value) {
214  independentOptions_[2] = value;
215  }
217 
219 private:
220 
231  int options_[7];
233  int extraInfo_[7];
241 };
242 
245 
246 public:
247 
248 
251  ClpSimplexProgress ( );
253 
255  ClpSimplexProgress ( ClpSimplex * model );
256 
259 
265  void reset();
267  void fillFromModel ( ClpSimplex * model );
268 
270 
276  int looping ( );
278  void startCheck();
280  int cycle(int in, int out, int wayIn, int wayOut);
281 
283  double lastObjective(int back = 1) const;
285  void setInfeasibility(double value);
287  double lastInfeasibility(int back = 1) const;
289  void modifyObjective(double value);
291  int lastIterationNumber(int back = 1) const;
293  void clearIterationNumbers();
295  inline void newOddState() {
296  oddState_ = - oddState_ - 1;
297  }
298  inline void endOddState() {
299  oddState_ = abs(oddState_);
300  }
301  inline void clearOddState() {
302  oddState_ = 0;
303  }
304  inline int oddState() const {
305  return oddState_;
306  }
308  inline int badTimes() const {
309  return numberBadTimes_;
310  }
311  inline void clearBadTimes() {
312  numberBadTimes_ = 0;
313  }
315  inline int reallyBadTimes() const {
316  return numberReallyBadTimes_;
317  }
318  inline void incrementReallyBadTimes() {
320  }
322  inline int timesFlagged() const {
323  return numberTimesFlagged_;
324  }
325  inline void clearTimesFlagged() {
327  }
328  inline void incrementTimesFlagged() {
330  }
331 
333 
334 #define CLP_PROGRESS 5
335  //#define CLP_PROGRESS_WEIGHT 10
337  double objective_[CLP_PROGRESS];
343 #ifdef CLP_PROGRESS_WEIGHT
344  double objectiveWeight_[CLP_PROGRESS_WEIGHT];
347  double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
349  double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
351  double drop_;
353  double best_;
354 #endif
355  double initialWeight_;
357 #define CLP_CYCLE 12
358  //double obj_[CLP_CYCLE];
369 #ifdef CLP_PROGRESS_WEIGHT
370  int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
373  int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
374 #endif
375  int numberTimes_;
386 };
387 #endif
int numberBadTimes_
Number of times it looked like loop.
Definition: ClpSolve.hpp:378
bool doDupcol() const
Whether we want to do dupcol part of presolve.
Definition: ClpSolve.hpp:179
void newOddState()
Odd state.
Definition: ClpSolve.hpp:295
#define CLP_CYCLE
Definition: ClpSolve.hpp:357
double objective_[CLP_PROGRESS]
Objective values.
Definition: ClpSolve.hpp:338
void setDoDuprow(bool doDuprow_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:190
bool doImpliedFree() const
Whether we want to do impliedfree part of presolve.
Definition: ClpSolve.hpp:171
bool infeasibleReturn() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:119
This is a very simple class to guide algorithms.
Definition: ClpSolve.hpp:20
ClpSolve & operator=(const ClpSolve &rhs)
Assignment operator. This copies the data.
bool doDual() const
Whether we want to do dual part of presolve.
Definition: ClpSolve.hpp:123
void setPresolveActions(int action)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:206
int looping()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
int lastIterationNumber(int back=1) const
Returns previous iteration number (if -1) - current if (0)
void endOddState()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:298
void setDoDual(bool doDual_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:126
~ClpSolve()
Destructor.
int numberTimesFlagged_
Number of times no iterations as flagged.
Definition: ClpSolve.hpp:382
void setPresolveType(PresolveType amount, int extraInfo=-1)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
bool doSingletonColumn() const
Whether we want to do singleton column part of presolve.
Definition: ClpSolve.hpp:195
void reset()
Resets as much as possible.
bool doTripleton() const
Whether we want to do tripleton part of presolve.
Definition: ClpSolve.hpp:147
int oddState() const
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:304
void setSubstitution(int value)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:213
int oddState_
If things are in an odd state.
Definition: ClpSolve.hpp:384
PresolveType presolveType_
Presolve type.
Definition: ClpSolve.hpp:227
char way_[CLP_CYCLE]
Objective values.
Definition: ClpSolve.hpp:362
#define CLP_PROGRESS
Definition: ClpSolve.hpp:334
void setDoForcing(bool doForcing_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:166
SolveType
enums for solve function
Definition: ClpSolve.hpp:25
SolveType method_
Solve type.
Definition: ClpSolve.hpp:225
SolveType getSolveType()
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
void setDoDoubleton(bool doDoubleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:142
For saving extra information to see if looping.
Definition: ClpSolve.hpp:244
bool doDuprow() const
Whether we want to do duprow part of presolve.
Definition: ClpSolve.hpp:187
bool doForcing() const
Whether we want to do forcing part of presolve.
Definition: ClpSolve.hpp:163
int substitution() const
Largest column for substitution (normally 3)
Definition: ClpSolve.hpp:210
int numberTimes_
Number of times checked (so won't stop too early)
Definition: ClpSolve.hpp:376
void clearBadTimes()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:311
int in_[CLP_CYCLE]
For cycle checking.
Definition: ClpSolve.hpp:360
void fillFromModel(ClpSimplex *model)
Fill from model.
void setSolveType(SolveType method, int extraInfo=-1)
Solve types.
void setSpecialOption(int which, int value, int extraInfo=-1)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
PresolveType getPresolveType()
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
int presolveActions() const
Set whole group.
Definition: ClpSolve.hpp:203
double realInfeasibility_[CLP_PROGRESS]
Sum of real primal infeasibilities for primal.
Definition: ClpSolve.hpp:342
double infeasibility_[CLP_PROGRESS]
Sum of infeasibilities for algorithm.
Definition: ClpSolve.hpp:340
int iterationNumber_[CLP_PROGRESS]
Iteration number at which occurred.
Definition: ClpSolve.hpp:368
void generateCpp(FILE *fp)
Generates code for above constructor.
~ClpSimplexProgress()
Destructor.
void clearTimesFlagged()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:325
int cycle(int in, int out, int wayIn, int wayOut)
Returns cycle length in whileIterating.
int getExtraInfo(int which) const
Extra info for idiot (or sprint)
int reallyBadTimes() const
number of really bad times
Definition: ClpSolve.hpp:315
bool doSingleton() const
Whether we want to do singleton part of presolve.
Definition: ClpSolve.hpp:131
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:49
bool doTighten() const
Whether we want to do tighten part of presolve.
Definition: ClpSolve.hpp:155
int numberInfeasibilities_[CLP_PROGRESS]
Number of infeasibilities.
Definition: ClpSolve.hpp:366
int getSpecialOption(int which) const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
int out_[CLP_CYCLE]
Objective values.
Definition: ClpSolve.hpp:361
void setDoDupcol(bool doDupcol_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:182
void setDoSingleton(bool doSingleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:134
void modifyObjective(double value)
Modify objective e.g. if dual infeasible in dual.
ClpSolve()
Default constructor.
double initialWeight_
Initial weight for weights.
Definition: ClpSolve.hpp:356
int badTimes() const
number of bad times
Definition: ClpSolve.hpp:308
int numberPasses_
Amount of presolve.
Definition: ClpSolve.hpp:229
int timesFlagged() const
number of times flagged
Definition: ClpSolve.hpp:322
void startCheck()
Start check at beginning of whileIterating.
int independentOptions_[3]
Extra algorithm dependent options 0 - if set return from clpsolve if infeasible 1 - To be copied over...
Definition: ClpSolve.hpp:239
double lastInfeasibility(int back=1) const
Returns real primal infeasibility (if -1) - current if (0)
void setInfeasibility(double value)
Set real primal infeasibility and move back.
void setDoSingletonColumn(bool doSingleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:198
void setDoTripleton(bool doTripleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:150
void clearIterationNumbers()
clears all iteration numbers (to switch off panic)
bool doDoubleton() const
Whether we want to do doubleton part of presolve.
Definition: ClpSolve.hpp:139
double lastObjective(int back=1) const
Returns previous objective (if -1) - current if (0)
void setDoTighten(bool doTighten_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:158
void setDoImpliedFree(bool doImpliedfree)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:174
void setInfeasibleReturn(bool trueFalse)
Say to return at once if infeasible, default is to solve.
void incrementReallyBadTimes()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:318
void clearOddState()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:301
int extraInfo_[7]
Extra information.
Definition: ClpSolve.hpp:233
ClpSimplex * model_
Pointer back to model so we can get information.
Definition: ClpSolve.hpp:364
ClpSimplexProgress & operator=(const ClpSimplexProgress &rhs)
Assignment operator. This copies the data.
int numberReallyBadTimes_
Number really bad times.
Definition: ClpSolve.hpp:380
ClpSimplexProgress()
Default constructor.
int options_[7]
Options - last is switch for OsiClp.
Definition: ClpSolve.hpp:231
void incrementTimesFlagged()
Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken, >=0 if give up and use as p...
Definition: ClpSolve.hpp:328
int getPresolvePasses() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...