56 #define SIGN(x) ((x) >= 0.0 ? 1.0 : -1.0) 60 #define SCIPInterval_NAMESPACE CppAD 67 using CppAD::SCIPInterval;
72 #ifndef CPPAD_MAX_NUM_THREADS 74 #define CPPAD_MAX_NUM_THREADS 64 76 #define CPPAD_MAX_NUM_THREADS 1 80 #include <cppad/cppad.hpp> 81 #include <cppad/utility/error_handler.hpp> 92 static pthread_mutex_t
cppadmutex = PTHREAD_MUTEX_INITIALIZER;
122 if( specific == NULL )
141 threadnum = (size_t)(specific) - 1;
159 CppAD::parallel_ad<double>();
160 CppAD::parallel_ad<SCIPInterval>();
169 #if !defined(_MSC_VER) 170 __attribute__ ((unused))
179 enum CppAD::CompareOp cop,
180 const SCIPInterval& left,
181 const SCIPInterval& right,
182 const SCIPInterval& trueCase,
183 const SCIPInterval& falseCase)
185 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
186 "SCIPInterval CondExpOp(...)",
187 "Error: cannot use CondExp with an interval type" 190 return SCIPInterval();
196 const SCIPInterval& x
205 const SCIPInterval& x
214 const SCIPInterval& x
223 const SCIPInterval& x,
224 const SCIPInterval& y
233 const SCIPInterval& x
236 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
237 "GreaterThanZero(x)",
238 "Error: cannot use GreaterThanZero with interval" 247 const SCIPInterval& x
250 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__ ,
251 "GreaterThanOrZero(x)",
252 "Error: cannot use GreaterThanOrZero with interval" 261 const SCIPInterval& x
264 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
266 "Error: cannot use LessThanZero with interval" 275 const SCIPInterval& x
278 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
280 "Error: cannot use LessThanOrZero with interval" 289 const SCIPInterval& x
292 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
294 "Error: cannot use Integer with interval" 306 const SCIPInterval& x,
307 const SCIPInterval& y
310 if( x.inf == 0.0 && x.sup == 0.0 )
311 return SCIPInterval(0.0, 0.0);
319 out <<
'[' << x.
inf <<
',' << x.
sup <<
']';
332 struct SCIP_ExprIntData
337 : val(0.0), need_retape(
true), int_need_retape(
true), need_retape_always(
false), userevalcapability(
SCIP_EXPRINTCAPABILITY_ALL), blkmem(NULL), root(NULL)
344 vector< AD<double> > X;
345 vector< AD<double> > Y;
346 CppAD::ADFun<double> f;
352 vector< AD<SCIPInterval> > int_X;
353 vector< AD<SCIPInterval> > int_Y;
354 CppAD::ADFun<SCIPInterval> int_f;
356 vector<SCIPInterval> int_x;
357 SCIPInterval int_val;
358 bool int_need_retape;
360 bool need_retape_always;
367 #ifndef NO_CPPAD_USER_ATOMIC 377 const CppAD::vector<bool>& r,
378 CppAD::vector<bool>& s
381 assert(r.size() == q);
382 assert(s.size() == q);
397 const CppAD::vector<bool>& r,
398 CppAD::vector<bool>& s
401 assert(r.size() == q);
402 assert(s.size() == q);
416 const CppAD::vector<bool>& vx,
417 const CppAD::vector<bool>& s,
418 CppAD::vector<bool>& t,
420 const CppAD::vector<bool>& r,
421 const CppAD::vector<bool>& u,
422 CppAD::vector<bool>& v
425 assert(r.size() == q);
426 assert(s.size() == 1);
427 assert(t.size() == 1);
428 assert(u.size() == q);
429 assert(v.size() == q);
438 for(
size_t j = 0; j < q; ++j )
458 :
CppAD::atomic_base<
Type>(
"posintpower"),
462 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
473 virtual void set_id(
size_t id)
493 const CppAD::vector<bool>& vx,
494 CppAD::vector<bool>& vy,
495 const CppAD::vector<Type>& tx,
496 CppAD::vector<Type>& ty
499 assert(exponent > 1);
500 assert(tx.size() >= p+1);
501 assert(ty.size() >= p+1);
506 assert(vx.size() == 1);
507 assert(vy.size() == 1);
518 if( q <= 1 && 1 <= p )
520 ty[1] =
CppAD::pow(tx[0], exponent-1) * tx[1];
521 ty[1] *= double(exponent);
524 if( q <= 2 && 2 <= p )
529 ty[2] =
CppAD::pow(tx[0], exponent-2) * tx[1] * tx[1];
530 ty[2] *= (exponent-1) / 2.0;
531 ty[2] +=
CppAD::pow(tx[0], exponent-1) * tx[2];
536 assert(exponent == 2);
538 ty[2] = tx[1] * tx[1] + 2.0 * tx[0] * tx[2];
581 const CppAD::vector<Type>& tx,
582 const CppAD::vector<Type>& ty,
583 CppAD::vector<Type>& px,
584 const CppAD::vector<Type>& py
587 assert(exponent > 1);
588 assert(px.size() >= p+1);
589 assert(py.size() >= p+1);
590 assert(tx.size() >= p+1);
596 px[0] = py[0] *
CppAD::pow(tx[0], exponent-1);
602 px[0] = py[1] * tx[1] *
CppAD::pow(tx[0], exponent-2);
604 px[0] += py[0] *
CppAD::pow(tx[0], exponent-1);
607 px[1] = py[1] *
CppAD::pow(tx[0], exponent-1);
618 using CppAD::atomic_base<Type>::for_sparse_jac;
627 const CppAD::vector<bool>& r,
628 CppAD::vector<bool>& s
634 using CppAD::atomic_base<Type>::rev_sparse_jac;
643 const CppAD::vector<bool>& r,
644 CppAD::vector<bool>& s
650 using CppAD::atomic_base<Type>::rev_sparse_hes;
658 const CppAD::vector<bool>& vx,
659 const CppAD::vector<bool>& s,
660 CppAD::vector<bool>& t,
662 const CppAD::vector<bool>& r,
663 const CppAD::vector<bool>& u,
664 CppAD::vector<bool>& v
675 const vector<Type>& in,
681 pip(in, out, exponent);
689 const vector<Type>& in,
694 out[0] =
pow(in[0], (
int)exponent);
700 #ifndef NO_CPPAD_USER_ATOMIC 719 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
730 virtual void set_id(
size_t id)
750 const CppAD::vector<bool>& vx,
751 CppAD::vector<bool>& vy,
752 const CppAD::vector<Type>& tx,
753 CppAD::vector<Type>& ty
756 assert(exponent > 0.0);
757 assert(tx.size() >= p+1);
758 assert(ty.size() >= p+1);
763 assert(vx.size() == 1);
764 assert(vy.size() == 1);
775 if( q <= 1 && 1 <= p )
777 ty[1] =
pow(
REALABS(tx[0]), exponent - 1.0) * tx[1];
781 if( q <= 2 && 2 <= p )
783 if( exponent != 2.0 )
785 ty[2] =
SIGN(tx[0]) *
pow(
REALABS(tx[0]), exponent - 2.0) * tx[1] * tx[1];
786 ty[2] *= (exponent - 1.0) / 2.0;
787 ty[2] +=
pow(
REALABS(tx[0]), exponent - 1.0) * tx[2];
793 ty[2] =
SIGN(tx[0]) * tx[1] * tx[1];
794 ty[2] += 2.0 *
REALABS(tx[0]) * tx[2];
837 const CppAD::vector<Type>& tx,
838 const CppAD::vector<Type>& ty,
839 CppAD::vector<Type>& px,
840 const CppAD::vector<Type>& py
843 assert(exponent > 1);
844 assert(px.size() >= p+1);
845 assert(py.size() >= p+1);
846 assert(tx.size() >= p+1);
852 px[0] = py[0] *
pow(
REALABS(tx[0]), exponent - 1.0);
857 if( exponent != 2.0 )
860 px[0] = py[1] * tx[1] *
pow(
REALABS(tx[0]), exponent - 2.0) *
SIGN(tx[0]);
861 px[0] *= exponent - 1.0;
862 px[0] += py[0] *
pow(
REALABS(tx[0]), exponent - 1.0);
865 px[1] = py[1] *
pow(
REALABS(tx[0]), exponent - 1.0);
871 px[0] = py[1] * tx[1] *
SIGN(tx[0]);
872 px[0] += py[0] *
REALABS(tx[0]);
875 px[1] = py[1] *
REALABS(tx[0]);
887 using CppAD::atomic_base<Type>::for_sparse_jac;
896 const CppAD::vector<bool>& r,
897 CppAD::vector<bool>& s
903 using CppAD::atomic_base<Type>::rev_sparse_jac;
912 const CppAD::vector<bool>& r,
913 CppAD::vector<bool>& s
919 using CppAD::atomic_base<Type>::rev_sparse_hes;
927 const CppAD::vector<bool>& vx,
928 const CppAD::vector<bool>& s,
929 CppAD::vector<bool>& t,
931 const CppAD::vector<bool>& r,
932 const CppAD::vector<bool>& u,
933 CppAD::vector<bool>& v
943 class atomic_signpower<SCIPInterval> :
public CppAD::atomic_base<SCIPInterval>
947 : CppAD::atomic_base<SCIPInterval>(
"signpowerint"),
951 this->option(CppAD::atomic_base<SCIPInterval>::bool_sparsity_enum);
962 virtual void set_id(
size_t id)
974 const CppAD::vector<bool>& vx,
975 CppAD::vector<bool>& vy,
976 const CppAD::vector<SCIPInterval>& tx,
977 CppAD::vector<SCIPInterval>& ty
980 assert(exponent > 0.0);
981 assert(tx.size() >= p+1);
982 assert(ty.size() >= p+1);
987 assert(vx.size() == 1);
988 assert(vy.size() == 1);
999 if( q <= 1 && 1 <= p )
1005 if( q <= 2 && 2 <= p )
1007 if( exponent != 2.0 )
1010 ty[2] *= (exponent - 1.0) / 2.0;
1035 const CppAD::vector<SCIPInterval>& tx,
1036 const CppAD::vector<SCIPInterval>& ty,
1037 CppAD::vector<SCIPInterval>& px,
1038 const CppAD::vector<SCIPInterval>& py
1041 assert(exponent > 1);
1042 assert(px.size() >= p+1);
1043 assert(py.size() >= p+1);
1044 assert(tx.size() >= p+1);
1055 if( exponent != 2.0 )
1059 px[0] *= exponent - 1.0;
1085 using CppAD::atomic_base<SCIPInterval>::for_sparse_jac;
1092 bool for_sparse_jac(
1094 const CppAD::vector<bool>& r,
1095 CppAD::vector<bool>& s
1101 using CppAD::atomic_base<SCIPInterval>::rev_sparse_jac;
1108 bool rev_sparse_jac(
1110 const CppAD::vector<bool>& r,
1111 CppAD::vector<bool>& s
1117 using CppAD::atomic_base<SCIPInterval>::rev_sparse_hes;
1124 bool rev_sparse_hes(
1125 const CppAD::vector<bool>& vx,
1126 const CppAD::vector<bool>& s,
1127 CppAD::vector<bool>& t,
1129 const CppAD::vector<bool>& r,
1130 const CppAD::vector<bool>& u,
1131 CppAD::vector<bool>& v
1139 template<
class Type>
1147 vector<Type> in(1, arg);
1148 vector<Type> out(1);
1151 sp(in, out, (
size_t)(
void*)expr);
1163 template<
class Type>
1171 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1173 "Error: SignPower not implemented for this value type" 1180 CppAD::AD<double>& resultant,
1181 const CppAD::AD<double>& arg,
1191 else if( arg > 0.0 )
1192 resultant =
pow( arg, exponent);
1194 resultant = -
pow(-arg, exponent);
1200 #ifndef NO_CPPAD_USER_ATOMIC 1202 template<
class Type>
1218 SCIPInterval& funcval,
1219 SCIPInterval* gradient,
1220 SCIPInterval* hessian
1230 template<
class Type>
1239 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
1250 virtual void set_id(
size_t id)
1280 const CppAD::vector<bool>& vx,
1281 CppAD::vector<bool>& vy,
1282 const CppAD::vector<Type>& tx,
1283 CppAD::vector<Type>& ty
1286 assert(expr != NULL);
1287 assert(ty.size() == p+1);
1290 size_t n = tx.size() / (p+1);
1296 assert(vx.size() == n);
1297 assert(vy.size() == 1);
1302 for(
size_t i = 0; i < n; ++i )
1311 Type* gradient = NULL;
1312 Type* hessian = NULL;
1314 if( q <= 2 && 1 <= p )
1315 gradient =
new Type[n];
1316 if( q <= 2 && 2 <= p )
1317 hessian =
new Type[n*n];
1319 for(
size_t i = 0; i < n; ++i )
1320 x[i] = tx[i * (p+1) + 0];
1330 if( gradient != NULL )
1333 for(
size_t i = 0; i < n; ++i )
1334 ty[1] += gradient[i] * tx[i * (p+1) + 1];
1337 if( hessian != NULL )
1339 assert(gradient != NULL);
1342 for(
size_t i = 0; i < n; ++i )
1344 for(
size_t j = 0; j < n; ++j )
1345 ty[2] += 0.5 * hessian[i*n+j] * tx[i * (p+1) + 1] * tx[j * (p+1) + 1];
1347 ty[2] += gradient[i] * tx[i * (p+1) + 2];
1420 const CppAD::vector<Type>& tx,
1421 const CppAD::vector<Type>& ty,
1422 CppAD::vector<Type>& px,
1423 const CppAD::vector<Type>& py
1426 assert(expr != NULL);
1427 assert(px.size() == tx.size());
1428 assert(py.size() == p+1);
1430 size_t n = tx.size() / (p+1);
1437 Type* hessian = NULL;
1440 hessian =
new Type[n*n];
1442 for(
size_t i = 0; i < n; ++i )
1443 x[i] = tx[i * (p+1) + 0];
1457 for(
size_t i = 0; i < n; ++i )
1458 px[i] = py[0] * gradient[i];
1464 assert(hessian != NULL);
1465 for(
size_t i = 0; i < n; ++i )
1467 px[i*2+0] = py[0] * gradient[i];
1468 for(
size_t j = 0; j < n; ++j )
1469 px[i*2+0] += py[1] * hessian[i+n*j] * tx[j*2+1];
1471 px[i*2+1] = py[1] * gradient[i];
1482 using CppAD::atomic_base<Type>::for_sparse_jac;
1488 bool for_sparse_jac(
1490 const CppAD::vector<bool>& r,
1491 CppAD::vector<bool>& s
1494 assert(expr != NULL);
1495 assert(s.size() == q);
1497 size_t n = r.size() / q;
1501 for(
size_t j = 0; j < q; j++ )
1504 for(
size_t i = 0; i < n; i++ )
1505 s[j] |= (
bool)r[i * q + j];
1511 using CppAD::atomic_base<Type>::rev_sparse_jac;
1517 bool rev_sparse_jac(
1519 const CppAD::vector<bool>& rt,
1520 CppAD::vector<bool>& st
1523 assert(expr != NULL);
1524 assert(rt.size() == q);
1526 size_t n = st.size() / q;
1530 for(
size_t j = 0; j < q; j++ )
1531 for(
size_t i = 0; i < n; i++ )
1532 st[i * q + j] = rt[j];
1537 using CppAD::atomic_base<Type>::rev_sparse_hes;
1543 bool rev_sparse_hes(
1544 const CppAD::vector<bool>& vx,
1545 const CppAD::vector<bool>& s,
1546 CppAD::vector<bool>& t,
1548 const CppAD::vector<bool>& r,
1549 const CppAD::vector<bool>& u,
1550 CppAD::vector<bool>& v
1553 assert(expr != NULL);
1554 size_t n = vx.size();
1556 assert(s.size() == 1);
1557 assert(t.size() == n);
1558 assert(r.size() == n * q);
1559 assert(u.size() == q);
1560 assert(v.size() == n * q);
1565 for( i = 0; i < n; ++i )
1573 for( j = 0; j < q; j++ )
1574 for( i = 0; i < n; i++ )
1575 v[ i * q + j] = u[j];
1580 for( j = 0; j < q; j++ )
1581 for( i = 0; i < n; i++ )
1582 for( k = 0; k < n; ++k )
1583 v[ i * q + j] |= (
bool) r[ k * q + j];
1590 template<
class Type>
1598 assert( args != 0 );
1600 vector<Type> out(1);
1603 u(in, out, (
size_t)(
void*)expr);
1611 template<
class Type>
1619 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1621 "Error: user expressions in CppAD not possible without CppAD user atomic facility" 1632 template<
class Type>
1640 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1642 "Error: Min not implemented for this value type" 1649 CppAD::AD<double>& resultant,
1650 const CppAD::AD<double>& arg1,
1651 const CppAD::AD<double>& arg2
1654 resultant = MIN(arg1, arg2);
1662 template<
class Type>
1670 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1672 "Error: Max not implemented for this value type" 1679 CppAD::AD<double>& resultant,
1680 const CppAD::AD<double>& arg1,
1681 const CppAD::AD<double>& arg2
1684 resultant =
MAX(arg1, arg2);
1691 template<
class Type>
1698 resultant =
sqrt(arg);
1702 template<
class Type>
1709 resultant =
abs(arg);
1718 CppAD::AD<SCIPInterval>& resultant,
1719 const CppAD::AD<SCIPInterval>& arg
1722 vector<CppAD::AD<SCIPInterval> > in(1, arg);
1723 vector<CppAD::AD<SCIPInterval> > out(1);
1727 resultant =
sqrt(out[0]);
1731 template<
class Type>
1741 vector<Type> in(1, arg);
1742 vector<Type> out(1);
1752 vector<Type> in(1, arg);
1753 vector<Type> out(1);
1757 resultant =
Type(1.0)/out[0];
1769 resultant =
Type(1.0);
1773 assert(exponent == -1);
1774 resultant =
Type(1.0)/arg;
1778 template<
class Type>
1782 const vector<Type>& x,
1789 assert(expr != NULL);
1816 assert(param != NULL);
1822 val = buf[0] + buf[1];
1827 val = buf[0] - buf[1];
1832 val = buf[0] * buf[1];
1837 val = buf[0] / buf[1];
1889 #ifdef SCIP_DISABLED_CODE 1895 case SCIP_EXPR_ERFI:
1942 val += coefs[i] * buf[i];
1954 vector<Type> out(1);
1961 assert(quadelems != NULL || nquadelems == 0);
1972 if( i == nquadelems || quadelems[i].idx1 > argidx )
1975 if( lincoefs != NULL )
1976 val += lincoefs[argidx] * buf[argidx];
1981 lincoef = lincoefs != NULL ? lincoefs[argidx] : 0.0;
1983 assert(i < nquadelems && quadelems[i].idx1 == argidx);
1986 if( quadelems[i].idx2 == argidx )
1987 sqrcoef += quadelems[i].
coef;
1989 lincoef += quadelems[i].
coef * buf[quadelems[i].
idx2];
1991 }
while( i < nquadelems && quadelems[i].idx1 == argidx );
1992 assert(i == nquadelems || quadelems[i].idx1 > argidx);
1995 if( sqrcoef != 0.0 )
1997 in[0] = buf[argidx];
1999 val += sqrcoef * out[0];
2002 val += lincoef * buf[argidx];
2004 assert(i == nquadelems);
2029 for( i = 0; i < nmonomials; ++i )
2036 for( j = 0; j < nfactors; ++j )
2038 assert(childidxs[j] >= 0);
2041 childval = buf[childidxs[j]];
2042 exponent = exponents[j];
2045 if( exponent == 0.0 )
2047 if( exponent == 1.0 )
2049 monomialval *= childval;
2052 if( (
int)exponent == exponent )
2059 if( exponent == 0.5 )
2066 monomialval *=
pow(childval, exponent);
2100 assert(expr != NULL);
2111 #ifdef NO_CPPAD_USER_ATOMIC 2114 data->need_retape_always =
true;
2142 SCIPdebugMessage(
"ignore CppAD error from %sknown source %s:%d: msg: %s exp: %s\n", known ?
"" :
"un", file, line, msg, cond);
2151 return CPPAD_PACKAGE_STRING;
2157 return "Algorithmic Differentiation of C++ algorithms developed by B. Bell (www.coin-or.org/CppAD)";
2176 assert(blkmem != NULL);
2177 assert(exprint != NULL);
2182 (*exprint)->blkmem = blkmem;
2192 assert( exprint != NULL);
2193 assert(*exprint != NULL);
2206 assert(tree != NULL);
2212 assert( data != NULL );
2214 SCIPdebugMessage(
"set interpreter data in tree %p to %p\n", (
void*)tree, (
void*)data);
2218 data->need_retape =
true;
2219 data->int_need_retape =
true;
2228 data->int_X.resize(n);
2229 data->int_x.resize(n);
2230 data->int_Y.resize(1);
2232 if( data->root != NULL )
2241 data->blkmem = exprint->
blkmem;
2261 assert(tree != NULL);
2264 assert(data != NULL);
2266 return data->userevalcapability;
2274 assert( interpreterdata != NULL);
2275 assert(*interpreterdata != NULL);
2277 if( (*interpreterdata)->root != NULL )
2280 delete *interpreterdata;
2281 *interpreterdata = NULL;
2295 assert(exprint != NULL);
2296 assert(tree != NULL);
2301 data->need_retape =
true;
2302 data->int_need_retape =
true;
2318 assert(exprint != NULL);
2319 assert(tree != NULL);
2320 assert(varvals != NULL);
2321 assert(val != NULL);
2324 assert(data != NULL);
2336 if( data->need_retape_always || data->need_retape )
2338 for(
int i = 0; i < n; ++i )
2340 data->X[i] = varvals[i];
2341 data->x[i] = varvals[i];
2344 CppAD::Independent(data->X);
2346 if( data->root != NULL )
2351 data->f.Dependent(data->X, data->Y);
2353 data->val = Value(data->Y[0]);
2359 data->need_retape =
false;
2363 assert((
int)data->x.size() >= n);
2364 for(
int i = 0; i < n; ++i )
2365 data->x[i] = varvals[i];
2367 data->val = data->f.Forward(0, data->x)[0];
2368 SCIPdebugMessage(
"Eval used forward sweep to compute value %g\n", data->val);
2387 assert(exprint != NULL);
2388 assert(tree != NULL);
2389 assert(varvals != NULL);
2390 assert(val != NULL);
2393 assert(data != NULL);
2407 if( data->int_need_retape || data->need_retape_always )
2409 for(
int i = 0; i < n; ++i )
2411 data->int_X[i] = varvals[i];
2412 data->int_x[i] = varvals[i];
2415 CppAD::Independent(data->int_X);
2417 if( data->root != NULL )
2420 data->int_Y[0] = 0.0;
2422 data->int_f.Dependent(data->int_X, data->int_Y);
2424 data->int_val = Value(data->int_Y[0]);
2426 data->int_need_retape =
false;
2430 assert((
int)data->int_x.size() >= n);
2431 for(
int i = 0; i < n; ++i )
2432 data->int_x[i] = varvals[i];
2434 data->int_val = data->int_f.Forward(0, data->int_x)[0];
2437 *val = data->int_val;
2452 assert(exprint != NULL);
2453 assert(tree != NULL);
2454 assert(varvals != NULL || new_varvals ==
FALSE);
2455 assert(val != NULL);
2456 assert(gradient != NULL);
2459 assert(data != NULL);
2473 vector<double> jac(data->f.Jacobian(data->x));
2475 for(
int i = 0; i < n; ++i )
2476 gradient[i] = jac[i];
2500 assert(exprint != NULL);
2501 assert(tree != NULL);
2502 assert(varvals != NULL || new_varvals ==
false);
2503 assert(val != NULL);
2504 assert(gradient != NULL);
2507 assert(data != NULL);
2512 *val = data->int_val;
2519 vector<SCIPInterval> jac(data->int_f.Jacobian(data->int_x));
2521 for (
int i = 0; i < n; ++i)
2522 gradient[i] = jac[i];
2547 assert(exprint != NULL);
2548 assert(tree != NULL);
2549 assert(varvals != NULL);
2550 assert(sparsity != NULL);
2553 assert(data != NULL);
2561 if( data->need_retape_always )
2565 for(
int i = 0; i < nn; ++i )
2578 if( data->need_retape )
2586 vector<bool> r(nn,
false);
2587 for (
int i = 0; i < n; ++i)
2589 (void) data->f.ForSparseJac(n, r);
2593 vector<bool> s(1,
true);
2594 vector<bool> sparsehes(data->f.RevSparseHes(n, s));
2596 for(
int i = 0; i < nn; ++i )
2597 sparsity[i] = sparsehes[i];
2622 assert(exprint != NULL);
2623 assert(tree != NULL);
2624 assert(varvals != NULL || new_varvals ==
FALSE);
2625 assert(val != NULL);
2626 assert(hessian != NULL);
2629 assert(data != NULL);
2645 vector<double> hess(data->f.Hessian(data->x, 0));
2648 for (
int i = 0; i < nn; ++i)
2649 hessian[i] = hess[i];
2653 for(
int i = 0; i < n; ++i )
2654 for(
int j = 0; j < n; ++j )
2656 vector<int> ii(1,i);
2657 vector<int> jj(1,j);
2658 hessian[i*n+j] = data->f.ForTwo(data->x, ii, jj)[0];
void SCIPexprFreeDeep(BMS_BLKMEM *blkmem, SCIP_EXPR **expr)
SCIPInterval square(const SCIPInterval &x)
bool LessThanZero(const SCIPInterval &x)
static void evalMax(Type &resultant, const Type &arg1, const Type &arg2)
const char * SCIPexprintGetName(void)
bool IdenticalEqualPar(const SCIPInterval &x, const SCIPInterval &y)
static SCIP_RETCODE eval(SCIP_EXPR *expr, const vector< Type > &x, SCIP_Real *param, Type &val)
SCIP_RETCODE SCIPexprtreeEvalInt(SCIP_EXPRTREE *tree, SCIP_Real infinity, SCIP_INTERVAL *varvals, SCIP_INTERVAL *val)
#define BMSfreeMemoryArrayNull(ptr)
methods to interpret (evaluate) an expression tree "fast"
int * SCIPexprGetMonomialChildIndices(SCIP_EXPRDATA_MONOMIAL *monomial)
static size_t thread_num(void)
static void evalUser(Type &resultant, const Type *args, SCIP_EXPR *expr)
SCIP_EXPROP SCIPexprGetOperator(SCIP_EXPR *expr)
static void evalSignPower(Type &resultant, const Type &arg, SCIP_EXPR *expr)
SCIPInterval pow(const SCIPInterval &x, const SCIPInterval &y)
SCIP_RETCODE SCIPexprintGradInt(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real infinity, SCIP_INTERVAL *varvals, SCIP_Bool new_varvals, SCIP_INTERVAL *val, SCIP_INTERVAL *gradient)
SCIP_Real * SCIPexprtreeGetParamVals(SCIP_EXPRTREE *tree)
#define SCIP_EXPRINTCAPABILITY_INTGRADIENT
SCIP_Real SCIPexprGetRealPowerExponent(SCIP_EXPR *expr)
int SCIPexprGetOpIndex(SCIP_EXPR *expr)
SCIPInterval cos(const SCIPInterval &x)
SCIP_Real SCIPexprGetPolynomialConstant(SCIP_EXPR *expr)
enum SCIP_Retcode SCIP_RETCODE
SCIP_RETCODE SCIPexprintCompile(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
SCIPInterval exp(const SCIPInterval &x)
const char * SCIPexprintGetDesc(void)
static void evalAbs(Type &resultant, const Type &arg)
#define BMSallocMemoryArray(ptr, num)
static size_t ncurthreads
#define CPPAD_MAX_NUM_THREADS
static void analyzeTree(SCIP_EXPRINTDATA *data, SCIP_EXPR *expr)
SCIP_EXPRINTCAPABILITY SCIPexprintGetExprtreeCapability(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
unsigned int SCIP_EXPRINTCAPABILITY
#define BMSfreeMemory(ptr)
static char init_parallel(void)
static void evalMin(Type &resultant, const Type &arg1, const Type &arg2)
SCIPInterval abs(const SCIPInterval &x)
SCIP_EXPRDATA_MONOMIAL ** SCIPexprGetMonomials(SCIP_EXPR *expr)
public methods for expressions, expression trees, expression graphs, and related stuff ...
int SCIPexprGetMonomialNFactors(SCIP_EXPRDATA_MONOMIAL *monomial)
int SCIPexprGetIntPowerExponent(SCIP_EXPR *expr)
#define SCIP_EXPRINTCAPABILITY_INTFUNCVALUE
SCIPInterval CondExpOp(enum CppAD::CompareOp cop, const SCIPInterval &left, const SCIPInterval &right, const SCIPInterval &trueCase, const SCIPInterval &falseCase)
SCIPInterval signpow(const SCIPInterval &x, const SCIP_Real p)
static bool univariate_for_sparse_jac(size_t q, const CppAD::vector< bool > &r, CppAD::vector< bool > &s)
bool IdenticalOne(const SCIPInterval &x)
SCIP_RETCODE SCIPexprintEval(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Real *val)
SCIP_RETCODE SCIPexprintCreate(BMS_BLKMEM *blkmem, SCIP_EXPRINT **exprint)
SCIP_Real * SCIPexprGetQuadLinearCoefs(SCIP_EXPR *expr)
static void cppaderrorcallback(bool known, int line, const char *file, const char *cond, const char *msg)
SCIP_RETCODE SCIPexprCopyDeep(BMS_BLKMEM *blkmem, SCIP_EXPR **targetexpr, SCIP_EXPR *sourceexpr)
SCIPInterval sqrt(const SCIPInterval &x)
SCIPInterval sign(const SCIPInterval &x)
SCIP_Real SCIPexprGetQuadConstant(SCIP_EXPR *expr)
int SCIPexprtreeGetNVars(SCIP_EXPRTREE *tree)
SCIP_RETCODE SCIPexprEvalUser(SCIP_EXPR *expr, SCIP_Real *argvals, SCIP_Real *val, SCIP_Real *gradient, SCIP_Real *hessian)
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
SCIP_RETCODE exprEvalUser(SCIP_EXPR *expr, Type *x, Type &funcval, Type *gradient, Type *hessian)
SCIP_EXPR * SCIPexprtreeGetRoot(SCIP_EXPRTREE *tree)
static void evalSqrt(Type &resultant, const Type &arg)
SCIP_EXPRINTCAPABILITY SCIPexprGetUserEvalCapability(SCIP_EXPR *expr)
#define SCIP_EXPRINTCAPABILITY_ALL
#define SCIP_EXPRINTCAPABILITY_HESSIAN
SCIP_EXPR ** SCIPexprGetChildren(SCIP_EXPR *expr)
SCIP_Real SCIPexprGetSignPowerExponent(SCIP_EXPR *expr)
bool IdenticalZero(const SCIPInterval &x)
SCIPInterval azmul(const SCIPInterval &x, const SCIPInterval &y)
SCIP_RETCODE SCIPexprintNewParametrization(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
SCIPInterval sin(const SCIPInterval &x)
void SCIPexprSortQuadElems(SCIP_EXPR *expr)
SCIP_RETCODE SCIPexprintEvalInt(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real infinity, SCIP_INTERVAL *varvals, SCIP_INTERVAL *val)
static pthread_mutex_t cppadmutex
SCIP_EXPRINTDATA * SCIPexprtreeGetInterpreterData(SCIP_EXPRTREE *tree)
int SCIPexprGetNChildren(SCIP_EXPR *expr)
static bool univariate_rev_sparse_jac(size_t q, const CppAD::vector< bool > &r, CppAD::vector< bool > &s)
SCIPInterval log(const SCIPInterval &x)
SCIP_RETCODE SCIPexprintHessianDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *hessian)
SCIP_Real SCIPexprGetMonomialCoef(SCIP_EXPRDATA_MONOMIAL *monomial)
static CppAD::ErrorHandler errorhandler(cppaderrorcallback)
SCIP_RETCODE SCIPexprintGrad(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *gradient)
static void evalIntPower(Type &resultant, const Type &arg, const int exponent)
bool GreaterThanZero(const SCIPInterval &x)
SCIP_RETCODE SCIPexprEvalIntUser(SCIP_EXPR *expr, SCIP_Real infinity, SCIP_INTERVAL *argvals, SCIP_INTERVAL *val, SCIP_INTERVAL *gradient, SCIP_INTERVAL *hessian)
bool IdenticalPar(const SCIPInterval &x)
#define SCIP_DEFAULT_INFINITY
#define SCIP_EXPRINTCAPABILITY_FUNCVALUE
SCIP_Real * SCIPexprGetLinearCoefs(SCIP_EXPR *expr)
SCIP_Real SCIPexprGetOpReal(SCIP_EXPR *expr)
SCIP_QUADELEM * SCIPexprGetQuadElements(SCIP_EXPR *expr)
std::ostream & operator<<(std::ostream &out, const SCIP_INTERVAL &x)
int SCIPexprGetNMonomials(SCIP_EXPR *expr)
int Integer(const SCIPInterval &x)
static bool in_parallel(void)
#define BMSallocMemory(ptr)
static pthread_key_t thread_specific_key
SCIP_RETCODE SCIPexprintHessianSparsityDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool *sparsity)
SCIP_Real * SCIPexprGetMonomialExponents(SCIP_EXPRDATA_MONOMIAL *monomial)
bool LessThanOrZero(const SCIPInterval &x)
static bool univariate_rev_sparse_hes(const CppAD::vector< bool > &vx, const CppAD::vector< bool > &s, CppAD::vector< bool > &t, size_t q, const CppAD::vector< bool > &r, const CppAD::vector< bool > &u, CppAD::vector< bool > &v)
SCIP_RETCODE SCIPexprintFreeData(SCIP_EXPRINTDATA **interpreterdata)
SCIP_RETCODE SCIPexprintFree(SCIP_EXPRINT **exprint)
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
SCIP_Real SCIPexprGetLinearConstant(SCIP_EXPR *expr)
void SCIPexprtreeSetInterpreterData(SCIP_EXPRTREE *tree, SCIP_EXPRINTDATA *interpreterdata)
struct SCIP_ExprIntData SCIP_EXPRINTDATA
int SCIPexprGetNQuadElements(SCIP_EXPR *expr)
bool GreaterThanOrZero(const SCIPInterval &x)
#define SCIP_EXPRINTCAPABILITY_GRADIENT
SCIP_RETCODE SCIPexprtreeEval(SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Real *val)
static void posintpower(const vector< Type > &in, vector< Type > &out, size_t exponent)
C++ extensions to interval arithmetics for provable bounds.
memory allocation routines