本文整理汇总了C++中Simplex::has_solution方法的典型用法代码示例。如果您正苦于以下问题:C++ Simplex::has_solution方法的具体用法?C++ Simplex::has_solution怎么用?C++ Simplex::has_solution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simplex
的用法示例。
在下文中一共展示了Simplex::has_solution方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solmax
//.........这里部分代码省略.........
// inequations en <= (nb=ineq1), inequations en >= (nb=ineq2)
// les inequations X_q >= 0 sont deja
// prisent en comptent de manière implicite
double s1;
double s2;
set< Word, ordre_mot >::const_iterator wi;
double pvw = 0; // v^{-1}P(w)
s2 = S[v];
// Initialisation du simplexe
simplx.set_number_of_unknown_to(XR.size()+1);
// sum of all Xi is equal to 1
simplx.setparam(1,0); // --- la variable 1 est toujours epsilon ---
simplx.setval(1); //
for (q = XR.begin (); q != XR.end (); q++)
simplx.setparam(q->second+1,1);
simplx.add_equality_constraint();
// cout << "XR.size() = " << XR.size() << endl;
// loop for each word :
simplx.setparam(1,1); // --- la variable 1 est toujours epsilon ---
i=0;
for (wi = W.begin (); wi != W.end () && i <= max; wi++)
{
s1 = S[(v + *wi)];
pvw = (double) s1 / (double) s2;
simplx.setval(pvw);
for (q = XR.begin (); q != XR.end (); q++)
{
s1 = S[q->first + *wi];
simplx.setparam(q->second+1, (double) s1 / (double) S[q->first]);
}
simplx.add_absolute_constraint();
++i;
}
switch (modeeps)
{
// ---------------------------------------------------------- EPSFIXED -
case epsfixed:
simplx.set_minimize_epsilon_mode(precision);
break;
// ---------------------------------------------------------- VARIABLE -
case variable:
simplx.set_minimize_epsilon_mode(-1);
break;
default:
cerr << "!!! PFA::sol -- modeeps " << modeeps << " inconnu !!!" << endl;
}
switch(modeVariables) {
case determinist:
simplx.set_mode(ZeroOrOne);
break;
case positive:
simplx.set_mode(realZeroBounded);
break;
case nonconstrained:
simplx.set_mode(realNotBounded);
break;
}
map<int,float> preciseSol;
float epsilon;
// simplx.affiche();
err = simplx.has_solution(preciseSol, epsilon);
// cout << (err?"solution trouvée":"pas de solution") << ", epsilon = " << epsilon << endl;
if ((!err) || (epsilon>precision)) {
solution.clear();
return ERR(0);
}
else {
solution.clear();
float tmp;
for (map<int,float>::const_iterator q = preciseSol.begin() ; q != preciseSol.end() ; q++) {
if (q->first != 1) {
if ((tmp = (float) q->second) != 0) {
solution[q->first - 1] = (float) q->second;
}
}
}
return VAL(0);
}
}
catch (int erreur)
{
if (PFA_VERBOSE)
{
cerr << "ERREUR !!! PFA::solmax !!! n°" << erreur << endl;
}
solution.clear ();
return erreur;
}
}