예제 #1
0
bool Transformer::allConsAssigned_(ProblemPtr p, HandlerVector &handlers)
{
  BoolVector asgn(p->getNumCons(), false);
  for (HandlerVector::const_iterator it=handlers.begin(); it!=handlers.end();
       ++it) {
    for (ConstraintVector::const_iterator it2=(*it)->consBegin();
         it2!=(*it)->consEnd(); ++it2) {
      if (asgn[(*it2)->getIndex()] == true) {
        std::cout << "constraint " << (*it2)->getName() <<
          " with index " << (*it2)->getIndex() << 
          " is assigned to more than one handlers!" << std::endl;
        (*it2)->write(std::cout);
        return false;
      }
      asgn[(*it2)->getIndex()] = true;
    }
  }
  for (UInt it=0; it<p->getNumCons(); ++it) {
    if (asgn[it] != true) {
      std::cout << "constraint " << p->getConstraint(it)->getName() <<
        " with index " << it << " is not assigned to any handler!" << std::endl;
      p->getConstraint(it)->write(std::cout);
      return false;
    }
  }
  return true;
}
예제 #2
0
void Transformer::clearUnusedHandlers_(HandlerVector &handlers)
{
  for (HandlerVector::iterator it=handlers.begin(); it!=handlers.end();) {
    if (false == (*it)->isNeeded()) {
      it = handlers.erase(it);
    } else {
      ++it;
    }
  }
}
예제 #3
0
PresolverPtr presolve(EnvPtr env, ProblemPtr p, size_t ndefs, 
                      HandlerVector &handlers)
{
  PresolverPtr pres = PresolverPtr(); // NULL
  const std::string me("qg: ");

  p->calculateSize();
  if (env->getOptions()->findBool("presolve")->getValue() == true) {
    LinearHandlerPtr lhandler = (LinearHandlerPtr) new LinearHandler(env, p);
    handlers.push_back(lhandler);
    if (p->isQP() || p->isQuadratic() || p->isLinear() ||
        true==env->getOptions()->findBool("use_native_cgraph")->getValue()) {
      lhandler->setPreOptPurgeVars(true);
      lhandler->setPreOptPurgeCons(true);
      lhandler->setPreOptCoeffImp(true);
    } else {
      lhandler->setPreOptPurgeVars(false);
      lhandler->setPreOptPurgeCons(false);
      lhandler->setPreOptCoeffImp(false);
    }
    if (ndefs>0) {
      lhandler->setPreOptDualFix(false);
    } else {
      lhandler->setPreOptDualFix(true);
    }

    if (!p->isLinear() && 
        true==env->getOptions()->findBool("use_native_cgraph")->getValue() && 
        true==env->getOptions()->findBool("nl_presolve")->getValue() 
       ) {
      NlPresHandlerPtr nlhand = (NlPresHandlerPtr) new NlPresHandler(env, p);
      handlers.push_back(nlhand);
    }

    // write the names.
    env->getLogger()->msgStream(LogExtraInfo) << me 
      << "handlers used in presolve:" << std::endl;
    for (HandlerIterator h = handlers.begin(); h != handlers.end(); 
        ++h) {
      env->getLogger()->msgStream(LogExtraInfo) << me 
        << (*h)->getName() << std::endl;
    }
  }

  pres = (PresolverPtr) new Presolver(p, env, handlers);
  pres->standardize(); 
  if (env->getOptions()->findBool("presolve")->getValue() == true) {
    pres->solve();
  }
  return pres;
}
예제 #4
0
int main(int argc, char* argv[])
{
  EnvPtr env = (EnvPtr) new Environment();
  OptionDBPtr options;

  MINOTAUR_AMPL::AMPLInterfacePtr iface = MINOTAUR_AMPL::AMPLInterfacePtr();  
  ProblemPtr inst;
  SolutionPtr sol, sol2;
  double obj_sense =1.0;
  
  // jacobian is read from AMPL interface and passed on to branch-and-bound
  JacobianPtr jPtr;
  // hessian is read from AMPL interface and passed on to branch-and-bound
  MINOTAUR_AMPL::AMPLHessianPtr hPtr;

  // the branch-and-bound
  BranchAndBound *bab = 0;
  PresolverPtr pres;
  EngineFactory *efac;
  const std::string me("qg: ");

  BrancherPtr br = BrancherPtr(); // NULL
  PCBProcessorPtr nproc;

  NodeIncRelaxerPtr nr;

  //handlers
  HandlerVector handlers;
  IntVarHandlerPtr vHand;
  LinearHandlerPtr lHand;
  QGAdvHandlerPtr qgHand;
  RCHandlerPtr rcHand;

  //engines
  EnginePtr nlp_e;
  EnginePtr proj_nlp_e;
  EnginePtr l1proj_nlp_e;

  LPEnginePtr lin_e;   // lp engine 
  LoggerPtr logger_ = (LoggerPtr) new Logger(LogInfo);
  VarVector *orig_v=0;

  int err = 0;

  // start timing.
  env->startTimer(err);
  if (err) {
    goto CLEANUP;
  }

  setInitialOptions(env);

  iface = (MINOTAUR_AMPL::AMPLInterfacePtr) 
    new MINOTAUR_AMPL::AMPLInterface(env, "qg");

  // parse options
  env->readOptions(argc, argv);
  options = env->getOptions();
  options->findString("interface_type")->setValue("AMPL");

  if (0!=showInfo(env)) {
    goto CLEANUP;
  }

  loadProblem(env, iface, inst, &obj_sense);

  // Initialize engines
  nlp_e = getNLPEngine(env, inst); //Engine for Original problem

  efac = new EngineFactory(env);
  lin_e = efac->getLPEngine();   // lp engine 
  delete efac;

  // get presolver.
  orig_v = new VarVector(inst->varsBegin(), inst->varsEnd());
  pres = presolve(env, inst, iface->getNumDefs(), handlers);
  handlers.clear();
  if (Finished != pres->getStatus() && NotStarted != pres->getStatus()) {
    env->getLogger()->msgStream(LogInfo) << me 
      << "status of presolve: " 
      << getSolveStatusString(pres->getStatus()) << std::endl;
    writeSol(env, orig_v, pres, SolutionPtr(), pres->getStatus(), iface);
    writeBnbStatus(env, bab, obj_sense);
    goto CLEANUP;
  }
 
   if (options->findBool("solve")->getValue()==true) {
    if (true==options->findBool("use_native_cgraph")->getValue()) {
      inst->setNativeDer();
    }
    // Initialize the handlers for branch-and-cut
    lHand = (LinearHandlerPtr) new LinearHandler(env, inst);
    lHand->setModFlags(false, true);
    handlers.push_back(lHand);
    assert(lHand);

    vHand = (IntVarHandlerPtr) new IntVarHandler(env, inst);
    vHand->setModFlags(false, true); 
    handlers.push_back(vHand);
    assert(vHand);
    // Use of perspective handler is user choice
    if (env->getOptions()->findBool("perspective")->getValue() == true) {
      PerspCutHandlerPtr pcHand = (PerspCutHandlerPtr) new 
        PerspCutHandler(env, inst); 
      pcHand->findPRCons();
      if (pcHand->getStatus()) {
        qgHand = (QGAdvHandlerPtr) new QGAdvHandler(env, inst, nlp_e, pcHand);
      } else {
        qgHand = (QGAdvHandlerPtr) new QGAdvHandler(env, inst, nlp_e); 
      }
    } else {
        qgHand = (QGAdvHandlerPtr) new QGAdvHandler(env, inst, nlp_e); 
    }
    qgHand->setModFlags(false, true);
    handlers.push_back(qgHand);
    assert(qgHand);
    
    if (options->findBool("rc_fix")->getValue()) {
      rcHand = (RCHandlerPtr) new RCHandler(env);
      rcHand->setModFlags(false, true); 
      handlers.push_back(rcHand);
      assert(rcHand);
    }  

    // report name
    env->getLogger()->msgStream(LogExtraInfo) << me << "handlers used:"
      << std::endl;
    for (HandlerIterator h = handlers.begin(); h != handlers.end(); ++h) {
        env->getLogger()->msgStream(LogExtraInfo) << me << (*h)->getName()
        << std::endl;
    }

    // Only store bound-changes of relaxation (not problem)
    nr = (NodeIncRelaxerPtr) new NodeIncRelaxer(env, handlers);
    nr->setModFlag(false);

    nr->setEngine(lin_e);
    nproc = (PCBProcessorPtr) new PCBProcessor(env, lin_e, handlers);

    if (env->getOptions()->findString("brancher")->getValue() == "rel") {
      ReliabilityBrancherPtr rel_br = 
        (ReliabilityBrancherPtr) new ReliabilityBrancher(env, handlers);
      rel_br->setEngine(lin_e);
      nproc->setBrancher(rel_br);
      br = rel_br;
    } else if (env->getOptions()->findString("brancher")->getValue()
               == "maxvio") {
      MaxVioBrancherPtr mbr = (MaxVioBrancherPtr) 
        new MaxVioBrancher(env, handlers);
      nproc->setBrancher(mbr);
      br = mbr;
    } else if (env->getOptions()->findString("brancher")->getValue()
               == "lex") {
      LexicoBrancherPtr lbr = (LexicoBrancherPtr) 
        new LexicoBrancher(env, handlers);
      br = lbr;
    }
    nproc->setBrancher(br);
    env->getLogger()->msgStream(LogExtraInfo) << me <<
      "brancher used = " << br->getName() << std::endl;

    bab = new BranchAndBound(env, inst);
    bab->setNodeRelaxer(nr);
    bab->setNodeProcessor(nproc);
    bab->shouldCreateRoot(true);


    // start solving
    bab->solve();
    bab->writeStats(env->getLogger()->msgStream(LogExtraInfo));
    //bab->writeStats(std::cout);
    nlp_e->writeStats(env->getLogger()->msgStream(LogExtraInfo));
    lin_e->writeStats(env->getLogger()->msgStream(LogExtraInfo));

    for (HandlerVector::iterator it=handlers.begin(); it!=handlers.end();
         ++it) {
      //(*it)->writeStats(std::cout);
      (*it)->writeStats(env->getLogger()->msgStream(LogExtraInfo));
    }

    writeSol(env, orig_v, pres, bab->getSolution(), bab->getStatus(), iface);
    writeBnbStatus(env, bab, obj_sense);
  }

CLEANUP:
  if (iface) {
    delete iface;
  }
  if (orig_v) {
    delete orig_v;
  }
  if (bab) {
    delete bab;
  }

  return 0;
}