本文整理汇总了C++中IloEnv::warning方法的典型用法代码示例。如果您正苦于以下问题:C++ IloEnv::warning方法的具体用法?C++ IloEnv::warning怎么用?C++ IloEnv::warning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IloEnv
的用法示例。
在下文中一共展示了IloEnv::warning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: x
//.........这里部分代码省略.........
}
}
// Test complementary slackness.
// For each constraint either the constraint must have zero slack or
// the dual multiplier for the constraint must be 0. We must also
// consider the special case in which a variable is not explicitly
// contained in a second order cone constraint.
for (IloInt i = 0; i < vars.getSize(); ++i) {
if ( cone[i] == NOT_IN_CONE ) {
if ( fabs(x[i]) > tol && dslack[i] > tol ) {
env.error() << "Invalid complementary slackness for " << vars[i]
<< ":" << endl
<< " " << x[i] << " and " << dslack[i]
<< endl;
return false;
}
}
}
for (IloInt i = 0; i < rngs.getSize(); ++i) {
if ( fabs(slack[i]) > tol && fabs(pi[i]) > tol ) {
env.error() << "Invalid complementary slackness for "
<< endl << rngs[i] << ":" << endl
<< " " << slack[i] << " and " << pi[i]
<< endl;
return false;
}
}
// Test stationarity.
// We must have
// c - g[i]'(X)*pi[i] = 0
// where c is the objective function, g[i] is the i-th constraint of the
// problem, g[i]'(x) is the derivate of g[i] with respect to x and X is the
// optimal solution.
// We need to distinguish the following cases:
// - linear constraints g(x) = ax - b. The derivative of such a
// constraint is g'(x) = a.
// - second order constraints g(x[1],...,x[n]) = -x[1] + |(x[2],...,x[n])|
// the derivative of such a constraint is
// g'(x) = (-1, x[2]/|(x[2],...,x[n])|, ..., x[n]/|(x[2],...,x[n])|
// (here |.| denotes the Euclidean norm).
// - bound constraints g(x) = -x for variables that are not explicitly
// contained in any second order cone constraint. The derivative for
// such a constraint is g'(x) = -1.
// Note that it may happen that the derivative of a second order cone
// constraint is not defined at the optimal solution X (this happens if
// X=0). In this case we just skip the stationarity test.
IloNumArray sum(env, vars.getSize());
for (IloExpr::LinearIterator it = obj.getLinearIterator(); it.ok(); ++it)
sum[idx(it.getVar())] = it.getCoef();
for (IloInt i = 0; i < vars.getSize(); ++i) {
IloNumVar v = vars[i];
if ( cone[i] == NOT_IN_CONE )
sum[i] -= dslack[i];
}
for (IloInt i = 0; i < rngs.getSize(); ++i) {
IloRange r = rngs[i];
if ( r.getQuadIterator().ok() ) {
// Quadratic (second order cone) constraint.
IloNum norm = 0.0;
for (IloExpr::QuadIterator q = r.getQuadIterator(); q.ok(); ++q) {
if ( q.getCoef() > 0 )
norm += x[idx(q.getVar1())] * x[idx(q.getVar1())];
}
norm = sqrt(norm);
if ( fabs(norm) <= tol ) {
// Derivative is not defined. Skip test.
env.warning() << "Cannot test stationarity at non-differentiable point."
<< endl;
return true;
}
else {
for (IloExpr::QuadIterator q = r.getQuadIterator(); q.ok(); ++q) {
if ( q.getCoef() < 0 )
sum[idx(q.getVar1())] -= pi[i];
else
sum[idx(q.getVar1())] += pi[i] * x[idx(q.getVar1())] / norm;
}
}
}
else {
// Linear constraint.
for (IloExpr::LinearIterator l = r.getLinearIterator(); l.ok(); ++l)
sum[idx(l.getVar())] -= pi[i] * l.getCoef();
}
}
// Now test that all elements in sum[] are 0.
for (IloInt i = 0; i < vars.getSize(); ++i) {
if ( fabs(sum[i]) > tol ) {
env.error() << "Invalid stationarity " << sum[i] << " for "
<< vars[i] << endl;
return false;
}
}
return true;
}