当前位置: 首页>>代码示例>>C++>>正文


C++ LinearFunctionPtr::termsEnd方法代码示例

本文整理汇总了C++中LinearFunctionPtr::termsEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearFunctionPtr::termsEnd方法的具体用法?C++ LinearFunctionPtr::termsEnd怎么用?C++ LinearFunctionPtr::termsEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinearFunctionPtr的用法示例。


在下文中一共展示了LinearFunctionPtr::termsEnd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: logobj

Bool logobj(LinearFunctionPtr lf, CGraphPtr nlf)
{
  UInt numvars = lf->getNumTerms();
  // VariableSet vars;
  // lf->getVars(&vars);
  VariableGroup::const_iterator it;
  VariableGroup::const_iterator begin = lf->termsBegin();
  VariableGroup::const_iterator end   = lf->termsEnd();
  // Variable nodes.
  std::map<UInt,CNode*> varnodes;
  std::map<CNode*, CNode*> lognodes;
  std::map<UInt, CNode*> logidnodes;
  std::map<CNode*, CNode*> numnodes;
  std::map<UInt, CNode*> numidnodes;
  std::map<CNode*, CNode*> mulnodes;
  std::map<UInt, CNode*> mulidnodes;
  std::set<CNode*> multnodes;
  std::map<UInt, CNode*> multidnodes;
  CNode** multnodesvec = new CNode*[numvars];
  // Iterate through variables.
  CNode* tempnode;
  CNode* lognode;
  CNode* numnode;
  CNode* mulnode;
  CNode* onenode;
  CNode* sumnode;
  // Create numnode for one.
  UInt index = 0;
  for(it=begin; it!=end; ++it) {
    VariablePtr var = it->first;
    Double varlb = var->getLb();
    if (varlb >= 0) {
      UInt varid = var->getId();
      Double coeff = it->second;
      // Create variable node and add it to a set.
      tempnode = nlf->newNode(var);
      varnodes.insert(std::pair<UInt,CNode*>(varid,tempnode));
      onenode = nlf->newNode(1.0);
      // Create sumnode.      
      sumnode = nlf->newNode(OpPlus, onenode, tempnode);
      // Create log nodes.
      lognode = nlf->newNode(OpLog, &sumnode, 1);
      lognodes.insert(std::pair<CNode* , CNode*>(tempnode, lognode));
      logidnodes.insert(std::pair<UInt, CNode*>(varid, lognode));
      // Create num nodes.
      numnode = nlf->newNode(coeff);
      numnodes.insert(std::pair<CNode*, CNode*>(tempnode, numnode));
      numidnodes.insert(std::pair<UInt, CNode*>(varid, numnode));
      // Create mul nodes.
      mulnode = nlf->newNode(OpMult, numnode, lognode);
      multnodes.insert(mulnode);
      multidnodes.insert(std::pair<UInt, CNode*>(varid,mulnode));
      multnodesvec[index] = mulnode;
      index++;
    }
  }
  
  // This is the root node.
  CNode* sumlistnode = nlf->newNode(OpSumList, multnodesvec, index);  
  nlf->setOut(sumlistnode);
  nlf->finalize();
  
  return true;
}
开发者ID:devanandR,项目名称:minotaur,代码行数:64,代码来源:CoverCutTest.cpp

示例2: if


//.........这里部分代码省略.........
      for(VariableConstIterator varit2 = inst->varsBegin(); varit2 != inst->varsEnd(); ++varit2) {
	for(VariablePairGroupConstIterator it = objQF->begin(); it != objQF->end(); ++it) {
	  if(((it->first).first)->getId() == (*varit1)->getId() && ((it->first).second)->getId() == (*varit2)->getId()){
	    int var1Id = (*varit1)->getId();
	    int var2Id = (*varit2)->getId();
	    objQ[var1Id][var2Id] = it->second;
	  }
	}
      }
    }
  }
  double ij;
  double ji;
  for(int i = 0; i < numVars; i++) {
    for(int j = i+1; j < numVars; j++) {
      ij = objQ[i][j];
      ji = objQ[j][i];
      objQ[i][j] = (ij+ji)/2;
      objQ[j][i] = (ij+ji)/2;
    }
  }
  
  for(int i = 0; i < numVars; i++) {
    for(int j = 0; j < numVars; j++) {
      fprintf(pFile, "%f\t", objQ[i][j]);
    }
    fprintf(pFile, "\n");
  }
  fprintf(pFile, "\n\n");

  //find objA
  if(objLF) {
    for(VariableConstIterator varit = inst->varsBegin(); varit != inst->varsEnd(); ++varit) {
      for(VariableGroupConstIterator it = objLF->termsBegin(); it != objLF->termsEnd(); ++it) {
	if((*varit)->getId() == (it->first)->getId()) {
	  objA[(*varit)->getId()] = it->second;
	}
      }
    }
  }

  for(int i = 0; i < numVars; i++)
    fprintf(pFile, "%f\t", objA[i]);
  fprintf(pFile, "\n");
  fprintf(pFile, "\n\n");

  //take care of the quadratic constraints
  for(ConstraintConstIterator cIter=inst->consBegin(); cIter!=inst->consEnd(); ++cIter) {
    FunctionType ct = (*cIter)->getFunctionType();
    if(ct == Quadratic) {
      // if it's an equality constraint
      if((*cIter)->getUb() - (*cIter)->getLb() >= -1e-6 && (*cIter)->getUb() - (*cIter)->getLb() <= 1e-6)  {
	fprintf(pFile, "%d\n", 1);
	fprintf(pFile, "%f\n\n", (*cIter)->getUb());
      }
      // if it's a <= constraint
      else if((*cIter)->getUb() <= 1e6)  {
	fprintf(pFile, "%d\n", 2);
	fprintf(pFile, "%f\n\n", (*cIter)->getUb());
      }
      else if ((*cIter)->getLb() >= -1e6) {
	fprintf(pFile, "%d\n", 3);
	fprintf(pFile, "%f\n\n", (*cIter)->getLb());	
      }

      FunctionPtr F = (*cIter)->getFunction();
开发者ID:devanandR,项目名称:minotaur,代码行数:67,代码来源:qp-converter.cpp


注:本文中的LinearFunctionPtr::termsEnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。