Clp  1.17.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 */
void reset()
Resets as much as possible.
bool doSingletonColumn() const
Whether we want to do singleton column part of presolve.
Definition: ClpSolve.hpp:233
This is a very simple class to guide algorithms.
Definition: ClpSolve.hpp:20
int numberInfeasibilities(int back=1) const
Returns number of primal infeasibilities (if -1) - current if (0)
bool doDupcol() const
Whether we want to do dupcol part of presolve.
Definition: ClpSolve.hpp:209
void startCheck()
Start check at beginning of whileIterating.
void setDoSingletonColumn(bool doSingleton_)
Definition: ClpSolve.hpp:237
SolveType method_
Solve type.
Definition: ClpSolve.hpp:290
bool doTripleton() const
Whether we want to do tripleton part of presolve.
Definition: ClpSolve.hpp:161
int options_[7]
Options - last is switch for OsiClp.
Definition: ClpSolve.hpp:296
void setIndependentOption(int type, int value)
Definition: ClpSolve.hpp:274
bool doSingleton() const
Whether we want to do singleton part of presolve.
Definition: ClpSolve.hpp:137
int getSpecialOption(int which) const
bool doImpliedFree() const
Whether we want to do impliedfree part of presolve.
Definition: ClpSolve.hpp:197
SolveType getSolveType()
int independentOptions_[3]
Extra algorithm dependent options 0 - if set return from clpsolve if infeasible 1 - To be copied over...
Definition: ClpSolve.hpp:305
ClpSimplex * model_
Pointer back to model so we can get information.
Definition: ClpSolve.hpp:441
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...
int out_[CLP_CYCLE]
Definition: ClpSolve.hpp:438
For saving extra information to see if looping.
Definition: ClpSolve.hpp:310
int numberTimes_
Number of times checked (so won't stop too early)
Definition: ClpSolve.hpp:453
#define CLP_PROGRESS
Definition: ClpSolve.hpp:411
void newOddState()
Odd state.
Definition: ClpSolve.hpp:361
bool doDuprow() const
Whether we want to do duprow part of presolve.
Definition: ClpSolve.hpp:221
void generateCpp(FILE *fp)
Generates code for above constructor.
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...
void setDoTripleton(bool doTripleton_)
Definition: ClpSolve.hpp:165
void setPresolveType(PresolveType amount, int extraInfo=-1)
double lastInfeasibility(int back=1) const
Returns real primal infeasibility (if -1) - current if (0)
ClpSolve()
Default constructor.
~ClpSimplexProgress()
Destructor.
int cycle(int in, int out, int wayIn, int wayOut)
Returns cycle length in whileIterating.
int in_[CLP_CYCLE]
For cycle checking.
Definition: ClpSolve.hpp:437
int numberReallyBadTimes_
Number really bad times.
Definition: ClpSolve.hpp:457
int getPresolvePasses() const
int reallyBadTimes() const
number of really bad times
Definition: ClpSolve.hpp:387
void incrementTimesFlagged()
Definition: ClpSolve.hpp:404
void setDoForcing(bool doForcing_)
Definition: ClpSolve.hpp:189
void clearIterationNumbers()
clears all iteration numbers (to switch off panic)
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:106
void setDoDupcol(bool doDupcol_)
Definition: ClpSolve.hpp:213
void fillFromModel(ClpSimplex *model)
Fill from model.
bool doKillSmall() const
Whether we want to kill small substitutions.
Definition: ClpSolve.hpp:245
void setDoTighten(bool doTighten_)
Definition: ClpSolve.hpp:177
SolveType
enums for solve function
Definition: ClpSolve.hpp:24
void setDoDual(bool doDual_)
Definition: ClpSolve.hpp:129
double lastObjective(int back=1) const
Returns previous objective (if -1) - current if (0)
int iterationNumber_[CLP_PROGRESS]
Iteration number at which occurred.
Definition: ClpSolve.hpp:445
void setDoSingleton(bool doSingleton_)
Definition: ClpSolve.hpp:141
double realInfeasibility_[CLP_PROGRESS]
Sum of real primal infeasibilities for primal.
Definition: ClpSolve.hpp:419
void setSolveType(SolveType method, int extraInfo=-1)
Solve types.
int lastIterationNumber(int back=1) const
Returns previous iteration number (if -1) - current if (0)
void incrementReallyBadTimes()
Definition: ClpSolve.hpp:391
void clearTimesFlagged()
Definition: ClpSolve.hpp:400
void setDoDuprow(bool doDuprow_)
Definition: ClpSolve.hpp:225
int timesFlagged() const
number of times flagged
Definition: ClpSolve.hpp:396
double infeasibility_[CLP_PROGRESS]
Sum of infeasibilities for algorithm.
Definition: ClpSolve.hpp:417
void setDoKillSmall(bool doKill)
Definition: ClpSolve.hpp:249
int presolveActions() const
Set whole group.
Definition: ClpSolve.hpp:257
ClpSolve & operator=(const ClpSolve &rhs)
Assignment operator. This copies the data.
bool infeasibleReturn() const
Definition: ClpSolve.hpp:120
bool doDoubleton() const
Whether we want to do doubleton part of presolve.
Definition: ClpSolve.hpp:149
void setInfeasibleReturn(bool trueFalse)
Say to return at once if infeasible, default is to solve.
int numberTimesFlagged_
Number of times no iterations as flagged.
Definition: ClpSolve.hpp:459
bool doTighten() const
Whether we want to do tighten part of presolve.
Definition: ClpSolve.hpp:173
~ClpSolve()
Destructor.
ClpSimplexProgress & operator=(const ClpSimplexProgress &rhs)
Assignment operator. This copies the data.
int oddState_
If things are in an odd state.
Definition: ClpSolve.hpp:461
int badTimes() const
number of bad times
Definition: ClpSolve.hpp:378
void setDoImpliedFree(bool doImpliedfree)
Definition: ClpSolve.hpp:201
int independentOption(int type) const
Definition: ClpSolve.hpp:278
ClpSimplexProgress()
Default constructor.
void setPresolveActions(int action)
Definition: ClpSolve.hpp:261
void modifyObjective(double value)
Modify objective e.g. if dual infeasible in dual.
double initialWeight_
Initial weight for weights.
Definition: ClpSolve.hpp:433
void setDoDoubleton(bool doDoubleton_)
Definition: ClpSolve.hpp:153
int extraInfo_[7]
Extra information.
Definition: ClpSolve.hpp:298
PresolveType presolveType_
Presolve type.
Definition: ClpSolve.hpp:292
void setInfeasibility(double value)
Set real primal infeasibility and move back.
int oddState() const
Definition: ClpSolve.hpp:373
double objective_[CLP_PROGRESS]
Objective values.
Definition: ClpSolve.hpp:415
int numberPasses_
Amount of presolve.
Definition: ClpSolve.hpp:294
bool doForcing() const
Whether we want to do forcing part of presolve.
Definition: ClpSolve.hpp:185
int numberInfeasibilities_[CLP_PROGRESS]
Number of infeasibilities.
Definition: ClpSolve.hpp:443
char way_[CLP_CYCLE]
Definition: ClpSolve.hpp:439
PresolveType getPresolveType()
#define CLP_CYCLE
Definition: ClpSolve.hpp:434
bool doDual() const
Whether we want to do dual part of presolve.
Definition: ClpSolve.hpp:125
int numberBadTimes_
Number of times it looked like loop.
Definition: ClpSolve.hpp:455
void setSubstitution(int value)
Definition: ClpSolve.hpp:270
int substitution() const
Largest column for substitution (normally 3)
Definition: ClpSolve.hpp:266
int getExtraInfo(int which) const
Extra info for idiot (or sprint)