Idiot.hpp
Go to the documentation of this file.
1 /* $Id: Idiot.hpp 1525 2010-02-26 17:27:59Z mjs $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // "Idiot" as the name of this algorithm is copylefted. If you want to change
5 // the name then it should be something equally stupid (but not "Stupid") or
6 // even better something witty.
7 
8 #ifndef Idiot_H
9 #define Idiot_H
10 #ifndef OSI_IDIOT
11 #include "ClpSimplex.hpp"
12 #define OsiSolverInterface ClpSimplex
13 #else
14 #include "OsiSolverInterface.hpp"
15 typedef int CoinBigIndex;
16 #endif
17 class CoinMessageHandler;
18 class CoinMessages;
20 typedef struct {
21  double infeas;
22  double objval;
23  double dropThis;
24  double weighted;
25  double sumSquared;
26  double djAtBeginning;
27  double djAtEnd;
28  int iteration;
29 } IdiotResult;
46 class Idiot {
47 
48 public:
49 
54  Idiot ( );
57  Idiot ( OsiSolverInterface & model );
58 
60  Idiot(const Idiot &);
62  Idiot & operator=(const Idiot & rhs);
64  ~Idiot ( );
66 
67 
71  void solve();
74  void crash(int numberPass, CoinMessageHandler * handler,
75  const CoinMessages * messages, bool doCrossover = true);
85  void crossOver(int mode);
87 
88 
94  inline double getStartingWeight() const {
95  return mu_;
96  }
97  inline void setStartingWeight(double value) {
98  mu_ = value;
99  }
102  inline double getWeightFactor() const {
103  return muFactor_;
104  }
105  inline void setWeightFactor(double value) {
106  muFactor_ = value;
107  }
111  inline double getFeasibilityTolerance() const {
112  return smallInfeas_;
113  }
114  inline void setFeasibilityTolerance(double value) {
115  smallInfeas_ = value;
116  }
120  inline double getReasonablyFeasible() const {
121  return reasonableInfeas_;
122  }
123  inline void setReasonablyFeasible(double value) {
124  reasonableInfeas_ = value;
125  }
128  inline double getExitInfeasibility() const {
129  return exitFeasibility_;
130  }
131  inline void setExitInfeasibility(double value) {
132  exitFeasibility_ = value;
133  }
136  inline int getMajorIterations() const {
137  return majorIterations_;
138  }
139  inline void setMajorIterations(int value) {
140  majorIterations_ = value;
141  }
148  inline int getMinorIterations() const {
149  return maxIts2_;
150  }
151  inline void setMinorIterations(int value) {
152  maxIts2_ = value;
153  }
154  // minor iterations for first time
155  inline int getMinorIterations0() const {
156  return maxIts_;
157  }
158  inline void setMinorIterations0(int value) {
159  maxIts_ = value;
160  }
164  inline int getReduceIterations() const {
165  return maxBigIts_;
166  }
167  inline void setReduceIterations(int value) {
168  maxBigIts_ = value;
169  }
171  inline int getLogLevel() const {
172  return logLevel_;
173  }
174  inline void setLogLevel(int value) {
175  logLevel_ = value;
176  }
178  inline int getLightweight() const {
179  return lightWeight_;
180  }
181  inline void setLightweight(int value) {
182  lightWeight_ = value;
183  }
185  inline int getStrategy() const {
186  return strategy_;
187  }
188  inline void setStrategy(int value) {
189  strategy_ = value;
190  }
192  inline double getDropEnoughFeasibility() const {
193  return dropEnoughFeasibility_;
194  }
195  inline void setDropEnoughFeasibility(double value) {
196  dropEnoughFeasibility_ = value;
197  }
199  inline double getDropEnoughWeighted() const {
200  return dropEnoughWeighted_;
201  }
202  inline void setDropEnoughWeighted(double value) {
203  dropEnoughWeighted_ = value;
204  }
206 
207 
209 private:
210 
212  // allow public!
213 public:
214  void solve2(CoinMessageHandler * handler, const CoinMessages *messages);
215 private:
217  int nrows, int ncols, double * rowsol , double * colsol,
218  double * pi, double * djs, const double * origcost ,
219  double * rowlower,
220  double * rowupper, const double * lower,
221  const double * upper, const double * element,
222  const int * row, const CoinBigIndex * colcc,
223  const int * length, double * lambda,
224  int maxIts, double mu, double drop,
225  double maxmin, double offset,
226  int strategy, double djTol, double djExit, double djFlag,
227  CoinThreadRandom * randomNumberGenerator);
228  int dropping(IdiotResult result,
229  double tolerance,
230  double small,
231  int *nbad);
232  IdiotResult objval(int nrows, int ncols, double * rowsol , double * colsol,
233  double * pi, double * djs, const double * cost ,
234  const double * rowlower,
235  const double * rowupper, const double * lower,
236  const double * upper, const double * elemnt,
237  const int * row, const CoinBigIndex * columnStart,
238  const int * length, int extraBlock, int * rowExtra,
239  double * solExtra, double * elemExtra, double * upperExtra,
240  double * costExtra, double weight);
241  // Deals with whenUsed and slacks
242  int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd,
243  double * colsol, const double * lower, const double * upper,
244  const double * rowLower, const double * rowUpper,
245  const double * cost, const double * element, double fixTolerance, double & objChange,
246  double & infChange);
247 private:
250 
251  double djTolerance_;
252  double mu_; /* starting mu */
253  double drop_; /* exit if drop over 5 checks less than this */
254  double muFactor_; /* reduce mu by this */
255  double stopMu_; /* exit if mu gets smaller than this */
256  double smallInfeas_; /* feasibility tolerance */
257  double reasonableInfeas_; /* use lambdas if feasibility less than this */
258  double exitDrop_; /* candidate for stopping after a major iteration */
259  double muAtExit_; /* mu on exit */
260  double exitFeasibility_; /* exit if infeasibility less than this */
261  double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
262  double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
263  int * whenUsed_; /* array to say what was used */
264  int maxBigIts_; /* always reduce mu after this */
265  int maxIts_; /* do this many iterations on first go */
268  int logFreq_;
269  int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
270  int lambdaIterations_; /* do at least this many lambda iterations */
271  int maxIts2_; /* do this many iterations on subsequent goes */
272  int strategy_; /* 0 - default strategy
273  1 - do accelerator step but be cautious
274  2 - do not do accelerator step
275  4 - drop, exitDrop and djTolerance all relative
276  8 - keep accelerator step to theta=10.0
277 
278  32 - Scale
279  512 - crossover
280  2048 - keep lambda across mu change
281  4096 - return best solution (not last found)
282  8192 - always do a presolve in crossover
283  16384 - costed slacks found - so whenUsed_ longer */
284  int lightWeight_; // 0 - normal, 1 lightweight
285 };
286 #endif
int lightWeight_
Definition: Idiot.hpp:284
Idiot()
Default constructor.
double getFeasibilityTolerance() const
Feasibility tolerance - problem essentially feasible if individual infeasibilities less than this...
Definition: Idiot.hpp:111
double mu_
Definition: Idiot.hpp:252
int getMajorIterations() const
Major iterations.
Definition: Idiot.hpp:136
double djAtEnd
Definition: Idiot.hpp:27
for use internally
Definition: Idiot.hpp:20
double sumSquared
Definition: Idiot.hpp:25
int getMinorIterations() const
Minor iterations.
Definition: Idiot.hpp:148
void setExitInfeasibility(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:131
int getReduceIterations() const
Reduce weight after this many major iterations.
Definition: Idiot.hpp:164
double drop_
Definition: Idiot.hpp:253
double djAtBeginning
Definition: Idiot.hpp:26
void setDropEnoughWeighted(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:202
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)
int dropping(IdiotResult result, double tolerance, double small, int *nbad)
void setReduceIterations(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:167
void setStartingWeight(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:97
void setFeasibilityTolerance(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:114
double exitFeasibility_
Definition: Idiot.hpp:260
void setMajorIterations(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:139
double exitDrop_
Definition: Idiot.hpp:258
double muFactor_
Definition: Idiot.hpp:254
double getDropEnoughWeighted() const
Fine tuning - okay if weighted obj drop this factor.
Definition: Idiot.hpp:199
void setReasonablyFeasible(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:123
double dropEnoughWeighted_
Definition: Idiot.hpp:262
double getStartingWeight() const
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:94
void setLogLevel(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:174
~Idiot()
Destructor.
void setMinorIterations(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:151
int getMinorIterations0() const
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:155
double weighted
Definition: Idiot.hpp:24
void solve()
Get an approximate solution with the idiot code.
int lambdaIterations_
Definition: Idiot.hpp:270
void crossOver(int mode)
Use simplex to get an optimal solution mode is how many steps the simplex crossover should take to ar...
int maxIts_
Definition: Idiot.hpp:265
int logLevel_
Definition: Idiot.hpp:267
double reasonableInfeas_
Definition: Idiot.hpp:257
int majorIterations_
Definition: Idiot.hpp:266
void setWeightFactor(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:105
double getDropEnoughFeasibility() const
Fine tuning - okay if feasibility drop this factor.
Definition: Idiot.hpp:192
int * whenUsed_
Definition: Idiot.hpp:263
void setLightweight(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:181
double muAtExit_
Definition: Idiot.hpp:259
double smallInfeas_
Definition: Idiot.hpp:256
double dropEnoughFeasibility_
Definition: Idiot.hpp:261
int getStrategy() const
strategy
Definition: Idiot.hpp:185
void crash(int numberPass, CoinMessageHandler *handler, const CoinMessages *messages, bool doCrossover=true)
Lightweight "crash".
int iteration
Definition: Idiot.hpp:28
double dropThis
Definition: Idiot.hpp:23
void setDropEnoughFeasibility(double value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:195
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)
int strategy_
Definition: Idiot.hpp:272
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)
int getLogLevel() const
Amount of information - default of 1 should be okay.
Definition: Idiot.hpp:171
void solve2(CoinMessageHandler *handler, const CoinMessages *messages)
Stuff for internal use.
Idiot & operator=(const Idiot &rhs)
Assignment operator. This copies the data.
void setStrategy(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:188
double djTolerance_
Definition: Idiot.hpp:251
double objval
Definition: Idiot.hpp:22
int maxIts2_
Definition: Idiot.hpp:271
#define OsiSolverInterface
Definition: Idiot.hpp:12
double stopMu_
Definition: Idiot.hpp:255
int maxBigIts_
Definition: Idiot.hpp:264
OsiSolverInterface * model_
Underlying model.
Definition: Idiot.hpp:249
double infeas
Definition: Idiot.hpp:21
int checkFrequency_
Definition: Idiot.hpp:269
This class implements a very silly algorithm.
Definition: Idiot.hpp:46
double getReasonablyFeasible() const
Reasonably feasible.
Definition: Idiot.hpp:120
void setMinorIterations0(int value)
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:158
double getExitInfeasibility() const
Exit infeasibility - exit if sum of infeasibilities less than this.
Definition: Idiot.hpp:128
double getWeightFactor() const
Weight factor - weight multiplied by this when changes, default 0.333.
Definition: Idiot.hpp:102
int getLightweight() const
How lightweight - 0 not, 1 yes, 2 very lightweight.
Definition: Idiot.hpp:178
int logFreq_
Definition: Idiot.hpp:268