Loading...
Searching...
No Matches
Idiot.hpp
Go to the documentation of this file.
/* $Id$ */
// Copyright (C) 2002, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
// "Idiot" as the name of this algorithm is copylefted. If you want to change
// the name then it should be something equally stupid (but not "Stupid") or
// even better something witty.
#ifndef Idiot_H
#define Idiot_H
#ifndef OSI_IDIOT
#include "ClpSimplex.hpp"
#define OsiSolverInterface ClpSimplex
#else
#include "OsiSolverInterface.hpp"
typedef int CoinBigIndex;
#endif
class CoinMessageHandler;
class CoinMessages;
typedef struct {
double infeas;
double objval;
double dropThis;
double weighted;
double sumSquared;
double djAtBeginning;
double djAtEnd;
int iteration;
} IdiotResult;
class Idiot {
public:
Idiot();
Idiot(OsiSolverInterface &model);
Idiot(const Idiot &);
Idiot &operator=(const Idiot &rhs);
~Idiot();
void solve();
void crash(int numberPass, CoinMessageHandler *handler,
const CoinMessages *messages, bool doCrossover = true);
void crossOver(int mode);
inline double getStartingWeight() const
{
return mu_;
}
inline void setStartingWeight(double value)
{
mu_ = value;
}
inline double getWeightFactor() const
{
return muFactor_;
}
inline void setWeightFactor(double value)
{
muFactor_ = value;
}
inline double getFeasibilityTolerance() const
{
return smallInfeas_;
}
inline void setFeasibilityTolerance(double value)
{
smallInfeas_ = value;
}
inline double getReasonablyFeasible() const
{
return reasonableInfeas_;
}
inline void setReasonablyFeasible(double value)
{
reasonableInfeas_ = value;
}
inline double getExitInfeasibility() const
{
return exitFeasibility_;
}
inline void setExitInfeasibility(double value)
{
exitFeasibility_ = value;
}
inline int getMajorIterations() const
{
return majorIterations_;
}
inline void setMajorIterations(int value)
{
majorIterations_ = value;
}
inline int getMinorIterations() const
{
return maxIts2_;
}
inline void setMinorIterations(int value)
{
maxIts2_ = value;
}
// minor iterations for first time
inline int getMinorIterations0() const
{
return maxIts_;
}
inline void setMinorIterations0(int value)
{
maxIts_ = value;
}
inline int getReduceIterations() const
{
return maxBigIts_;
}
inline void setReduceIterations(int value)
{
maxBigIts_ = value;
}
inline int getLogLevel() const
{
return logLevel_;
}
inline void setLogLevel(int value)
{
logLevel_ = value;
}
inline int getLightweight() const
{
return lightWeight_;
}
inline void setLightweight(int value)
{
lightWeight_ = value;
}
inline int getStrategy() const
{
return strategy_;
}
inline void setStrategy(int value)
{
strategy_ = value;
}
inline double getDropEnoughFeasibility() const
{
return dropEnoughFeasibility_;
}
inline void setDropEnoughFeasibility(double value)
{
dropEnoughFeasibility_ = value;
}
inline double getDropEnoughWeighted() const
{
return dropEnoughWeighted_;
}
inline void setDropEnoughWeighted(double value)
{
dropEnoughWeighted_ = value;
}
inline void setModel(OsiSolverInterface *model)
{
model_ = model;
};
private:
// allow public!
public:
void solve2(CoinMessageHandler *handler, const CoinMessages *messages);
private:
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 dropping(IdiotResult result,
double tolerance,
double small,
int *nbad);
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);
// Deals with whenUsed and slacks
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);
private:
OsiSolverInterface *model_;
double djTolerance_;
double mu_; /* starting mu */
double drop_; /* exit if drop over 5 checks less than this */
double muFactor_; /* reduce mu by this */
double stopMu_; /* exit if mu gets smaller than this */
double smallInfeas_; /* feasibility tolerance */
double reasonableInfeas_; /* use lambdas if feasibility less than this */
double exitDrop_; /* candidate for stopping after a major iteration */
double muAtExit_; /* mu on exit */
double exitFeasibility_; /* exit if infeasibility less than this */
double dropEnoughFeasibility_; /* okay if feasibility drop this factor */
double dropEnoughWeighted_; /* okay if weighted obj drop this factor */
int *whenUsed_; /* array to say what was used */
int maxBigIts_; /* always reduce mu after this */
int maxIts_; /* do this many iterations on first go */
int majorIterations_;
int logLevel_;
int logFreq_;
int checkFrequency_; /* can exit after 5 * this iterations (on drop) */
int lambdaIterations_; /* do at least this many lambda iterations */
int maxIts2_; /* do this many iterations on subsequent goes */
int strategy_; /* 0 - default strategy
1 - do accelerator step but be cautious
2 - do not do accelerator step
4 - drop, exitDrop and djTolerance all relative
8 - keep accelerator step to theta=10.0
32 - Scale
512 - crossover
2048 - keep lambda across mu change
4096 - return best solution (not last found)
8192 - always do a presolve in crossover
16384 - costed slacks found - so whenUsed_ longer
32768 - experimental 1
65536 - experimental 2
131072 - experimental 3
262144 - just values pass etc
524288 - don't treat structural slacks as slacks */
int lightWeight_; // 0 - normal, 1 lightweight
};
#endif
/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
*/
ClpSimplex.hpp
OsiSolverInterface
#define OsiSolverInterface
Definition Idiot.hpp:14
Idiot::getReasonablyFeasible
double getReasonablyFeasible() const
Reasonably feasible.
Definition Idiot.hpp:125
Idiot::getLightweight
int getLightweight() const
How lightweight - 0 not, 1 yes, 2 very lightweight.
Definition Idiot.hpp:197
Idiot::setDropEnoughWeighted
void setDropEnoughWeighted(double value)
Definition Idiot.hpp:228
Idiot::maxIts_
int maxIts_
Definition Idiot.hpp:297
Idiot::stopMu_
double stopMu_
Definition Idiot.hpp:287
Idiot::maxIts2_
int maxIts2_
Definition Idiot.hpp:303
Idiot::majorIterations_
int majorIterations_
Definition Idiot.hpp:298
Idiot::dropEnoughFeasibility_
double dropEnoughFeasibility_
Definition Idiot.hpp:293
Idiot::dropping
int dropping(IdiotResult result, double tolerance, double small, int *nbad)
Idiot::Idiot
Idiot(OsiSolverInterface &model)
Constructor with model.
Idiot::setWeightFactor
void setWeightFactor(double value)
Definition Idiot.hpp:107
Idiot::setReasonablyFeasible
void setReasonablyFeasible(double value)
Definition Idiot.hpp:129
Idiot::setDropEnoughFeasibility
void setDropEnoughFeasibility(double value)
Definition Idiot.hpp:219
Idiot::setMinorIterations0
void setMinorIterations0(int value)
Definition Idiot.hpp:172
Idiot::getExitInfeasibility
double getExitInfeasibility() const
Exit infeasibility - exit if sum of infeasibilities less than this.
Definition Idiot.hpp:135
Idiot::setLightweight
void setLightweight(int value)
Definition Idiot.hpp:201
Idiot::muFactor_
double muFactor_
Definition Idiot.hpp:286
Idiot::setStartingWeight
void setStartingWeight(double value)
Definition Idiot.hpp:97
Idiot::Idiot
Idiot()
Default constructor.
Idiot::getDropEnoughWeighted
double getDropEnoughWeighted() const
Fine tuning - okay if weighted obj drop this factor.
Definition Idiot.hpp:224
Idiot::operator=
Idiot & operator=(const Idiot &rhs)
Assignment operator. This copies the data.
Idiot::lightWeight_
int lightWeight_
Definition Idiot.hpp:322
Idiot::setModel
void setModel(OsiSolverInterface *model)
Set model.
Definition Idiot.hpp:233
Idiot::lambdaIterations_
int lambdaIterations_
Definition Idiot.hpp:302
Idiot::exitDrop_
double exitDrop_
Definition Idiot.hpp:290
Idiot::whenUsed_
int * whenUsed_
Definition Idiot.hpp:295
Idiot::crash
void crash(int numberPass, CoinMessageHandler *handler, const CoinMessages *messages, bool doCrossover=true)
Lightweight "crash".
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::reasonableInfeas_
double reasonableInfeas_
Definition Idiot.hpp:289
Idiot::maxBigIts_
int maxBigIts_
Definition Idiot.hpp:296
Idiot::djTolerance_
double djTolerance_
Definition Idiot.hpp:283
Idiot::getFeasibilityTolerance
double getFeasibilityTolerance() const
Feasibility tolerance - problem essentially feasible if individual infeasibilities less than this.
Definition Idiot.hpp:114
Idiot::smallInfeas_
double smallInfeas_
Definition Idiot.hpp:288
Idiot::setLogLevel
void setLogLevel(int value)
Definition Idiot.hpp:192
Idiot::solve
void solve()
Get an approximate solution with the idiot code.
Idiot::getReduceIterations
int getReduceIterations() const
Reduce weight after this many major iterations.
Definition Idiot.hpp:179
Idiot::logFreq_
int logFreq_
Definition Idiot.hpp:300
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::logLevel_
int logLevel_
Definition Idiot.hpp:299
Idiot::setStrategy
void setStrategy(int value)
Definition Idiot.hpp:210
Idiot::solve2
void solve2(CoinMessageHandler *handler, const CoinMessages *messages)
Stuff for internal use.
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::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::getStartingWeight
double getStartingWeight() const
Starting weight - small emphasizes feasibility, default 1.0e-4.
Definition Idiot.hpp:93
Idiot::model_
OsiSolverInterface * model_
Underlying model.
Definition Idiot.hpp:281
Idiot::mu_
double mu_
Definition Idiot.hpp:284
Idiot::getLogLevel
int getLogLevel() const
Amount of information - default of 1 should be okay.
Definition Idiot.hpp:188
Idiot::getMajorIterations
int getMajorIterations() const
Major iterations.
Definition Idiot.hpp:145
Idiot::~Idiot
~Idiot()
Destructor.
Idiot::getDropEnoughFeasibility
double getDropEnoughFeasibility() const
Fine tuning - okay if feasibility drop this factor.
Definition Idiot.hpp:215
Idiot::getStrategy
int getStrategy() const
strategy
Definition Idiot.hpp:206
Idiot::drop_
double drop_
Definition Idiot.hpp:285
Idiot::setFeasibilityTolerance
void setFeasibilityTolerance(double value)
Definition Idiot.hpp:118
Idiot::muAtExit_
double muAtExit_
Definition Idiot.hpp:291
Idiot::setMajorIterations
void setMajorIterations(int value)
Definition Idiot.hpp:149
Idiot::dropEnoughWeighted_
double dropEnoughWeighted_
Definition Idiot.hpp:294
Idiot::setExitInfeasibility
void setExitInfeasibility(double value)
Definition Idiot.hpp:139
Idiot::strategy_
int strategy_
Definition Idiot.hpp:304
Idiot::checkFrequency_
int checkFrequency_
Definition Idiot.hpp:301
Idiot::getMinorIterations
int getMinorIterations() const
Minor iterations.
Definition Idiot.hpp:159
Idiot::Idiot
Idiot(const Idiot &)
Copy constructor.
Idiot::getMinorIterations0
int getMinorIterations0() const
Definition Idiot.hpp:168
Idiot::getWeightFactor
double getWeightFactor() const
Weight factor - weight multiplied by this when changes, default 0.333.
Definition Idiot.hpp:103
Idiot::exitFeasibility_
double exitFeasibility_
Definition Idiot.hpp:292
Idiot::setReduceIterations
void setReduceIterations(int value)
Definition Idiot.hpp:183
Idiot::setMinorIterations
void setMinorIterations(int value)
Definition Idiot.hpp:163
IdiotResult
for use internally
Definition Idiot.hpp:22
IdiotResult::dropThis
double dropThis
Definition Idiot.hpp:25
IdiotResult::weighted
double weighted
Definition Idiot.hpp:26
IdiotResult::djAtBeginning
double djAtBeginning
Definition Idiot.hpp:28
IdiotResult::djAtEnd
double djAtEnd
Definition Idiot.hpp:29
IdiotResult::sumSquared
double sumSquared
Definition Idiot.hpp:27
IdiotResult::iteration
int iteration
Definition Idiot.hpp:30
IdiotResult::infeas
double infeas
Definition Idiot.hpp:23
IdiotResult::objval
double objval
Definition Idiot.hpp:24