coin-Bcp
ClpSolve.hpp
Go to the documentation of this file.
1 /* $Id: ClpSolve.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
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:
24  enum SolveType {
25  useDual = 0,
34  };
35  enum PresolveType {
40  };
41 
44  ClpSolve();
47  ClpSolve(SolveType method, PresolveType presolveType,
48  int numberPasses, int options[6],
49  int extraInfo[6], int independentOptions[3]);
51  void generateCpp(FILE *fp);
53  ClpSolve(const ClpSolve &);
55  ClpSolve &operator=(const ClpSolve &rhs);
57  ~ClpSolve();
59 
104  void setSpecialOption(int which, int value, int extraInfo = -1);
105  int getSpecialOption(int which) const;
106 
108  void setSolveType(SolveType method, int extraInfo = -1);
110 
111  // Presolve types
112  void setPresolveType(PresolveType amount, int extraInfo = -1);
114  int getPresolvePasses() const;
116  int getExtraInfo(int which) const;
119  void setInfeasibleReturn(bool trueFalse);
120  inline bool infeasibleReturn() const
121  {
122  return independentOptions_[0] != 0;
123  }
125  inline bool doDual() const
126  {
127  return (independentOptions_[1] & 1) == 0;
128  }
129  inline void setDoDual(bool doDual_)
130  {
131  if (doDual_)
132  independentOptions_[1] &= ~1;
133  else
134  independentOptions_[1] |= 1;
135  }
137  inline bool doSingleton() const
138  {
139  return (independentOptions_[1] & 2) == 0;
140  }
141  inline void setDoSingleton(bool doSingleton_)
142  {
143  if (doSingleton_)
144  independentOptions_[1] &= ~2;
145  else
146  independentOptions_[1] |= 2;
147  }
149  inline bool doDoubleton() const
150  {
151  return (independentOptions_[1] & 4) == 0;
152  }
153  inline void setDoDoubleton(bool doDoubleton_)
154  {
155  if (doDoubleton_)
156  independentOptions_[1] &= ~4;
157  else
158  independentOptions_[1] |= 4;
159  }
161  inline bool doTripleton() const
162  {
163  return (independentOptions_[1] & 8) == 0;
164  }
165  inline void setDoTripleton(bool doTripleton_)
166  {
167  if (doTripleton_)
168  independentOptions_[1] &= ~8;
169  else
170  independentOptions_[1] |= 8;
171  }
173  inline bool doTighten() const
174  {
175  return (independentOptions_[1] & 16) == 0;
176  }
177  inline void setDoTighten(bool doTighten_)
178  {
179  if (doTighten_)
180  independentOptions_[1] &= ~16;
181  else
182  independentOptions_[1] |= 16;
183  }
185  inline bool doForcing() const
186  {
187  return (independentOptions_[1] & 32) == 0;
188  }
189  inline void setDoForcing(bool doForcing_)
190  {
191  if (doForcing_)
192  independentOptions_[1] &= ~32;
193  else
194  independentOptions_[1] |= 32;
195  }
197  inline bool doImpliedFree() const
198  {
199  return (independentOptions_[1] & 64) == 0;
200  }
201  inline void setDoImpliedFree(bool doImpliedfree)
202  {
203  if (doImpliedfree)
204  independentOptions_[1] &= ~64;
205  else
206  independentOptions_[1] |= 64;
207  }
209  inline bool doDupcol() const
210  {
211  return (independentOptions_[1] & 128) == 0;
212  }
213  inline void setDoDupcol(bool doDupcol_)
214  {
215  if (doDupcol_)
216  independentOptions_[1] &= ~128;
217  else
218  independentOptions_[1] |= 128;
219  }
221  inline bool doDuprow() const
222  {
223  return (independentOptions_[1] & 256) == 0;
224  }
225  inline void setDoDuprow(bool doDuprow_)
226  {
227  if (doDuprow_)
228  independentOptions_[1] &= ~256;
229  else
230  independentOptions_[1] |= 256;
231  }
233  inline bool doSingletonColumn() const
234  {
235  return (independentOptions_[1] & 512) == 0;
236  }
237  inline void setDoSingletonColumn(bool doSingleton_)
238  {
239  if (doSingleton_)
240  independentOptions_[1] &= ~512;
241  else
242  independentOptions_[1] |= 512;
243  }
245  inline bool doKillSmall() const
246  {
247  return (independentOptions_[1] & 8192) == 0;
248  }
249  inline void setDoKillSmall(bool doKill)
250  {
251  if (doKill)
252  independentOptions_[1] &= ~8192;
253  else
254  independentOptions_[1] |= 8192;
255  }
257  inline int presolveActions() const
258  {
259  return independentOptions_[1] & 0xffffff;
260  }
261  inline void setPresolveActions(int action)
262  {
263  independentOptions_[1] = (independentOptions_[1] & 0xff000000) | (action & 0xffffff);
264  }
266  inline int substitution() const
267  {
268  return independentOptions_[2];
269  }
270  inline void setSubstitution(int value)
271  {
272  independentOptions_[2] = value;
273  }
274  inline void setIndependentOption(int type, int value)
275  {
276  independentOptions_[type] = value;
277  }
278  inline int independentOption(int type) const
279  {
280  return independentOptions_[type];
281  }
283 
285 private:
296  int options_[7];
298  int extraInfo_[7];
307 };
308 
311 
312 public:
317 
320 
323 
329  void reset();
331  void fillFromModel(ClpSimplex *model);
332 
334 
340  int looping();
342  void startCheck();
344  int cycle(int in, int out, int wayIn, int wayOut);
345 
347  double lastObjective(int back = 1) const;
349  void setInfeasibility(double value);
351  double lastInfeasibility(int back = 1) const;
353  int numberInfeasibilities(int back = 1) const;
355  void modifyObjective(double value);
357  int lastIterationNumber(int back = 1) const;
359  void clearIterationNumbers();
361  inline void newOddState()
362  {
363  oddState_ = -oddState_ - 1;
364  }
365  inline void endOddState()
366  {
367  oddState_ = abs(oddState_);
368  }
369  inline void clearOddState()
370  {
371  oddState_ = 0;
372  }
373  inline int oddState() const
374  {
375  return oddState_;
376  }
378  inline int badTimes() const
379  {
380  return numberBadTimes_;
381  }
382  inline void clearBadTimes()
383  {
384  numberBadTimes_ = 0;
385  }
387  inline int reallyBadTimes() const
388  {
389  return numberReallyBadTimes_;
390  }
392  {
394  }
396  inline int timesFlagged() const
397  {
398  return numberTimesFlagged_;
399  }
400  inline void clearTimesFlagged()
401  {
403  }
404  inline void incrementTimesFlagged()
405  {
407  }
408 
410 
411 #define CLP_PROGRESS 5
412  //#define CLP_PROGRESS_WEIGHT 10
414  double objective_[CLP_PROGRESS];
420 #ifdef CLP_PROGRESS_WEIGHT
421  double objectiveWeight_[CLP_PROGRESS_WEIGHT];
424  double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
426  double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
428  double drop_;
430  double best_;
431 #endif
432  double initialWeight_;
434 #define CLP_CYCLE 12
435  //double obj_[CLP_CYCLE];
446 #ifdef CLP_PROGRESS_WEIGHT
447  int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
450  int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
451 #endif
452  int numberTimes_;
463 };
464 
465 #include "ClpConfig.h"
466 #if CLP_HAS_ABC
467 #include "AbcCommon.hpp"
469 class AbcSimplexProgress : public ClpSimplexProgress {
470 
471 public:
474  AbcSimplexProgress();
476 
478  AbcSimplexProgress(ClpSimplex *model);
479 
481  AbcSimplexProgress(const AbcSimplexProgress &);
482 
484  AbcSimplexProgress &operator=(const AbcSimplexProgress &rhs);
486  ~AbcSimplexProgress();
487 
489 
495  int looping();
496 
498 
500 };
501 #endif
502 #endif
503 
504 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
505 */
int numberBadTimes_
Number of times it looked like loop.
Definition: ClpSolve.hpp:455
bool doDupcol() const
Whether we want to do dupcol part of presolve.
Definition: ClpSolve.hpp:209
void newOddState()
Odd state.
Definition: ClpSolve.hpp:361
#define CLP_CYCLE
Definition: ClpSolve.hpp:434
double objective_[CLP_PROGRESS]
Objective values.
Definition: ClpSolve.hpp:415
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:225
bool doImpliedFree() const
Whether we want to do impliedfree part of presolve.
Definition: ClpSolve.hpp:197
bool infeasibleReturn() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:120
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 basi...
Definition: ClpSolve.hpp:261
bool doKillSmall() const
Whether we want to kill small substitutions.
Definition: ClpSolve.hpp:245
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:365
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:129
~ClpSolve()
Destructor.
int numberTimesFlagged_
Number of times no iterations as flagged.
Definition: ClpSolve.hpp:459
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:233
void reset()
Resets as much as possible.
bool doTripleton() const
Whether we want to do tripleton part of presolve.
Definition: ClpSolve.hpp:161
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:373
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:270
int oddState_
If things are in an odd state.
Definition: ClpSolve.hpp:461
PresolveType presolveType_
Presolve type.
Definition: ClpSolve.hpp:292
char way_[CLP_CYCLE]
Objective values.
Definition: ClpSolve.hpp:439
#define CLP_PROGRESS
Definition: ClpSolve.hpp:411
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:189
SolveType
enums for solve function
Definition: ClpSolve.hpp:24
SolveType method_
Solve type.
Definition: ClpSolve.hpp:290
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:153
For saving extra information to see if looping.
Definition: ClpSolve.hpp:310
bool doDuprow() const
Whether we want to do duprow part of presolve.
Definition: ClpSolve.hpp:221
bool doForcing() const
Whether we want to do forcing part of presolve.
Definition: ClpSolve.hpp:185
int substitution() const
Largest column for substitution (normally 3)
Definition: ClpSolve.hpp:266
int numberTimes_
Number of times checked (so won't stop too early)
Definition: ClpSolve.hpp:453
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:382
int in_[CLP_CYCLE]
For cycle checking.
Definition: ClpSolve.hpp:437
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:257
double realInfeasibility_[CLP_PROGRESS]
Sum of real primal infeasibilities for primal.
Definition: ClpSolve.hpp:419
double infeasibility_[CLP_PROGRESS]
Sum of infeasibilities for algorithm.
Definition: ClpSolve.hpp:417
int iterationNumber_[CLP_PROGRESS]
Iteration number at which occurred.
Definition: ClpSolve.hpp:445
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:400
void setIndependentOption(int type, int value)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:274
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:387
bool doSingleton() const
Whether we want to do singleton part of presolve.
Definition: ClpSolve.hpp:137
int independentOption(int type) const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:278
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:106
bool doTighten() const
Whether we want to do tighten part of presolve.
Definition: ClpSolve.hpp:173
int numberInfeasibilities_[CLP_PROGRESS]
Number of infeasibilities.
Definition: ClpSolve.hpp:443
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:438
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:213
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 basi...
Definition: ClpSolve.hpp:141
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:433
int badTimes() const
number of bad times
Definition: ClpSolve.hpp:378
int numberPasses_
Amount of presolve.
Definition: ClpSolve.hpp:294
int timesFlagged() const
number of times flagged
Definition: ClpSolve.hpp:396
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:305
void setDoKillSmall(bool doKill)
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...
Definition: ClpSolve.hpp:249
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:237
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:165
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:149
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:177
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:201
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:391
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:369
int extraInfo_[7]
Extra information.
Definition: ClpSolve.hpp:298
ClpSimplex * model_
Pointer back to model so we can get information.
Definition: ClpSolve.hpp:441
ClpSimplexProgress & operator=(const ClpSimplexProgress &rhs)
Assignment operator. This copies the data.
int numberReallyBadTimes_
Number really bad times.
Definition: ClpSolve.hpp:457
ClpSimplexProgress()
Default constructor.
int options_[7]
Options - last is switch for OsiClp.
Definition: ClpSolve.hpp:296
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:404
int getPresolvePasses() const
Special options - bits 0 4 - use crash (default allslack in dual, idiot in primal) 8 - all slack basi...