Cgl 0.59.7

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 2143 2015-05-20 15:49:17Z forrest $ */
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:
51
56 Idiot ( );
59 Idiot ( OsiSolverInterface & model );
60
62 Idiot(const Idiot &);
64 Idiot & operator=(const Idiot & rhs);
66 ~Idiot ( );
68
69
73 void solve();
76 void crash(int numberPass, CoinMessageHandler * handler,
77 const CoinMessages * messages, bool doCrossover = true);
87 void crossOver(int mode);
89
90
96 inline double getStartingWeight() const {
97 return mu_;
98 }
99 inline void setStartingWeight(double value) {
100 mu_ = value;
101 }
104 inline double getWeightFactor() const {
105 return muFactor_;
106 }
107 inline void setWeightFactor(double value) {
108 muFactor_ = value;
109 }
113 inline double getFeasibilityTolerance() const {
114 return smallInfeas_;
115 }
116 inline void setFeasibilityTolerance(double value) {
117 smallInfeas_ = value;
118 }
122 inline double getReasonablyFeasible() const {
123 return reasonableInfeas_;
124 }
125 inline void setReasonablyFeasible(double value) {
126 reasonableInfeas_ = value;
127 }
130 inline double getExitInfeasibility() const {
131 return exitFeasibility_;
132 }
133 inline void setExitInfeasibility(double value) {
134 exitFeasibility_ = value;
135 }
138 inline int getMajorIterations() const {
139 return majorIterations_;
140 }
141 inline void setMajorIterations(int value) {
142 majorIterations_ = value;
143 }
150 inline int getMinorIterations() const {
151 return maxIts2_;
152 }
153 inline void setMinorIterations(int value) {
154 maxIts2_ = value;
155 }
156 // minor iterations for first time
157 inline int getMinorIterations0() const {
158 return maxIts_;
159 }
160 inline void setMinorIterations0(int value) {
161 maxIts_ = value;
162 }
166 inline int getReduceIterations() const {
167 return maxBigIts_;
168 }
169 inline void setReduceIterations(int value) {
170 maxBigIts_ = value;
171 }
173 inline int getLogLevel() const {
174 return logLevel_;
175 }
176 inline void setLogLevel(int value) {
177 logLevel_ = value;
178 }
180 inline int getLightweight() const {
181 return lightWeight_;
182 }
183 inline void setLightweight(int value) {
184 lightWeight_ = value;
185 }
187 inline int getStrategy() const {
188 return strategy_;
189 }
190 inline void setStrategy(int value) {
191 strategy_ = value;
192 }
194 inline double getDropEnoughFeasibility() const {
195 return dropEnoughFeasibility_;
196 }
197 inline void setDropEnoughFeasibility(double value) {
198 dropEnoughFeasibility_ = value;
199 }
201 inline double getDropEnoughWeighted() const {
202 return dropEnoughWeighted_;
203 }
204 inline void setDropEnoughWeighted(double value) {
205 dropEnoughWeighted_ = value;
206 }
208 inline void setModel(OsiSolverInterface * model) {
209 model_ = model;
210 };
212
213
215 private:
216
218 // allow public!
219 public:
220 void solve2(CoinMessageHandler * handler, const CoinMessages *messages);
221 private:
222 IdiotResult IdiSolve(
223 int nrows, int ncols, double * rowsol , double * colsol,
224 double * pi, double * djs, const double * origcost ,
225 double * rowlower,
226 double * rowupper, const double * lower,
227 const double * upper, const double * element,
228 const int * row, const CoinBigIndex * colcc,
229 const int * length, double * lambda,
230 int maxIts, double mu, double drop,
231 double maxmin, double offset,
232 int strategy, double djTol, double djExit, double djFlag,
233 CoinThreadRandom * randomNumberGenerator);
234 int dropping(IdiotResult result,
235 double tolerance,
236 double small,
237 int *nbad);
238 IdiotResult objval(int nrows, int ncols, double * rowsol , double * colsol,
239 double * pi, double * djs, const double * cost ,
240 const double * rowlower,
241 const double * rowupper, const double * lower,
242 const double * upper, const double * elemnt,
243 const int * row, const CoinBigIndex * columnStart,
244 const int * length, int extraBlock, int * rowExtra,
245 double * solExtra, double * elemExtra, double * upperExtra,
246 double * costExtra, double weight);
247 // Deals with whenUsed and slacks
248 int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd,
249 double * colsol, const double * lower, const double * upper,
250 const double * rowLower, const double * rowUpper,
251 const double * cost, const double * element, double fixTolerance, double & objChange,
252 double & infChange, double & maxInfeasibility);
253 private:
255 OsiSolverInterface * model_;
256
257 double djTolerance_;
258 double mu_; /* starting mu */
259 double drop_; /* exit if drop over 5 checks less than this */
260 double muFactor_; /* reduce mu by this */
261 double stopMu_; /* exit if mu gets smaller than this */
262 double smallInfeas_; /* feasibility tolerance */
263 double reasonableInfeas_; /* use lambdas if feasibility less than this */
264 double exitDrop_; /* candidate for stopping after a major iteration */
265 double muAtExit_; /* mu on exit */
266 double exitFeasibility_; /* exit if infeasibility less than this */
267 double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
268 double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
269 int * whenUsed_; /* array to say what was used */
270 int maxBigIts_; /* always reduce mu after this */
271 int maxIts_; /* do this many iterations on first go */
272 int majorIterations_;
273 int logLevel_;
274 int logFreq_;
275 int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
276 int lambdaIterations_; /* do at least this many lambda iterations */
277 int maxIts2_; /* do this many iterations on subsequent goes */
278 int strategy_; /* 0 - default strategy
279 1 - do accelerator step but be cautious
280 2 - do not do accelerator step
281 4 - drop, exitDrop and djTolerance all relative
282 8 - keep accelerator step to theta=10.0
283
284 32 - Scale
285 512 - crossover
286 2048 - keep lambda across mu change
287 4096 - return best solution (not last found)
288 8192 - always do a presolve in crossover
289 16384 - costed slacks found - so whenUsed_ longer
290 32768 - experimental 1
291 65536 - experimental 2
292 131072 - experimental 3
293 262144 - just values pass etc
294 524288 - don't treat structural slacks as slacks */
295
296 int lightWeight_; // 0 - normal, 1 lightweight
297 };
298 #endif
Idiot::drop_
double drop_
Definition: Idiot.hpp:259
Idiot::solve
void solve()
Get an approximate solution with the idiot code.
Idiot::maxBigIts_
int maxBigIts_
Definition: Idiot.hpp:270
Idiot::setStrategy
void setStrategy(int value)
Definition: Idiot.hpp:190
Idiot::getMinorIterations
int getMinorIterations() const
Minor iterations.
Definition: Idiot.hpp:150
ClpSimplex.hpp
Idiot::exitDrop_
double exitDrop_
Definition: Idiot.hpp:264
Idiot::reasonableInfeas_
double reasonableInfeas_
Definition: Idiot.hpp:263
Idiot::muFactor_
double muFactor_
Definition: Idiot.hpp:260
Idiot::maxIts2_
int maxIts2_
Definition: Idiot.hpp:277
Idiot::operator=
Idiot & operator=(const Idiot &rhs)
Assignment operator. This copies the data.
Idiot::getMinorIterations0
int getMinorIterations0() const
Definition: Idiot.hpp:157
Idiot::getDropEnoughWeighted
double getDropEnoughWeighted() const
Fine tuning - okay if weighted obj drop this factor.
Definition: Idiot.hpp:201
Idiot::getExitInfeasibility
double getExitInfeasibility() const
Exit infeasibility - exit if sum of infeasibilities less than this.
Definition: Idiot.hpp:130
Idiot::getDropEnoughFeasibility
double getDropEnoughFeasibility() const
Fine tuning - okay if feasibility drop this factor.
Definition: Idiot.hpp:194
Idiot::setDropEnoughFeasibility
void setDropEnoughFeasibility(double value)
Definition: Idiot.hpp:197
Idiot::setReduceIterations
void setReduceIterations(int value)
Definition: Idiot.hpp:169
Idiot::setMinorIterations0
void setMinorIterations0(int value)
Definition: Idiot.hpp:160
IdiotResult::sumSquared
double sumSquared
Definition: Idiot.hpp:27
Idiot::getMajorIterations
int getMajorIterations() const
Major iterations.
Definition: Idiot.hpp:138
Idiot::exitFeasibility_
double exitFeasibility_
Definition: Idiot.hpp:266
Idiot::getFeasibilityTolerance
double getFeasibilityTolerance() const
Feasibility tolerance - problem essentially feasible if individual infeasibilities less than this...
Definition: Idiot.hpp:113
Idiot::IdiSolve
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)
Idiot::solve2
void solve2(CoinMessageHandler *handler, const CoinMessages *messages)
Stuff for internal use.
CoinMessageHandler
Base class for message handling.
Definition: CoinMessageHandler.hpp:327
Idiot::setDropEnoughWeighted
void setDropEnoughWeighted(double value)
Definition: Idiot.hpp:204
Idiot::setMinorIterations
void setMinorIterations(int value)
Definition: Idiot.hpp:153
Idiot::mu_
double mu_
Definition: Idiot.hpp:258
Idiot::dropEnoughFeasibility_
double dropEnoughFeasibility_
Definition: Idiot.hpp:267
OsiSolverInterface
Abstract Base Class for describing an interface to a solver.
Definition: OsiSolverInterface.hpp:62
Idiot::setWeightFactor
void setWeightFactor(double value)
Definition: Idiot.hpp:107
Idiot::djTolerance_
double djTolerance_
Definition: Idiot.hpp:257
IdiotResult::djAtEnd
double djAtEnd
Definition: Idiot.hpp:29
Idiot::strategy_
int strategy_
Definition: Idiot.hpp:278
IdiotResult::iteration
int iteration
Definition: Idiot.hpp:30
Idiot::objval
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)
Idiot::setReasonablyFeasible
void setReasonablyFeasible(double value)
Definition: Idiot.hpp:125
Idiot::getLogLevel
int getLogLevel() const
Amount of information - default of 1 should be okay.
Definition: Idiot.hpp:173
Idiot::whenUsed_
int * whenUsed_
Definition: Idiot.hpp:269
Idiot::logFreq_
int logFreq_
Definition: Idiot.hpp:274
Idiot::majorIterations_
int majorIterations_
Definition: Idiot.hpp:272
Idiot::model_
OsiSolverInterface * model_
Underlying model.
Definition: Idiot.hpp:255
Idiot::getStrategy
int getStrategy() const
strategy
Definition: Idiot.hpp:187
Idiot::setMajorIterations
void setMajorIterations(int value)
Definition: Idiot.hpp:141
Idiot::crash
void crash(int numberPass, CoinMessageHandler *handler, const CoinMessages *messages, bool doCrossover=true)
Lightweight &quot;crash&quot;.
Idiot::maxIts_
int maxIts_
Definition: Idiot.hpp:271
Idiot::setModel
void setModel(OsiSolverInterface *model)
Set model.
Definition: Idiot.hpp:208
Idiot::dropping
int dropping(IdiotResult result, double tolerance, double small, int *nbad)
Idiot::Idiot
Idiot()
Default constructor.
IdiotResult::dropThis
double dropThis
Definition: Idiot.hpp:25
IdiotResult::weighted
double weighted
Definition: Idiot.hpp:26
Idiot
This class implements a very silly algorithm.
Definition: Idiot.hpp:48
Idiot::getReasonablyFeasible
double getReasonablyFeasible() const
Reasonably feasible.
Definition: Idiot.hpp:122
OsiSolverInterface.hpp
Idiot::dropEnoughWeighted_
double dropEnoughWeighted_
Definition: Idiot.hpp:268
IdiotResult::objval
double objval
Definition: Idiot.hpp:24
CoinBigIndex
int CoinBigIndex
Definition: Coin_C_defines.h:105
Idiot::lambdaIterations_
int lambdaIterations_
Definition: Idiot.hpp:276
Idiot::lightWeight_
int lightWeight_
Definition: Idiot.hpp:296
Idiot::setExitInfeasibility
void setExitInfeasibility(double value)
Definition: Idiot.hpp:133
Idiot::getLightweight
int getLightweight() const
How lightweight - 0 not, 1 yes, 2 very lightweight.
Definition: Idiot.hpp:180
IdiotResult::infeas
double infeas
Definition: Idiot.hpp:23
Idiot::checkFrequency_
int checkFrequency_
Definition: Idiot.hpp:275
Idiot::smallInfeas_
double smallInfeas_
Definition: Idiot.hpp:262
Idiot::crossOver
void crossOver(int mode)
Use simplex to get an optimal solution mode is how many steps the simplex crossover should take to ar...
Idiot::~Idiot
~Idiot()
Destructor.
Idiot::setStartingWeight
void setStartingWeight(double value)
Definition: Idiot.hpp:99
Idiot::logLevel_
int logLevel_
Definition: Idiot.hpp:273
Idiot::getReduceIterations
int getReduceIterations() const
Reduce weight after this many major iterations.
Definition: Idiot.hpp:166
IdiotResult::djAtBeginning
double djAtBeginning
Definition: Idiot.hpp:28
Idiot::setLogLevel
void setLogLevel(int value)
Definition: Idiot.hpp:176
Idiot::cleanIteration
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)
Idiot::getWeightFactor
double getWeightFactor() const
Weight factor - weight multiplied by this when changes, default 0.333.
Definition: Idiot.hpp:104
IdiotResult
for use internally
Definition: Idiot.hpp:22
Idiot::getStartingWeight
double getStartingWeight() const
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition: Idiot.hpp:96
Idiot::muAtExit_
double muAtExit_
Definition: Idiot.hpp:265
Idiot::setLightweight
void setLightweight(int value)
Definition: Idiot.hpp:183
Idiot::setFeasibilityTolerance
void setFeasibilityTolerance(double value)
Definition: Idiot.hpp:116
CoinMessages
Class to hold and manipulate an array of massaged messages.
Definition: CoinMessageHandler.hpp:128
CoinThreadRandom
Class for thread specific random numbers.
Definition: CoinHelperFunctions.hpp:953
Idiot::stopMu_
double stopMu_
Definition: Idiot.hpp:261