Clp trunk
Idiot.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
00005 
00006 // "Idiot" as the name of this algorithm is copylefted.  If you want to change
00007 // the name then it should be something equally stupid (but not "Stupid") or
00008 // even better something witty.
00009 
00010 #ifndef Idiot_H
00011 #define Idiot_H
00012 #ifndef OSI_IDIOT
00013 #include "ClpSimplex.hpp"
00014 #define OsiSolverInterface ClpSimplex
00015 #else
00016 #include "OsiSolverInterface.hpp"
00017 typedef int CoinBigIndex;
00018 #endif
00019 class CoinMessageHandler;
00020 class CoinMessages;
00022 typedef struct {
00023      double infeas;
00024      double objval;
00025      double dropThis;
00026      double weighted;
00027      double sumSquared;
00028      double djAtBeginning;
00029      double djAtEnd;
00030      int iteration;
00031 } IdiotResult;
00048 class Idiot {
00049 
00050 public:
00051 
00056 
00057      Idiot (  );
00059      Idiot ( OsiSolverInterface & model );
00060 
00062      Idiot(const Idiot &);
00064      Idiot & operator=(const Idiot & rhs);
00066      ~Idiot (  );
00068 
00069 
00073 
00074      void solve();
00076      void crash(int numberPass, CoinMessageHandler * handler,
00077                 const CoinMessages * messages, bool doCrossover = true);
00087      void crossOver(int mode);
00089 
00090 
00096      inline double getStartingWeight() const {
00097           return mu_;
00098      }
00099      inline void setStartingWeight(double value) {
00100           mu_ = value;
00101      }
00104      inline double getWeightFactor() const {
00105           return muFactor_;
00106      }
00107      inline void setWeightFactor(double value) {
00108           muFactor_ = value;
00109      }
00113      inline double getFeasibilityTolerance() const {
00114           return smallInfeas_;
00115      }
00116      inline void setFeasibilityTolerance(double value) {
00117           smallInfeas_ = value;
00118      }
00122      inline double getReasonablyFeasible() const {
00123           return reasonableInfeas_;
00124      }
00125      inline void setReasonablyFeasible(double value) {
00126           reasonableInfeas_ = value;
00127      }
00130      inline double getExitInfeasibility() const {
00131           return exitFeasibility_;
00132      }
00133      inline void setExitInfeasibility(double value) {
00134           exitFeasibility_ = value;
00135      }
00138      inline int getMajorIterations() const {
00139           return majorIterations_;
00140      }
00141      inline void setMajorIterations(int value) {
00142           majorIterations_ = value;
00143      }
00150      inline int getMinorIterations() const {
00151           return maxIts2_;
00152      }
00153      inline void setMinorIterations(int value) {
00154           maxIts2_ = value;
00155      }
00156      // minor iterations for first time
00157      inline int getMinorIterations0() const {
00158           return maxIts_;
00159      }
00160      inline void setMinorIterations0(int value) {
00161           maxIts_ = value;
00162      }
00166      inline int getReduceIterations() const {
00167           return maxBigIts_;
00168      }
00169      inline void setReduceIterations(int value) {
00170           maxBigIts_ = value;
00171      }
00173      inline int getLogLevel() const {
00174           return logLevel_;
00175      }
00176      inline void setLogLevel(int value) {
00177           logLevel_ = value;
00178      }
00180      inline int getLightweight() const {
00181           return lightWeight_;
00182      }
00183      inline void setLightweight(int value) {
00184           lightWeight_ = value;
00185      }
00187      inline int getStrategy() const {
00188           return strategy_;
00189      }
00190      inline void setStrategy(int value) {
00191           strategy_ = value;
00192      }
00194      inline double getDropEnoughFeasibility() const {
00195           return dropEnoughFeasibility_;
00196      }
00197      inline void setDropEnoughFeasibility(double value) {
00198           dropEnoughFeasibility_ = value;
00199      }
00201      inline double getDropEnoughWeighted() const {
00202           return dropEnoughWeighted_;
00203      }
00204      inline void setDropEnoughWeighted(double value) {
00205           dropEnoughWeighted_ = value;
00206      }
00208 
00209 
00211 private:
00212 
00214      // allow public!
00215 public:
00216      void solve2(CoinMessageHandler * handler, const CoinMessages *messages);
00217 private:
00218      IdiotResult IdiSolve(
00219           int nrows, int ncols, double * rowsol , double * colsol,
00220           double * pi, double * djs, const double * origcost ,
00221           double * rowlower,
00222           double * rowupper, const double * lower,
00223           const double * upper, const double * element,
00224           const int * row, const CoinBigIndex * colcc,
00225           const int * length, double * lambda,
00226           int maxIts, double mu, double drop,
00227           double maxmin, double offset,
00228           int strategy, double djTol, double djExit, double djFlag,
00229           CoinThreadRandom * randomNumberGenerator);
00230      int dropping(IdiotResult result,
00231                   double tolerance,
00232                   double small,
00233                   int *nbad);
00234      IdiotResult objval(int nrows, int ncols, double * rowsol , double * colsol,
00235                         double * pi, double * djs, const double * cost ,
00236                         const double * rowlower,
00237                         const double * rowupper, const double * lower,
00238                         const double * upper, const double * elemnt,
00239                         const int * row, const CoinBigIndex * columnStart,
00240                         const int * length, int extraBlock, int * rowExtra,
00241                         double * solExtra, double * elemExtra, double * upperExtra,
00242                         double * costExtra, double weight);
00243      // Deals with whenUsed and slacks
00244      int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd,
00245                         double * colsol, const double * lower, const double * upper,
00246                         const double * rowLower, const double * rowUpper,
00247                         const double * cost, const double * element, double fixTolerance, double & objChange,
00248                         double & infChange);
00249 private:
00251      OsiSolverInterface * model_;
00252 
00253      double djTolerance_;
00254      double mu_;  /* starting mu */
00255      double drop_; /* exit if drop over 5 checks less than this */
00256      double muFactor_; /* reduce mu by this */
00257      double stopMu_; /* exit if mu gets smaller than this */
00258      double smallInfeas_; /* feasibility tolerance */
00259      double reasonableInfeas_; /* use lambdas if feasibility less than this */
00260      double exitDrop_; /* candidate for stopping after a major iteration */
00261      double muAtExit_; /* mu on exit */
00262      double exitFeasibility_; /* exit if infeasibility less than this */
00263      double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
00264      double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
00265      int * whenUsed_; /* array to say what was used */
00266      int maxBigIts_; /* always reduce mu after this */
00267      int maxIts_; /* do this many iterations on first go */
00268      int majorIterations_;
00269      int logLevel_;
00270      int logFreq_;
00271      int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
00272      int lambdaIterations_; /* do at least this many lambda iterations */
00273      int maxIts2_; /* do this many iterations on subsequent goes */
00274      int strategy_;   /* 0 - default strategy
00275                      1 - do accelerator step but be cautious
00276                      2 - do not do accelerator step
00277                      4 - drop, exitDrop and djTolerance all relative
00278                      8 - keep accelerator step to theta=10.0
00279 
00280                     32 - Scale
00281                    512 - crossover
00282                   2048 - keep lambda across mu change
00283                   4096 - return best solution (not last found)
00284                   8192 - always do a presolve in crossover
00285                  16384 - costed slacks found - so whenUsed_ longer */
00286      int lightWeight_; // 0 - normal, 1 lightweight
00287 };
00288 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines