Idiot.hpp

Go to the documentation of this file.
00001 /* $Id: Idiot.hpp 2078 2015-01-05 12:39:49Z forrest $ */
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      inline void setModel(OsiSolverInterface * model) {
00209        model_ = model;
00210      };
00212 
00213 
00215 private:
00216 
00218      // allow public!
00219 public:
00220      void solve2(CoinMessageHandler * handler, const CoinMessages *messages);
00221 private:
00222      IdiotResult IdiSolve(
00223           int nrows, int ncols, double * rowsol , double * colsol,
00224           double * pi, double * djs, const double * origcost ,
00225           double * rowlower,
00226           double * rowupper, const double * lower,
00227           const double * upper, const double * element,
00228           const int * row, const CoinBigIndex * colcc,
00229           const int * length, double * lambda,
00230           int maxIts, double mu, double drop,
00231           double maxmin, double offset,
00232           int strategy, double djTol, double djExit, double djFlag,
00233           CoinThreadRandom * randomNumberGenerator);
00234      int dropping(IdiotResult result,
00235                   double tolerance,
00236                   double small,
00237                   int *nbad);
00238      IdiotResult objval(int nrows, int ncols, double * rowsol , double * colsol,
00239                         double * pi, double * djs, const double * cost ,
00240                         const double * rowlower,
00241                         const double * rowupper, const double * lower,
00242                         const double * upper, const double * elemnt,
00243                         const int * row, const CoinBigIndex * columnStart,
00244                         const int * length, int extraBlock, int * rowExtra,
00245                         double * solExtra, double * elemExtra, double * upperExtra,
00246                         double * costExtra, double weight);
00247      // Deals with whenUsed and slacks
00248      int cleanIteration(int iteration, int ordinaryStart, int ordinaryEnd,
00249                         double * colsol, const double * lower, const double * upper,
00250                         const double * rowLower, const double * rowUpper,
00251                         const double * cost, const double * element, double fixTolerance, double & objChange,
00252                         double & infChange, double & maxInfeasibility);
00253 private:
00255      OsiSolverInterface * model_;
00256 
00257      double djTolerance_;
00258      double mu_;  /* starting mu */
00259      double drop_; /* exit if drop over 5 checks less than this */
00260      double muFactor_; /* reduce mu by this */
00261      double stopMu_; /* exit if mu gets smaller than this */
00262      double smallInfeas_; /* feasibility tolerance */
00263      double reasonableInfeas_; /* use lambdas if feasibility less than this */
00264      double exitDrop_; /* candidate for stopping after a major iteration */
00265      double muAtExit_; /* mu on exit */
00266      double exitFeasibility_; /* exit if infeasibility less than this */
00267      double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
00268      double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
00269      int * whenUsed_; /* array to say what was used */
00270      int maxBigIts_; /* always reduce mu after this */
00271      int maxIts_; /* do this many iterations on first go */
00272      int majorIterations_;
00273      int logLevel_;
00274      int logFreq_;
00275      int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
00276      int lambdaIterations_; /* do at least this many lambda iterations */
00277      int maxIts2_; /* do this many iterations on subsequent goes */
00278      int strategy_;   /* 0 - default strategy
00279                      1 - do accelerator step but be cautious
00280                      2 - do not do accelerator step
00281                      4 - drop, exitDrop and djTolerance all relative
00282                      8 - keep accelerator step to theta=10.0
00283 
00284                     32 - Scale
00285                    512 - crossover
00286                   2048 - keep lambda across mu change
00287                   4096 - return best solution (not last found)
00288                   8192 - always do a presolve in crossover
00289                  16384 - costed slacks found - so whenUsed_ longer 
00290                  32768 - experimental 1
00291                  65536 - experimental 2
00292                  131072 - experimental 3 
00293                  262144 - just values pass etc */
00294                  
00295      int lightWeight_; // 0 - normal, 1 lightweight
00296 };
00297 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 19 Jan 2015 for Clp by  doxygen 1.6.1