本文整理汇总了C++中LinearFunctionPtr::getWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearFunctionPtr::getWeight方法的具体用法?C++ LinearFunctionPtr::getWeight怎么用?C++ LinearFunctionPtr::getWeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearFunctionPtr
的用法示例。
在下文中一共展示了LinearFunctionPtr::getWeight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void
Hypergraph::create(std::map<ConstVariablePtr, SetOfVars > const &terms)
{
// Add the vertices
std::map<ConstVariablePtr, SetOfVars >::const_iterator terms_it;
for(terms_it = terms.begin(); terms_it != terms.end(); ++terms_it) {
SetOfVars const &jt = terms_it->second;
for(SetOfVars::iterator it = jt.begin(); it != jt.end(); ++it) {
V_.insert(*it);
}
}
// Add empty lists for the hyperedges
for(SetOfVars::iterator v_it = V_.begin(); v_it != V_.end(); ++v_it) {
std::list<SetOfVars> e_list;
adjList_.insert(make_pair(*v_it, e_list));
}
// Now add the edges
for(terms_it = terms.begin(); terms_it != terms.end(); ++terms_it) {
SetOfVars const &jt = terms_it->second;
E_.insert(jt);
// Put it in the adjacency lists
for (SetOfVars::const_iterator it = jt.begin(); it != jt.end(); ++it) {
AdjListType::iterator pos = adjList_.find(*it);
assert(pos != adjList_.end());
std::list<SetOfVars> &e_list = pos->second;
e_list.push_back(jt);
}
// Determine weight
ConstVariablePtr zvar = terms_it->first;
double zweight = 0.0;
for (ConstrSet::iterator it2 = zvar->consBegin(); it2 != zvar->consEnd(); ++it2) {
const LinearFunctionPtr lf = (*it2)->getLinearFunction();
double w = lf->getWeight(zvar);
#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
zvar->write(std::cout);
std::cout << " has weight: " << w << " in constraint: ";
(*it2)->write(std::cout);
#endif
zweight += fabs(w);
}
// Add objective weight
const LinearFunctionPtr obj = problem_->getObjective()->getLinearFunction();
if (obj != 0) {
double w = obj->getWeight(zvar);
zweight += fabs(w);
}
weights_.insert(make_pair(jt, zweight));
originalWeights_.insert(make_pair(jt, zweight));
}
}
示例2: if
bool SOS1Handler::isGUB(SOS *sos)
{
VariablePtr var;
int nz = sos->getNz();
ConstConstraintPtr c;
FunctionPtr f;
LinearFunctionPtr lf;
bool isgub = false;
for (VariableConstIterator viter = sos->varsBegin(); viter!=sos->varsEnd();
++viter) {
var = *viter;
if (Binary!=var->getType() || ImplBin!=var->getType()) {
return false;
}
}
// If we are here, then it means all variables are binary. Check if their sum
// is <= 1.
var = *(sos->varsBegin());
for (ConstrSet::iterator it=var->consBegin();
it!=var->consEnd() && false==isgub; ++it) {
c = *it;
f = c->getFunction();
isgub = true;
if (Linear!=f->getType()) {
isgub = false;
} else if ((UInt) nz==f->getNumVars()) {
isgub = false;
} else if (fabs(c->getUb()-1.0)>zTol_) {
isgub = false;
} else {
lf = f->getLinearFunction();
for (VariableConstIterator viter = sos->varsBegin();
viter!=sos->varsEnd(); ++viter) {
if ((lf->getWeight(*viter)-1.0)>zTol_) {
isgub = false;
break;
}
}
}
}
return isgub;
}
示例3: defined
void
MultilinearTermsHandler::setupWeights_()
{
for(ConstTermIterator it = termsR_.begin(); it != termsR_.end(); ++it) {
ConstVariablePtr zvar = it->first;
double zweight = 0.0;
for (ConstrSet::iterator it2 = zvar->consBegin(); it2 != zvar->consEnd(); ++it2) {
const LinearFunctionPtr lf = (*it2)->getLinearFunction();
double w = lf->getWeight(zvar);
#if defined(DEBUG_MULTILINEARTERMS_HANDLER)
zvar->write(std::cout);
std::cout << " has weight: " << w << " in constraint: ";
(*it2)->write(std::cout);
#endif
zweight += fabs(w);
}
weights_.insert(std::make_pair(zvar, zweight));
}
}