ClpSolve.hpp
Go to the documentation of this file.
1 /* $Id: ClpSolve.hpp 2078 2015-01-05 12:39:49Z 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 
20 class ClpSolve {
21 
22 public:
23 
25  enum SolveType {
26  useDual = 0,
35  };
36  enum PresolveType {
41  };
42 
45  ClpSolve ( );
48  ClpSolve ( SolveType method, PresolveType presolveType,
49  int numberPasses, int options[6],
50  int extraInfo[6], int independentOptions[3]);
52  void generateCpp(FILE * fp);
54  ClpSolve(const ClpSolve &);
56  ClpSolve & operator=(const ClpSolve & rhs);
58  ~ClpSolve ( );
60 
105  void setSpecialOption(int which, int value, int extraInfo = -1);
106  int getSpecialOption(int which) const;
107 
109  void setSolveType(SolveType method, int extraInfo = -1);
111 
112  // Presolve types
113  void setPresolveType(PresolveType amount, int extraInfo = -1);
115  int getPresolvePasses() const;
117  int getExtraInfo(int which) const;
120  void setInfeasibleReturn(bool trueFalse);
121  inline bool infeasibleReturn() const {
122  return independentOptions_[0] != 0;
123  }
125  inline bool doDual() const {
126  return (independentOptions_[1] & 1) == 0;
127  }
128  inline void setDoDual(bool doDual_) {
129  if (doDual_) independentOptions_[1] &= ~1;
130  else independentOptions_[1] |= 1;
131  }
133  inline bool doSingleton() const {
134  return (independentOptions_[1] & 2) == 0;
135  }
136  inline void setDoSingleton(bool doSingleton_) {
137  if (doSingleton_) independentOptions_[1] &= ~2;
138  else independentOptions_[1] |= 2;
139  }
141  inline bool doDoubleton() const {
142  return (independentOptions_[1] & 4) == 0;
143  }
144  inline void setDoDoubleton(bool doDoubleton_) {
145  if (doDoubleton_) independentOptions_[1] &= ~4;
146  else independentOptions_[1] |= 4;
147  }
149  inline bool doTripleton() const {
150  return (independentOptions_[1] & 8) == 0;
151  }
152  inline void setDoTripleton(bool doTripleton_) {
153  if (doTripleton_) independentOptions_[1] &= ~8;
154  else independentOptions_[1] |= 8;
155  }
157  inline bool doTighten() const {
158  return (independentOptions_[1] & 16) == 0;
159  }
160  inline void setDoTighten(bool doTighten_) {
161  if (doTighten_) independentOptions_[1] &= ~16;
162  else independentOptions_[1] |= 16;
163  }
165  inline bool doForcing() const {
166  return (independentOptions_[1] & 32) == 0;
167  }
168  inline void setDoForcing(bool doForcing_) {
169  if (doForcing_) independentOptions_[1] &= ~32;
170  else independentOptions_[1] |= 32;
171  }
173  inline bool doImpliedFree() const {
174  return (independentOptions_[1] & 64) == 0;
175  }
176  inline void setDoImpliedFree(bool doImpliedfree) {
177  if (doImpliedfree) independentOptions_[1] &= ~64;
178  else independentOptions_[1] |= 64;
179  }
181  inline bool doDupcol() const {
182  return (independentOptions_[1] & 128) == 0;
183  }
184  inline void setDoDupcol(bool doDupcol_) {
185  if (doDupcol_) independentOptions_[1] &= ~128;
186  else independentOptions_[1] |= 128;
187  }
189  inline bool doDuprow() const {
190  return (independentOptions_[1] & 256) == 0;
191  }
192  inline void setDoDuprow(bool doDuprow_) {
193  if (doDuprow_) independentOptions_[1] &= ~256;
194  else independentOptions_[1] |= 256;
195  }
197  inline bool doSingletonColumn() const {
198  return (independentOptions_[1] & 512) == 0;
199  }
200  inline void setDoSingletonColumn(bool doSingleton_) {
201  if (doSingleton_) independentOptions_[1] &= ~512;
202  else independentOptions_[1] |= 512;
203  }
205  inline bool doKillSmall() const {
206  return (independentOptions_[1] & 8192) == 0;
207  }
208  inline void setDoKillSmall(bool doKill) {
209  if (doKill) independentOptions_[1] &= ~8192;
210  else independentOptions_[1] |= 8192;
211  }
213  inline int presolveActions() const {
214  return independentOptions_[1] & 0xffff;
215  }
216  inline void setPresolveActions(int action) {
217  independentOptions_[1] = (independentOptions_[1] & 0xffff0000) | (action & 0xffff);
218  }
220  inline int substitution() const {
221  return independentOptions_[2];
222  }
223  inline void setSubstitution(int value) {
224  independentOptions_[2] = value;
225  }
226  inline void setIndependentOption(int type,int value) {
227  independentOptions_[type] = value;
228  }
229  inline int independentOption(int type) const {
230  return independentOptions_[type];
231  }
233 
235 private:
236 
247  int options_[7];
249  int extraInfo_[7];
258 };
259 
262 
263 public:
264 
265 
268  ClpSimplexProgress ( );
270 
272  ClpSimplexProgress ( ClpSimplex * model );
273 
276 
282  void reset();
284  void fillFromModel ( ClpSimplex * model );
285 
287 
293  int looping ( );
295  void startCheck();
297  int cycle(int in, int out, int wayIn, int wayOut);
298 
300  double lastObjective(int back = 1) const;
302  void setInfeasibility(double value);
304  double lastInfeasibility(int back = 1) const;
306  int numberInfeasibilities(int back = 1) const;
308  void modifyObjective(double value);
310  int lastIterationNumber(int back = 1) const;
312  void clearIterationNumbers();
314  inline void newOddState() {
315  oddState_ = - oddState_ - 1;
316  }
317  inline void endOddState() {
318  oddState_ = abs(oddState_);
319  }
320  inline void clearOddState() {
321  oddState_ = 0;
322  }
323  inline int oddState() const {
324  return oddState_;
325  }
327  inline int badTimes() const {
328  return numberBadTimes_;
329  }
330  inline void clearBadTimes() {
331  numberBadTimes_ = 0;
332  }
334  inline int reallyBadTimes() const {
335  return numberReallyBadTimes_;
336  }
337  inline void incrementReallyBadTimes() {
339  }
341  inline int timesFlagged() const {
342  return numberTimesFlagged_;
343  }
344  inline void clearTimesFlagged() {
346  }
347  inline void incrementTimesFlagged() {
349  }
350 
352 
353 #define CLP_PROGRESS 5
354  //#define CLP_PROGRESS_WEIGHT 10
356  double objective_[CLP_PROGRESS];
362 #ifdef CLP_PROGRESS_WEIGHT
363  double objectiveWeight_[CLP_PROGRESS_WEIGHT];
366  double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
368  double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
370  double drop_;
372  double best_;
373 #endif
374  double initialWeight_;
376 #define CLP_CYCLE 12
377  //double obj_[CLP_CYCLE];
388 #ifdef CLP_PROGRESS_WEIGHT
389  int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
392  int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
393 #endif
394  int numberTimes_;
405 };
406 
407 #include "ClpConfig.h"
408 #if CLP_HAS_ABC
409 #include "AbcCommon.hpp"
411 class AbcSimplexProgress : public ClpSimplexProgress {
412 
413 public:
414 
415 
418  AbcSimplexProgress ( );
420 
422  AbcSimplexProgress ( ClpSimplex * model );
423 
425  AbcSimplexProgress(const AbcSimplexProgress &);
426 
428  AbcSimplexProgress & operator=(const AbcSimplexProgress & rhs);
430  ~AbcSimplexProgress ( );
431 
433 
439  int looping ( );
440 
442 
444 };
445 #endif
446 #endif
int numberBadTimes_
Number of times it looked like loop.
Definition: ClpSolve.hpp:397
bool doDupcol() const
Whether we want to do dupcol part of presolve.
Definition: ClpSolve.hpp:181
void newOddState()
Odd state.
Definition: ClpSolve.hpp:314
#define CLP_CYCLE
Definition: ClpSolve.hpp:376
double objective_[CLP_PROGRESS]
Objective values.
Definition: ClpSolve.hpp:357
void setDoDuprow(bool doDuprow_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:192
bool doImpliedFree() const
Whether we want to do impliedfree part of presolve.
Definition: ClpSolve.hpp:173
bool infeasibleReturn() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:121
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:125
void setPresolveActions(int action)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:216
bool doKillSmall() const
Whether we want to kill small substitutions.
Definition: ClpSolve.hpp:205
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:317
void setDoDual(bool doDual_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:128
~ClpSolve()
Destructor.
int numberTimesFlagged_
Number of times no iterations as flagged.
Definition: ClpSolve.hpp:401
void setPresolveType(PresolveType amount, int extraInfo=-1)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
bool doSingletonColumn() const
Whether we want to do singleton column part of presolve.
Definition: ClpSolve.hpp:197
void reset()
Resets as much as possible.
bool doTripleton() const
Whether we want to do tripleton part of presolve.
Definition: ClpSolve.hpp:149
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:323
void setSubstitution(int value)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:223
int oddState_
If things are in an odd state.
Definition: ClpSolve.hpp:403
PresolveType presolveType_
Presolve type.
Definition: ClpSolve.hpp:243
char way_[CLP_CYCLE]
Objective values.
Definition: ClpSolve.hpp:381
#define CLP_PROGRESS
Definition: ClpSolve.hpp:353
void setDoForcing(bool doForcing_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:168
SolveType
enums for solve function
Definition: ClpSolve.hpp:25
SolveType method_
Solve type.
Definition: ClpSolve.hpp:241
SolveType getSolveType()
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
void setDoDoubleton(bool doDoubleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:144
For saving extra information to see if looping.
Definition: ClpSolve.hpp:261
bool doDuprow() const
Whether we want to do duprow part of presolve.
Definition: ClpSolve.hpp:189
bool doForcing() const
Whether we want to do forcing part of presolve.
Definition: ClpSolve.hpp:165
int substitution() const
Largest column for substitution (normally 3)
Definition: ClpSolve.hpp:220
int numberTimes_
Number of times checked (so won't stop too early)
Definition: ClpSolve.hpp:395
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:330
int in_[CLP_CYCLE]
For cycle checking.
Definition: ClpSolve.hpp:379
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 bas...
PresolveType getPresolveType()
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
int presolveActions() const
Set whole group.
Definition: ClpSolve.hpp:213
double realInfeasibility_[CLP_PROGRESS]
Sum of real primal infeasibilities for primal.
Definition: ClpSolve.hpp:361
double infeasibility_[CLP_PROGRESS]
Sum of infeasibilities for algorithm.
Definition: ClpSolve.hpp:359
int iterationNumber_[CLP_PROGRESS]
Iteration number at which occurred.
Definition: ClpSolve.hpp:387
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:344
void setIndependentOption(int type, int value)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:226
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:334
bool doSingleton() const
Whether we want to do singleton part of presolve.
Definition: ClpSolve.hpp:133
int independentOption(int type) const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:229
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:70
bool doTighten() const
Whether we want to do tighten part of presolve.
Definition: ClpSolve.hpp:157
int numberInfeasibilities_[CLP_PROGRESS]
Number of infeasibilities.
Definition: ClpSolve.hpp:385
int getSpecialOption(int which) const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
int out_[CLP_CYCLE]
Objective values.
Definition: ClpSolve.hpp:380
void setDoDupcol(bool doDupcol_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:184
int numberInfeasibilities(int back=1) const
Returns number of primal infeasibilities (if -1) - current if (0)
void setDoSingleton(bool doSingleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:136
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:375
int badTimes() const
number of bad times
Definition: ClpSolve.hpp:327
int numberPasses_
Amount of presolve.
Definition: ClpSolve.hpp:245
int timesFlagged() const
number of times flagged
Definition: ClpSolve.hpp:341
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:256
void setDoKillSmall(bool doKill)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:208
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 bas...
Definition: ClpSolve.hpp:200
void setDoTripleton(bool doTripleton_)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:152
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:141
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 bas...
Definition: ClpSolve.hpp:160
void setDoImpliedFree(bool doImpliedfree)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...
Definition: ClpSolve.hpp:176
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:337
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:320
int extraInfo_[7]
Extra information.
Definition: ClpSolve.hpp:249
ClpSimplex * model_
Pointer back to model so we can get information.
Definition: ClpSolve.hpp:383
ClpSimplexProgress & operator=(const ClpSimplexProgress &rhs)
Assignment operator. This copies the data.
int numberReallyBadTimes_
Number really bad times.
Definition: ClpSolve.hpp:399
ClpSimplexProgress()
Default constructor.
int options_[7]
Options - last is switch for OsiClp.
Definition: ClpSolve.hpp:247
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:347
int getPresolvePasses() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack bas...