Cgl  0.60.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Idiot.hpp
Go to the documentation of this file.
1 /* $Id: Idiot.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
2 // Copyright (C) 2002, 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 // "Idiot" as the name of this algorithm is copylefted. If you want to change
7 // the name then it should be something equally stupid (but not "Stupid") or
8 // even better something witty.
9 
10 #ifndef Idiot_H
11 #define Idiot_H
12 #ifndef OSI_IDIOT
13 #include "ClpSimplex.hpp"
14 #define OsiSolverInterface ClpSimplex
15 #else
16 #include "OsiSolverInterface.hpp"
17 typedef int CoinBigIndex;
18 #endif
19 class CoinMessageHandler;
20 class CoinMessages;
22 typedef struct {
23  double infeas;
24  double objval;
25  double dropThis;
26  double weighted;
27  double sumSquared;
28  double djAtBeginning;
29  double djAtEnd;
30  int iteration;
31 } IdiotResult;
48 class Idiot {
49 
50 public:
55  Idiot();
58  Idiot(OsiSolverInterface &model);
59 
61  Idiot(const Idiot &);
63  Idiot &operator=(const Idiot &rhs);
65  ~Idiot();
67 
71  void solve();
74  void crash(int numberPass, CoinMessageHandler *handler,
75  const CoinMessages *messages, bool doCrossover = true);
85  void crossOver(int mode);
87 
93  inline double getStartingWeight() const
94  {
95  return mu_;
96  }
97  inline void setStartingWeight(double value)
98  {
99  mu_ = value;
100  }
103  inline double getWeightFactor() const
104  {
105  return muFactor_;
106  }
107  inline void setWeightFactor(double value)
108  {
109  muFactor_ = value;
110  }
114  inline double getFeasibilityTolerance() const
115  {
116  return smallInfeas_;
117  }
118  inline void setFeasibilityTolerance(double value)
119  {
120  smallInfeas_ = value;
121  }
125  inline double getReasonablyFeasible() const
126  {
127  return reasonableInfeas_;
128  }
129  inline void setReasonablyFeasible(double value)
130  {
131  reasonableInfeas_ = value;
132  }
135  inline double getExitInfeasibility() const
136  {
137  return exitFeasibility_;
138  }
139  inline void setExitInfeasibility(double value)
140  {
141  exitFeasibility_ = value;
142  }
145  inline int getMajorIterations() const
146  {
147  return majorIterations_;
148  }
149  inline void setMajorIterations(int value)
150  {
151  majorIterations_ = value;
152  }
159  inline int getMinorIterations() const
160  {
161  return maxIts2_;
162  }
163  inline void setMinorIterations(int value)
164  {
165  maxIts2_ = value;
166  }
167  // minor iterations for first time
168  inline int getMinorIterations0() const
169  {
170  return maxIts_;
171  }
172  inline void setMinorIterations0(int value)
173  {
174  maxIts_ = value;
175  }
179  inline int getReduceIterations() const
180  {
181  return maxBigIts_;
182  }
183  inline void setReduceIterations(int value)
184  {
185  maxBigIts_ = value;
186  }
188  inline int getLogLevel() const
189  {
190  return logLevel_;
191  }
192  inline void setLogLevel(int value)
193  {
194  logLevel_ = value;
195  }
197  inline int getLightweight() const
198  {
199  return lightWeight_;
200  }
201  inline void setLightweight(int value)
202  {
203  lightWeight_ = value;
204  }
206  inline int getStrategy() const
207  {
208  return strategy_;
209  }
210  inline void setStrategy(int value)
211  {
212  strategy_ = value;
213  }
215  inline double getDropEnoughFeasibility() const
216  {
217  return dropEnoughFeasibility_;
218  }
219  inline void setDropEnoughFeasibility(double value)
220  {
221  dropEnoughFeasibility_ = value;
222  }
224  inline double getDropEnoughWeighted() const
225  {
226  return dropEnoughWeighted_;
227  }
228  inline void setDropEnoughWeighted(double value)
229  {
230  dropEnoughWeighted_ = value;
231  }
233  inline void setModel(OsiSolverInterface *model)
234  {
235  model_ = model;
236  };
238 
240 private:
242  // allow public!
243 public:
244  void solve2(CoinMessageHandler *handler, const CoinMessages *messages);
245 
246 private:
248  int nrows, int ncols, double *rowsol, double *colsol,
249  double *pi, double *djs, const double *origcost,
250  double *rowlower,
251  double *rowupper, const double *lower,
252  const double *upper, const double *element,
253  const int *row, const CoinBigIndex *colcc,
254  const int *length, double *lambda,
255  int maxIts, double mu, double drop,
256  double maxmin, double offset,
257  int strategy, double djTol, double djExit, double djFlag,
258  CoinThreadRandom *randomNumberGenerator);
259  int dropping(IdiotResult result,
260  double tolerance,
261  double small,
262  int *nbad);
263  IdiotResult objval(int nrows, int ncols, double *rowsol, double *colsol,
264  double *pi, double *djs, const double *cost,
265  const double *rowlower,
266  const double *rowupper, const double *lower,
267  const double *upper, const double *elemnt,
268  const int *row, const CoinBigIndex *columnStart,
269  const int *length, int extraBlock, int *rowExtra,
270  double *solExtra, double *elemExtra, double *upperExtra,
271  double *costExtra, double weight);
272  // Deals with whenUsed and slacks
273  int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd,
274  double *colsol, const double *lower, const double *upper,
275  const double *rowLower, const double *rowUpper,
276  const double *cost, const double *element, double fixTolerance, double &objChange,
277  double &infChange, double &maxInfeasibility);
278 
279 private:
282 
283  double djTolerance_;
284  double mu_; /* starting mu */
285  double drop_; /* exit if drop over 5 checks less than this */
286  double muFactor_; /* reduce mu by this */
287  double stopMu_; /* exit if mu gets smaller than this */
288  double smallInfeas_; /* feasibility tolerance */
289  double reasonableInfeas_; /* use lambdas if feasibility less than this */
290  double exitDrop_; /* candidate for stopping after a major iteration */
291  double muAtExit_; /* mu on exit */
292  double exitFeasibility_; /* exit if infeasibility less than this */
293  double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
294  double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
295  int *whenUsed_; /* array to say what was used */
296  int maxBigIts_; /* always reduce mu after this */
297  int maxIts_; /* do this many iterations on first go */
300  int logFreq_;
301  int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
302  int lambdaIterations_; /* do at least this many lambda iterations */
303  int maxIts2_; /* do this many iterations on subsequent goes */
304  int strategy_; /* 0 - default strategy
305  1 - do accelerator step but be cautious
306  2 - do not do accelerator step
307  4 - drop, exitDrop and djTolerance all relative
308  8 - keep accelerator step to theta=10.0
309 
310  32 - Scale
311  512 - crossover
312  2048 - keep lambda across mu change
313  4096 - return best solution (not last found)
314  8192 - always do a presolve in crossover
315  16384 - costed slacks found - so whenUsed_ longer
316  32768 - experimental 1
317  65536 - experimental 2
318  131072 - experimental 3
319  262144 - just values pass etc
320  524288 - don't treat structural slacks as slacks */
321 
322  int lightWeight_; // 0 - normal, 1 lightweight
323 };
324 #endif
325 
326 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
327 */
double drop_
Definition: Idiot.hpp:285
void solve()
Get an approximate solution with the idiot code.
int maxBigIts_
Definition: Idiot.hpp:296
void setStrategy(int value)
Definition: Idiot.hpp:210
int getMinorIterations() const
Minor iterations.
Definition: Idiot.hpp:159
double exitDrop_
Definition: Idiot.hpp:290
double reasonableInfeas_
Definition: Idiot.hpp:289
double muFactor_
Definition: Idiot.hpp:286
int maxIts2_
Definition: Idiot.hpp:303
Idiot & operator=(const Idiot &rhs)
Assignment operator. This copies the data.
int getMinorIterations0() const
Definition: Idiot.hpp:168
double getDropEnoughWeighted() const
Fine tuning - okay if weighted obj drop this factor.
Definition: Idiot.hpp:224
double getExitInfeasibility() const
Exit infeasibility - exit if sum of infeasibilities less than this.
Definition: Idiot.hpp:135
double getDropEnoughFeasibility() const
Fine tuning - okay if feasibility drop this factor.
Definition: Idiot.hpp:215
void setDropEnoughFeasibility(double value)
Definition: Idiot.hpp:219
void setReduceIterations(int value)
Definition: Idiot.hpp:183
void setMinorIterations0(int value)
Definition: Idiot.hpp:172
double sumSquared
Definition: Idiot.hpp:27
int getMajorIterations() const
Major iterations.
Definition: Idiot.hpp:145
double exitFeasibility_
Definition: Idiot.hpp:292
double getFeasibilityTolerance() const
Feasibility tolerance - problem essentially feasible if individual infeasibilities less than this...
Definition: Idiot.hpp:114
IdiotResult IdiSolve(int nrows, int ncols, double *rowsol, double *colsol, double *pi, double *djs, const double *origcost, double *rowlower, double *rowupper, const double *lower, const double *upper, const double *element, const int *row, const CoinBigIndex *colcc, const int *length, double *lambda, int maxIts, double mu, double drop, double maxmin, double offset, int strategy, double djTol, double djExit, double djFlag, CoinThreadRandom *randomNumberGenerator)
void solve2(CoinMessageHandler *handler, const CoinMessages *messages)
Stuff for internal use.
Base class for message handling.
void setDropEnoughWeighted(double value)
Definition: Idiot.hpp:228
void setMinorIterations(int value)
Definition: Idiot.hpp:163
double mu_
Definition: Idiot.hpp:284
double dropEnoughFeasibility_
Definition: Idiot.hpp:293
Abstract Base Class for describing an interface to a solver.
void setWeightFactor(double value)
Definition: Idiot.hpp:107
double djTolerance_
Definition: Idiot.hpp:283
double djAtEnd
Definition: Idiot.hpp:29
int strategy_
Definition: Idiot.hpp:304
int iteration
Definition: Idiot.hpp:30
IdiotResult objval(int nrows, int ncols, double *rowsol, double *colsol, double *pi, double *djs, const double *cost, const double *rowlower, const double *rowupper, const double *lower, const double *upper, const double *elemnt, const int *row, const CoinBigIndex *columnStart, const int *length, int extraBlock, int *rowExtra, double *solExtra, double *elemExtra, double *upperExtra, double *costExtra, double weight)
void setReasonablyFeasible(double value)
Definition: Idiot.hpp:129
int getLogLevel() const
Amount of information - default of 1 should be okay.
Definition: Idiot.hpp:188
int * whenUsed_
Definition: Idiot.hpp:295
int logFreq_
Definition: Idiot.hpp:300
int majorIterations_
Definition: Idiot.hpp:298
OsiSolverInterface * model_
Underlying model.
Definition: Idiot.hpp:281
int getStrategy() const
strategy
Definition: Idiot.hpp:206
void setMajorIterations(int value)
Definition: Idiot.hpp:149
void crash(int numberPass, CoinMessageHandler *handler, const CoinMessages *messages, bool doCrossover=true)
Lightweight "crash".
int maxIts_
Definition: Idiot.hpp:297
void setModel(OsiSolverInterface *model)
Set model.
Definition: Idiot.hpp:233
int dropping(IdiotResult result, double tolerance, double small, int *nbad)
Idiot()
Default constructor.
double dropThis
Definition: Idiot.hpp:25
double weighted
Definition: Idiot.hpp:26
This class implements a very silly algorithm.
Definition: Idiot.hpp:48
double getReasonablyFeasible() const
Reasonably feasible.
Definition: Idiot.hpp:125
double dropEnoughWeighted_
Definition: Idiot.hpp:294
double objval
Definition: Idiot.hpp:24
int CoinBigIndex
int lambdaIterations_
Definition: Idiot.hpp:302
int lightWeight_
Definition: Idiot.hpp:322
void setExitInfeasibility(double value)
Definition: Idiot.hpp:139
int getLightweight() const
How lightweight - 0 not, 1 yes, 2 very lightweight.
Definition: Idiot.hpp:197
double infeas
Definition: Idiot.hpp:23
int checkFrequency_
Definition: Idiot.hpp:301
double smallInfeas_
Definition: Idiot.hpp:288
void crossOver(int mode)
Use simplex to get an optimal solution mode is how many steps the simplex crossover should take to ar...
~Idiot()
Destructor.
void setStartingWeight(double value)
Definition: Idiot.hpp:97
int logLevel_
Definition: Idiot.hpp:299
int getReduceIterations() const
Reduce weight after this many major iterations.
Definition: Idiot.hpp:179
double djAtBeginning
Definition: Idiot.hpp:28
void setLogLevel(int value)
Definition: Idiot.hpp:192
int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd, double *colsol, const double *lower, const double *upper, const double *rowLower, const double *rowUpper, const double *cost, const double *element, double fixTolerance, double &objChange, double &infChange, double &maxInfeasibility)
double getWeightFactor() const
Weight factor - weight multiplied by this when changes, default 0.333.
Definition: Idiot.hpp:103
for use internally
Definition: Idiot.hpp:22
double getStartingWeight() const
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:93
double muAtExit_
Definition: Idiot.hpp:291
void setLightweight(int value)
Definition: Idiot.hpp:201
void setFeasibilityTolerance(double value)
Definition: Idiot.hpp:118
Class to hold and manipulate an array of massaged messages.
Class for thread specific random numbers.
double stopMu_
Definition: Idiot.hpp:287