本文整理汇总了C++中EnvPtr::getNewTimer方法的典型用法代码示例。如果您正苦于以下问题:C++ EnvPtr::getNewTimer方法的具体用法?C++ EnvPtr::getNewTimer怎么用?C++ EnvPtr::getNewTimer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EnvPtr
的用法示例。
在下文中一共展示了EnvPtr::getNewTimer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadProblem
void loadProblem(EnvPtr env, MINOTAUR_AMPL::AMPLInterface* iface,
ProblemPtr &oinst, double *obj_sense)
{
Timer *timer = env->getNewTimer();
OptionDBPtr options = env->getOptions();
JacobianPtr jac;
HessianOfLagPtr hess;
const std::string me("qg: ");
timer->start();
oinst = iface->readInstance(options->findString("problem_file")->getValue());
env->getLogger()->msgStream(LogInfo) << me
<< "time used in reading instance = " << std::fixed
<< std::setprecision(2) << timer->query() << std::endl;
// display the problem
oinst->calculateSize();
if (options->findBool("display_problem")->getValue()==true) {
oinst->write(env->getLogger()->msgStream(LogNone), 12);
}
if (options->findBool("display_size")->getValue()==true) {
oinst->writeSize(env->getLogger()->msgStream(LogNone));
}
// create the jacobian
if (false==options->findBool("use_native_cgraph")->getValue()) {
jac = (MINOTAUR_AMPL::AMPLJacobianPtr)
new MINOTAUR_AMPL::AMPLJacobian(iface);
oinst->setJacobian(jac);
// create the hessian
hess = (MINOTAUR_AMPL::AMPLHessianPtr)
new MINOTAUR_AMPL::AMPLHessian(iface);
oinst->setHessian(hess);
}
// set initial point
oinst->setInitialPoint(iface->getInitialPoint(),
oinst->getNumVars()-iface->getNumDefs());
if (oinst->getObjective() &&
oinst->getObjective()->getObjectiveType()==Maximize) {
*obj_sense = -1.0;
env->getLogger()->msgStream(LogInfo) << me
<< "objective sense: maximize (will be converted to Minimize)"
<< std::endl;
} else {
*obj_sense = 1.0;
env->getLogger()->msgStream(LogInfo) << me
<< "objective sense: minimize" << std::endl;
}
delete timer;
}
示例2: RandomBrStats
RandomBrancher::RandomBrancher(EnvPtr env, HandlerVector handlers)
{
logger_ = env->getLogger();
timer_ = env->getNewTimer();
stats_ = new RandomBrStats();
stats_->calls = 0;
stats_->time = 0.0;
handlers_ = handlers;
seed_ = env->getOptions()->findInt("rand_seed")->getValue();
if (seed_ == 0) {
srand(time(NULL));
} else {
srand(seed_);
}
}
示例3: defined
IpoptEngine::IpoptEngine(EnvPtr env)
: bndChanged_(false),
consChanged_(false),
env_(env),
etol_(1e-7),
myapp_(0),
mynlp_(0),
sol_(IpoptSolPtr()), // NULL
strBr_(false),
timer_(0),
ws_(IpoptWarmStartPtr()) // NULL
{
#if defined(USE_IPOPT)
problem_ = ProblemPtr(); // NULL
logger_ = (LoggerPtr) new Logger((LogLevel) env->getOptions()->
findInt("engine_log_level")->getValue());
myapp_ = new Ipopt::IpoptApplication();
setOptionsForRepeatedSolve();
status_ = EngineError;
if (env->getOptions()->findBool("use_warmstart")->getValue()==true) {
prepareWs_ = true;
useWs_ = true;
} else {
prepareWs_ = false;
useWs_ = false;
}
timer_ = env->getNewTimer();
stats_ = new IpoptStats();
stats_->calls = 0;
stats_->strCalls = 0;
stats_->time = 0;
stats_->ptime = 0;
stats_->strTime = 0;
stats_->iters = 0;
stats_->strIters = 0;
#else
assert(!"ipopt engine can only be called when compiled with ipopt!")
#endif
}
示例4: main
int main()
{
// Generate output.
ofstream output;
output.open("numknapcov.txt");
// Generate input.
ifstream input;
input.open("list.txt");
// Check if input is opened succesfully.
if (input.is_open() == false) {
cerr << "Input file read error." << endl;
output << "Input file read error." << endl;
exit(0);
}
/********************************************************************************/
// Headers for output data.
output << "Statistics of knapsack cover cuts applied to root relaxation." << endl;
output << "problem " << "vars " << "cons " << "lincons " << "knapcons " << "knapcov "
<< "knaps " << "totalcuts " << "cuts " << "violknapcuts " << "initobj "
<< "endobj " << "gapclosed " << "timeinit " << "timecut " << "timemod"
<< endl;
/********************************************************************************/
// loop to test all problems in list.txt
while (input.good()) {
// problem name
string pname;
getline(input, pname);
// At the end of file just exit from loop.
if (pname.empty()) {
break;
}
cout << "Problem considered is: " << pname << endl;
// Real stuff begins.
// Ampl interface, jacobian and hessian.
MINOTAUR_AMPL::AMPLInterfacePtr iface = MINOTAUR_AMPL::AMPLInterfacePtr();
JacobianPtr jPtr; //! Jacobian read from AMPL
HessianOfLagPtr hPtr; //! Hessian read from AMPL
// environment, timers and options:
EnvPtr env = (EnvPtr) new Environment();
OptionDBPtr options;
// problem to be solved.
ProblemPtr minlp;
// solver pointers, including status.
FilterSQPEngine e(env);
EngineStatus status;
// Presolver.
PresolverPtr pres;
// give parameters.
UInt argc2 = 2;
std::string arg1 = "bnb";
std::string arg2 = pname;
char** argv2 = new char* [2];
argv2[0] = &arg1[0];
argv2[1] = &arg2[0];
// Default options
env->getOptions()->findBool("presolve")->setValue(false);
env->getOptions()->findBool("use_native_cgraph")->setValue(true);
env->getOptions()->findBool("nl_presolve")->setValue(false);
// parse options
env->readOptions(argc2, argv2);
options = env->getOptions();
options->findString("interface_type")->setValue("AMPL");
// read minlp from AMPL.
iface = (MINOTAUR_AMPL::AMPLInterfacePtr) new MINOTAUR_AMPL::AMPLInterface(env);
minlp = iface->readInstance(pname);
// Timer is obtained.
Timer * timer = env->getNewTimer();
// Nonlinearize objective function.
Bool MIPCONSIDERED = false;
if (MIPCONSIDERED == true) {
ObjectivePtr initobjfun = minlp->getObjective();
if (initobjfun->getObjectiveType() == Maximize) {
cerr << "Objective type is Maximize, change it to Minimize." << endl;
exit(0);
}
LinearFunctionPtr lfinitobj = initobjfun->getLinearFunction();
// NonlinearFunctionPtr nlfobj = (NonlinearFunctionPtr) new NonlinearFunction();
CGraphPtr nlfobj = (CGraphPtr) new CGraph();
logobj(lfinitobj, nlfobj);
FunctionPtr logobjfun = (FunctionPtr) new Function(nlfobj);
ObjectiveType otyp = Minimize;
minlp->changeObj(logobjfun, 0);
}
minlp->calculateSize();
minlp->prepareForSolve();
//.........这里部分代码省略.........