コード例 #1
0
void
MultilinearTermsHandler::relaxNodeInc(NodePtr node,
                                      RelaxationPtr relaxation, bool *isInfeasible)
{
  *isInfeasible = false;

#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
  std::cout << "MultilinearTermsHandler::relaxNodeInc.  Node: ";
  node->write(std::cout);
  std::cout << "Initial Relaxation: ";
  relaxation->write(std::cout);
#endif

  ModVector mods;
  handleXDefConstraints_(relaxation, relaxNodeInc_Call, mods);
  handleZDefConstraints_(relaxation, relaxNodeInc_Call, mods);
  
  ModificationConstIterator it;
  for (it = mods.begin(); it != mods.end(); ++it) {
    node->addRMod(*it);
  }

#if defined(DEBUG_MULTILINEARTERMS_HANDLER) 
  std::cout << "MultilinearTermsHandler::relaxNodeInc.  Final relaxation:" << std::endl;
  relaxation->write(std::cout);
#endif

}
コード例 #2
0
void CxUnivarHandler::relaxNodeInc(NodePtr , RelaxationPtr rel, bool *is_inf)
{

#if defined(DEBUG_CXUNIVARHANDLER)
  std::cout << "CxUnivarHandler::relaxNodeInc.  Current relaxation: "
            << std::endl;
  rel->write(std::cout);
  std::cout << "Current node: " << std::endl;
  node->write(std::cout);
#endif

  // You must apply all modifications to the nodes

  // I think this is all done by branches now.
  //  FALSE -- If you don't branch on a variable, you still need to update the relaxation from
  //  this node

  ModVector mods;
  CxUnivarConstraintIterator dit;   
  for (dit = cons_data_.begin(); dit != cons_data_.end(); ++dit) {
    (*dit)->updateRelax(rel, tmpX_, grad_, mods);
  }

  ModificationConstIterator it;
  for (it = mods.begin(); it != mods.end(); ++it) {
    assert(!"add Mod correctly here.");
    // node->addPMod(*it);
  }

 *is_inf = false;
}
コード例 #3
0
void
MultilinearTermsHandler::relaxInitInc(RelaxationPtr relaxation, bool *)
{

  //  General notes...
  // Use Id to order variables
  // x[v->getIndex()] returns solution.
  
  /*
    0) Create "terms" map using the relaxation variables, not the original
       problem variables
    1) Create groups based on container of terms
    2) Add all lambda variables based on groups.
       (Be sure to keep a container of which constraints are associated with
       which groups)
   */

#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
  cout << "In MultilinearTermHandler::relaxInitInc()" << endl << " Current Relaxation: " << endl;
  relaxation->write(cout);
  cout << "And current terms: " << endl;

  for(ConstTermIterator it = termsO_.begin(); it != termsO_.end(); ++it) {
    std::cout << "zvar: ";
    it->first->write(std::cout);
    std::cout << "Contains vars: " << std::endl;
    for(SetOfVars::const_iterator it2 = it->second.begin(); 
        it2 != it->second.end(); ++it2) {
      (*it2)->write(cout);
    }
  }
#endif  

  // Copy the original variable pointers into a data structure consisting of 
  //  relaxation variables   (It just makes likfe easier to keep things in 
  //  terms of relaxation variables).
  for (ConstTermIterator it = termsO_.begin(); it != termsO_.end(); ++it) {
    ConstVariablePtr ov = it->first;
    SetOfVars const &ovset = it->second;
    ConstVariablePtr rv = relaxation->getRelaxationVar(ov);
    SetOfVars rvset;
    for(SetOfVars::const_iterator it2 = ovset.begin(); it2 != ovset.end(); ++it2) {
      rvset.insert( relaxation->getRelaxationVar(*it2));
    }
    termsR_.insert(make_pair(rv, rvset));
  }
      
    
  // First we make the groups.

  makeGroups_();

#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
  cout << "After making groups: " << endl;

  for (ConstGroupIterator it = groups_.begin(); it != groups_.end(); ++it) {  
    cout << "Group of: " << endl;
    for(set<ConstVariablePtr>::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) {
      (*it2)->write(cout);
    }
  }

  // Just checking groups now.  Stop here.
  //exit(1);
#endif

  /* This chunk of code creates the (powerset) representation 
   * of the extreme points in the groups, adds the lambda variables,
   * and adds the convexity constraints
   */

  lambdavars_.resize(groups_.size());
  for(UInt gix = 0; gix < groups_.size(); ++gix) {    

    LinearFunctionPtr lf = (LinearFunctionPtr) new LinearFunction();

    std::set<SetOfVars> p = powerset_(groups_[gix]);
    int pix = 0;
    for (std::set<SetOfVars>::iterator it2 = p.begin(); it2 != p.end(); ++it2) {
      std::string name;
      std::stringstream name_stream;
      name_stream << "lam_" << gix << "_" << pix;
      name = name_stream.str();
      
      VariablePtr lam;
      lam = relaxation->newVariable(0.0, 1.0, Continuous, name);
      lf->addTerm(lam, 1.0);
#if defined(DEBUG_MULTILINEARTERMS_HANDLER2)
      std::cout << "Adding: " << name << std::endl;
#endif

      lambdavars_[gix].push_back(lam);
      pix++;
    }    
    points_.push_back(p);
    FunctionPtr f = (FunctionPtr) new Function(lf);
    relaxation->newConstraint(f, 1.0, 1.0);
  }  


  ModVector mods;  // Not used in initialization
  handleXDefConstraints_(relaxation, relaxInit_Call, mods);
  handleZDefConstraints_(relaxation, relaxInit_Call, mods);


#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
  std::cout << "In MultilinearTermHandler::relaxInitInc()" << std::endl << " Final Relaxation: " << std::endl;
  relaxation->write(std::cout);
#endif
    
}