本文整理汇总了C++中LinearFunctionPtr::termsBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearFunctionPtr::termsBegin方法的具体用法?C++ LinearFunctionPtr::termsBegin怎么用?C++ LinearFunctionPtr::termsBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearFunctionPtr
的用法示例。
在下文中一共展示了LinearFunctionPtr::termsBegin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assignHandler_
void Transformer::assignHandler_(CGraphPtr cg, ConstraintPtr c)
{
switch (cg->getOut()->getOp()) {
case OpMult:
case OpSqr:
qHandler_->addConstraint(c);
break;
default:
{
VariablePtr iv;
VariablePtr ov = VariablePtr();
LinearFunctionPtr lf = c->getFunction()->getLinearFunction();
if (lf) {
assert(lf->getNumTerms()==1);
ov = lf->termsBegin()->first;
}
iv = *(c->getFunction()->getNonlinearFunction()->varsBegin());
uHandler_->addConstraint(c, iv, ov, 'E');
}
}
}
示例2: 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;
}
示例3: 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();