56 #define SIGN(x) ((x) >= 0.0 ? 1.0 : -1.0) 60 #define SCIPInterval_NAMESPACE CppAD 64 using CppAD::SCIPInterval;
69 #ifndef CPPAD_MAX_NUM_THREADS 71 #define CPPAD_MAX_NUM_THREADS 64 73 #define CPPAD_MAX_NUM_THREADS 1 77 #include <cppad/cppad.hpp> 78 #include <cppad/utility/error_handler.hpp> 89 static pthread_mutex_t
cppadmutex = PTHREAD_MUTEX_INITIALIZER;
119 if( specific ==
NULL )
138 threadnum = (size_t)(specific) - 1;
156 CppAD::parallel_ad<double>();
157 CppAD::parallel_ad<SCIPInterval>();
166 #if !defined(_MSC_VER) 167 __attribute__ ((unused))
176 enum CppAD::CompareOp cop,
177 const SCIPInterval& left,
178 const SCIPInterval& right,
179 const SCIPInterval& trueCase,
180 const SCIPInterval& falseCase)
182 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
183 "SCIPInterval CondExpOp(...)",
184 "Error: cannot use CondExp with an interval type" 187 return SCIPInterval();
193 const SCIPInterval& x
202 const SCIPInterval& x
211 const SCIPInterval& x
220 const SCIPInterval& x,
221 const SCIPInterval& y
230 const SCIPInterval& x
233 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
234 "GreaterThanZero(x)",
235 "Error: cannot use GreaterThanZero with interval" 244 const SCIPInterval& x
247 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__ ,
248 "GreaterThanOrZero(x)",
249 "Error: cannot use GreaterThanOrZero with interval" 258 const SCIPInterval& x
261 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
263 "Error: cannot use LessThanZero with interval" 272 const SCIPInterval& x
275 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
277 "Error: cannot use LessThanOrZero with interval" 286 const SCIPInterval& x
289 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
291 "Error: cannot use Integer with interval" 303 const SCIPInterval& x,
304 const SCIPInterval& y
307 if( x.inf == 0.0 && x.sup == 0.0 )
308 return SCIPInterval(0.0, 0.0);
316 out <<
'[' << x.
inf <<
',' << x.
sup <<
']';
329 struct SCIP_ExprIntData
341 vector< AD<double> > X;
342 vector< AD<double> > Y;
343 CppAD::ADFun<double> f;
349 vector< AD<SCIPInterval> > int_X;
350 vector< AD<SCIPInterval> > int_Y;
351 CppAD::ADFun<SCIPInterval> int_f;
353 vector<SCIPInterval> int_x;
354 SCIPInterval int_val;
355 bool int_need_retape;
357 bool need_retape_always;
364 #ifndef NO_CPPAD_USER_ATOMIC 374 const CppAD::vector<bool>& r,
375 CppAD::vector<bool>& s
378 assert(r.size() == q);
379 assert(s.size() == q);
394 const CppAD::vector<bool>& r,
395 CppAD::vector<bool>& s
398 assert(r.size() == q);
399 assert(s.size() == q);
413 const CppAD::vector<bool>& vx,
414 const CppAD::vector<bool>& s,
415 CppAD::vector<bool>& t,
417 const CppAD::vector<bool>& r,
418 const CppAD::vector<bool>& u,
419 CppAD::vector<bool>& v
422 assert(r.size() == q);
423 assert(s.size() == 1);
424 assert(t.size() == 1);
425 assert(u.size() == q);
426 assert(v.size() == q);
435 for(
size_t j = 0; j < q; ++j )
455 : CppAD::atomic_base<
Type>(
"posintpower"),
459 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
470 virtual void set_id(
size_t id)
490 const CppAD::vector<bool>& vx,
491 CppAD::vector<bool>& vy,
492 const CppAD::vector<Type>& tx,
493 CppAD::vector<Type>& ty
496 assert(exponent > 1);
497 assert(tx.size() >= p+1);
498 assert(ty.size() >= p+1);
503 assert(vx.size() == 1);
504 assert(vy.size() == 1);
515 if( q <= 1 && 1 <= p )
517 ty[1] =
CppAD::pow(tx[0], exponent-1) * tx[1];
518 ty[1] *= double(exponent);
521 if( q <= 2 && 2 <= p )
526 ty[2] =
CppAD::pow(tx[0], exponent-2) * tx[1] * tx[1];
527 ty[2] *= (exponent-1) / 2.0;
528 ty[2] +=
CppAD::pow(tx[0], exponent-1) * tx[2];
533 assert(exponent == 2);
535 ty[2] = tx[1] * tx[1] + 2.0 * tx[0] * tx[2];
578 const CppAD::vector<Type>& tx,
579 const CppAD::vector<Type>& ty,
580 CppAD::vector<Type>& px,
581 const CppAD::vector<Type>& py
584 assert(exponent > 1);
585 assert(px.size() >= p+1);
586 assert(py.size() >= p+1);
587 assert(tx.size() >= p+1);
593 px[0] = py[0] *
CppAD::pow(tx[0], exponent-1);
599 px[0] = py[1] * tx[1] *
CppAD::pow(tx[0], exponent-2);
601 px[0] += py[0] *
CppAD::pow(tx[0], exponent-1);
604 px[1] = py[1] *
CppAD::pow(tx[0], exponent-1);
615 using CppAD::atomic_base<Type>::for_sparse_jac;
624 const CppAD::vector<bool>& r,
625 CppAD::vector<bool>& s
631 using CppAD::atomic_base<Type>::rev_sparse_jac;
640 const CppAD::vector<bool>& r,
641 CppAD::vector<bool>& s
647 using CppAD::atomic_base<Type>::rev_sparse_hes;
655 const CppAD::vector<bool>& vx,
656 const CppAD::vector<bool>& s,
657 CppAD::vector<bool>& t,
659 const CppAD::vector<bool>& r,
660 const CppAD::vector<bool>& u,
661 CppAD::vector<bool>& v
672 const vector<Type>& in,
678 pip(in, out, exponent);
686 const vector<Type>& in,
691 out[0] =
pow(in[0], (
int)exponent);
697 #ifndef NO_CPPAD_USER_ATOMIC 712 : CppAD::atomic_base<
Type>(
"signpower"),
716 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
727 virtual void set_id(
size_t id)
747 const CppAD::vector<bool>& vx,
748 CppAD::vector<bool>& vy,
749 const CppAD::vector<Type>& tx,
750 CppAD::vector<Type>& ty
753 assert(exponent > 0.0);
754 assert(tx.size() >= p+1);
755 assert(ty.size() >= p+1);
760 assert(vx.size() == 1);
761 assert(vy.size() == 1);
772 if( q <= 1 && 1 <= p )
774 ty[1] =
pow(
REALABS(tx[0]), exponent - 1.0) * tx[1];
778 if( q <= 2 && 2 <= p )
780 if( exponent != 2.0 )
782 ty[2] =
SIGN(tx[0]) *
pow(
REALABS(tx[0]), exponent - 2.0) * tx[1] * tx[1];
783 ty[2] *= (exponent - 1.0) / 2.0;
784 ty[2] +=
pow(
REALABS(tx[0]), exponent - 1.0) * tx[2];
790 ty[2] =
SIGN(tx[0]) * tx[1] * tx[1];
791 ty[2] += 2.0 *
REALABS(tx[0]) * tx[2];
834 const CppAD::vector<Type>& tx,
835 const CppAD::vector<Type>& ty,
836 CppAD::vector<Type>& px,
837 const CppAD::vector<Type>& py
840 assert(exponent > 1);
841 assert(px.size() >= p+1);
842 assert(py.size() >= p+1);
843 assert(tx.size() >= p+1);
849 px[0] = py[0] *
pow(
REALABS(tx[0]), exponent - 1.0);
854 if( exponent != 2.0 )
857 px[0] = py[1] * tx[1] *
pow(
REALABS(tx[0]), exponent - 2.0) *
SIGN(tx[0]);
858 px[0] *= exponent - 1.0;
859 px[0] += py[0] *
pow(
REALABS(tx[0]), exponent - 1.0);
862 px[1] = py[1] *
pow(
REALABS(tx[0]), exponent - 1.0);
868 px[0] = py[1] * tx[1] *
SIGN(tx[0]);
869 px[0] += py[0] *
REALABS(tx[0]);
872 px[1] = py[1] *
REALABS(tx[0]);
884 using CppAD::atomic_base<Type>::for_sparse_jac;
893 const CppAD::vector<bool>& r,
894 CppAD::vector<bool>& s
900 using CppAD::atomic_base<Type>::rev_sparse_jac;
909 const CppAD::vector<bool>& r,
910 CppAD::vector<bool>& s
916 using CppAD::atomic_base<Type>::rev_sparse_hes;
924 const CppAD::vector<bool>& vx,
925 const CppAD::vector<bool>& s,
926 CppAD::vector<bool>& t,
928 const CppAD::vector<bool>& r,
929 const CppAD::vector<bool>& u,
930 CppAD::vector<bool>& v
940 class atomic_signpower<SCIPInterval> :
public CppAD::atomic_base<SCIPInterval>
944 : CppAD::atomic_base<SCIPInterval>(
"signpowerint"),
948 this->option(CppAD::atomic_base<SCIPInterval>::bool_sparsity_enum);
959 virtual void set_id(
size_t id)
971 const CppAD::vector<bool>& vx,
972 CppAD::vector<bool>& vy,
973 const CppAD::vector<SCIPInterval>& tx,
974 CppAD::vector<SCIPInterval>& ty
977 assert(exponent > 0.0);
978 assert(tx.size() >= p+1);
979 assert(ty.size() >= p+1);
984 assert(vx.size() == 1);
985 assert(vy.size() == 1);
996 if( q <= 1 && 1 <= p )
1002 if( q <= 2 && 2 <= p )
1004 if( exponent != 2.0 )
1007 ty[2] *= (exponent - 1.0) / 2.0;
1032 const CppAD::vector<SCIPInterval>& tx,
1033 const CppAD::vector<SCIPInterval>& ty,
1034 CppAD::vector<SCIPInterval>& px,
1035 const CppAD::vector<SCIPInterval>& py
1038 assert(exponent > 1);
1039 assert(px.size() >= p+1);
1040 assert(py.size() >= p+1);
1041 assert(tx.size() >= p+1);
1052 if( exponent != 2.0 )
1056 px[0] *= exponent - 1.0;
1082 using CppAD::atomic_base<SCIPInterval>::for_sparse_jac;
1089 bool for_sparse_jac(
1091 const CppAD::vector<bool>& r,
1092 CppAD::vector<bool>& s
1098 using CppAD::atomic_base<SCIPInterval>::rev_sparse_jac;
1105 bool rev_sparse_jac(
1107 const CppAD::vector<bool>& r,
1108 CppAD::vector<bool>& s
1114 using CppAD::atomic_base<SCIPInterval>::rev_sparse_hes;
1121 bool rev_sparse_hes(
1122 const CppAD::vector<bool>& vx,
1123 const CppAD::vector<bool>& s,
1124 CppAD::vector<bool>& t,
1126 const CppAD::vector<bool>& r,
1127 const CppAD::vector<bool>& u,
1128 CppAD::vector<bool>& v
1136 template<
class Type>
1144 vector<Type> in(1, arg);
1145 vector<Type> out(1);
1148 sp(in, out, (
size_t)(
void*)expr);
1160 template<
class Type>
1168 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1170 "Error: SignPower not implemented for this value type" 1177 CppAD::AD<double>& resultant,
1178 const CppAD::AD<double>& arg,
1188 else if( arg > 0.0 )
1189 resultant =
pow( arg, exponent);
1191 resultant = -
pow(-arg, exponent);
1197 #ifndef NO_CPPAD_USER_ATOMIC 1199 template<
class Type>
1215 SCIPInterval& funcval,
1216 SCIPInterval* gradient,
1217 SCIPInterval* hessian
1227 template<
class Type>
1232 : CppAD::atomic_base<
Type>(
"userexpr"),
1236 this->option(CppAD::atomic_base<Type>::bool_sparsity_enum);
1247 virtual void set_id(
size_t id)
1277 const CppAD::vector<bool>& vx,
1278 CppAD::vector<bool>& vy,
1279 const CppAD::vector<Type>& tx,
1280 CppAD::vector<Type>& ty
1283 assert(expr !=
NULL);
1284 assert(ty.size() == p+1);
1287 size_t n = tx.size() / (p+1);
1293 assert(vx.size() == n);
1294 assert(vy.size() == 1);
1299 for(
size_t i = 0; i < n; ++i )
1311 if( q <= 2 && 1 <= p )
1312 gradient =
new Type[n];
1313 if( q <= 2 && 2 <= p )
1314 hessian =
new Type[n*n];
1316 for(
size_t i = 0; i < n; ++i )
1317 x[i] = tx[i * (p+1) + 0];
1327 if( gradient !=
NULL )
1330 for(
size_t i = 0; i < n; ++i )
1331 ty[1] += gradient[i] * tx[i * (p+1) + 1];
1334 if( hessian !=
NULL )
1336 assert(gradient !=
NULL);
1339 for(
size_t i = 0; i < n; ++i )
1341 for(
size_t j = 0; j < n; ++j )
1342 ty[2] += 0.5 * hessian[i*n+j] * tx[i * (p+1) + 1] * tx[j * (p+1) + 1];
1344 ty[2] += gradient[i] * tx[i * (p+1) + 2];
1417 const CppAD::vector<Type>& tx,
1418 const CppAD::vector<Type>& ty,
1419 CppAD::vector<Type>& px,
1420 const CppAD::vector<Type>& py
1423 assert(expr !=
NULL);
1424 assert(px.size() == tx.size());
1425 assert(py.size() == p+1);
1427 size_t n = tx.size() / (p+1);
1437 hessian =
new Type[n*n];
1439 for(
size_t i = 0; i < n; ++i )
1440 x[i] = tx[i * (p+1) + 0];
1454 for(
size_t i = 0; i < n; ++i )
1455 px[i] = py[0] * gradient[i];
1461 assert(hessian !=
NULL);
1462 for(
size_t i = 0; i < n; ++i )
1464 px[i*2+0] = py[0] * gradient[i];
1465 for(
size_t j = 0; j < n; ++j )
1466 px[i*2+0] += py[1] * hessian[i+n*j] * tx[j*2+1];
1468 px[i*2+1] = py[1] * gradient[i];
1479 using CppAD::atomic_base<Type>::for_sparse_jac;
1485 bool for_sparse_jac(
1487 const CppAD::vector<bool>& r,
1488 CppAD::vector<bool>& s
1491 assert(expr !=
NULL);
1492 assert(s.size() == q);
1494 size_t n = r.size() / q;
1498 for(
size_t j = 0; j < q; j++ )
1501 for(
size_t i = 0; i < n; i++ )
1502 s[j] |= (
bool)r[i * q + j];
1508 using CppAD::atomic_base<Type>::rev_sparse_jac;
1514 bool rev_sparse_jac(
1516 const CppAD::vector<bool>& rt,
1517 CppAD::vector<bool>& st
1520 assert(expr !=
NULL);
1521 assert(rt.size() == q);
1523 size_t n = st.size() / q;
1527 for(
size_t j = 0; j < q; j++ )
1528 for(
size_t i = 0; i < n; i++ )
1529 st[i * q + j] = rt[j];
1534 using CppAD::atomic_base<Type>::rev_sparse_hes;
1540 bool rev_sparse_hes(
1541 const CppAD::vector<bool>& vx,
1542 const CppAD::vector<bool>& s,
1543 CppAD::vector<bool>& t,
1545 const CppAD::vector<bool>& r,
1546 const CppAD::vector<bool>& u,
1547 CppAD::vector<bool>& v
1550 assert(expr !=
NULL);
1551 size_t n = vx.size();
1553 assert(s.size() == 1);
1554 assert(t.size() == n);
1555 assert(r.size() == n * q);
1556 assert(u.size() == q);
1557 assert(v.size() == n * q);
1562 for( i = 0; i < n; ++i )
1570 for( j = 0; j < q; j++ )
1571 for( i = 0; i < n; i++ )
1572 v[ i * q + j] = u[j];
1577 for( j = 0; j < q; j++ )
1578 for( i = 0; i < n; i++ )
1579 for( k = 0; k < n; ++k )
1580 v[ i * q + j] |= (
bool) r[ k * q + j];
1587 template<
class Type>
1595 assert( args != 0 );
1597 vector<Type> out(1);
1600 u(in, out, (
size_t)(
void*)expr);
1608 template<
class Type>
1616 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1618 "Error: user expressions in CppAD not possible without CppAD user atomic facility" 1629 template<
class Type>
1637 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1639 "Error: Min not implemented for this value type" 1646 CppAD::AD<double>& resultant,
1647 const CppAD::AD<double>& arg1,
1648 const CppAD::AD<double>& arg2
1651 resultant =
MIN(arg1, arg2);
1659 template<
class Type>
1667 CppAD::ErrorHandler::Call(
true, __LINE__, __FILE__,
1669 "Error: Max not implemented for this value type" 1676 CppAD::AD<double>& resultant,
1677 const CppAD::AD<double>& arg1,
1678 const CppAD::AD<double>& arg2
1681 resultant =
MAX(arg1, arg2);
1688 template<
class Type>
1695 resultant =
sqrt(arg);
1699 template<
class Type>
1706 resultant =
abs(arg);
1715 CppAD::AD<SCIPInterval>& resultant,
1716 const CppAD::AD<SCIPInterval>& arg
1719 vector<CppAD::AD<SCIPInterval> > in(1, arg);
1720 vector<CppAD::AD<SCIPInterval> > out(1);
1724 resultant =
sqrt(out[0]);
1728 template<
class Type>
1738 vector<Type> in(1, arg);
1739 vector<Type> out(1);
1749 vector<Type> in(1, arg);
1750 vector<Type> out(1);
1754 resultant =
Type(1.0)/out[0];
1766 resultant =
Type(1.0);
1770 assert(exponent == -1);
1771 resultant =
Type(1.0)/arg;
1775 template<
class Type>
1779 const vector<Type>& x,
1786 assert(expr !=
NULL);
1813 assert(param !=
NULL);
1819 val = buf[0] + buf[1];
1824 val = buf[0] - buf[1];
1829 val = buf[0] * buf[1];
1834 val = buf[0] / buf[1];
1886 #ifdef SCIP_DISABLED_CODE 1892 case SCIP_EXPR_ERFI:
1939 val += coefs[i] * buf[i];
1951 vector<Type> out(1);
1958 assert(quadelems !=
NULL || nquadelems == 0);
1969 if( i == nquadelems || quadelems[i].idx1 > argidx )
1972 if( lincoefs !=
NULL )
1973 val += lincoefs[argidx] * buf[argidx];
1978 lincoef = lincoefs !=
NULL ? lincoefs[argidx] : 0.0;
1980 assert(i < nquadelems && quadelems[i].idx1 == argidx);
1983 if( quadelems[i].idx2 == argidx )
1984 sqrcoef += quadelems[i].
coef;
1986 lincoef += quadelems[i].
coef * buf[quadelems[i].
idx2];
1988 }
while( i < nquadelems && quadelems[i].idx1 == argidx );
1989 assert(i == nquadelems || quadelems[i].idx1 > argidx);
1992 if( sqrcoef != 0.0 )
1994 in[0] = buf[argidx];
1996 val += sqrcoef * out[0];
1999 val += lincoef * buf[argidx];
2001 assert(i == nquadelems);
2026 for( i = 0; i < nmonomials; ++i )
2033 for( j = 0; j < nfactors; ++j )
2035 assert(childidxs[j] >= 0);
2038 childval = buf[childidxs[j]];
2039 exponent = exponents[j];
2042 if( exponent == 0.0 )
2044 if( exponent == 1.0 )
2046 monomialval *= childval;
2049 if( (
int)exponent == exponent )
2056 if( exponent == 0.5 )
2063 monomialval *=
pow(childval, exponent);
2097 assert(expr !=
NULL);
2108 #ifdef NO_CPPAD_USER_ATOMIC 2111 data->need_retape_always =
true;
2139 SCIPdebugMessage(
"ignore CppAD error from %sknown source %s:%d: msg: %s exp: %s\n", known ?
"" :
"un", file, line, msg, cond);
2148 return CPPAD_PACKAGE_STRING;
2154 return "Algorithmic Differentiation of C++ algorithms developed by B. Bell (www.coin-or.org/CppAD)";
2173 assert(blkmem !=
NULL);
2174 assert(exprint !=
NULL);
2179 (*exprint)->blkmem =
blkmem;
2189 assert( exprint !=
NULL);
2190 assert(*exprint !=
NULL);
2203 assert(tree !=
NULL);
2209 assert( data !=
NULL );
2211 SCIPdebugMessage(
"set interpreter data in tree %p to %p\n", (
void*)tree, (
void*)data);
2215 data->need_retape =
true;
2216 data->int_need_retape =
true;
2225 data->int_X.resize(n);
2226 data->int_x.resize(n);
2227 data->int_Y.resize(1);
2229 if( data->root !=
NULL )
2238 data->blkmem = exprint->
blkmem;
2258 assert(tree !=
NULL);
2261 assert(data !=
NULL);
2263 return data->userevalcapability;
2271 assert( interpreterdata !=
NULL);
2272 assert(*interpreterdata !=
NULL);
2274 if( (*interpreterdata)->root !=
NULL )
2277 delete *interpreterdata;
2278 *interpreterdata =
NULL;
2292 assert(exprint !=
NULL);
2293 assert(tree !=
NULL);
2298 data->need_retape =
true;
2299 data->int_need_retape =
true;
2315 assert(exprint !=
NULL);
2316 assert(tree !=
NULL);
2317 assert(varvals !=
NULL);
2318 assert(val !=
NULL);
2321 assert(data !=
NULL);
2333 if( data->need_retape_always || data->need_retape )
2335 for(
int i = 0; i < n; ++i )
2337 data->X[i] = varvals[i];
2338 data->x[i] = varvals[i];
2341 CppAD::Independent(data->X);
2343 if( data->root !=
NULL )
2348 data->f.Dependent(data->X, data->Y);
2350 data->val = Value(data->Y[0]);
2356 data->need_retape =
false;
2360 assert((
int)data->x.size() >= n);
2361 for(
int i = 0; i < n; ++i )
2362 data->x[i] = varvals[i];
2364 data->val = data->f.Forward(0, data->x)[0];
2365 SCIPdebugMessage(
"Eval used forward sweep to compute value %g\n", data->val);
2384 assert(exprint !=
NULL);
2385 assert(tree !=
NULL);
2386 assert(varvals !=
NULL);
2387 assert(val !=
NULL);
2390 assert(data !=
NULL);
2404 if( data->int_need_retape || data->need_retape_always )
2406 for(
int i = 0; i < n; ++i )
2408 data->int_X[i] = varvals[i];
2409 data->int_x[i] = varvals[i];
2412 CppAD::Independent(data->int_X);
2414 if( data->root !=
NULL )
2417 data->int_Y[0] = 0.0;
2419 data->int_f.Dependent(data->int_X, data->int_Y);
2421 data->int_val = Value(data->int_Y[0]);
2423 data->int_need_retape =
false;
2427 assert((
int)data->int_x.size() >= n);
2428 for(
int i = 0; i < n; ++i )
2429 data->int_x[i] = varvals[i];
2431 data->int_val = data->int_f.Forward(0, data->int_x)[0];
2434 *val = data->int_val;
2449 assert(exprint !=
NULL);
2450 assert(tree !=
NULL);
2451 assert(varvals !=
NULL || new_varvals ==
FALSE);
2452 assert(val !=
NULL);
2453 assert(gradient !=
NULL);
2456 assert(data !=
NULL);
2470 vector<double> jac(data->f.Jacobian(data->x));
2472 for(
int i = 0; i < n; ++i )
2473 gradient[i] = jac[i];
2497 assert(exprint !=
NULL);
2498 assert(tree !=
NULL);
2499 assert(varvals !=
NULL || new_varvals ==
false);
2500 assert(val !=
NULL);
2501 assert(gradient !=
NULL);
2504 assert(data !=
NULL);
2509 *val = data->int_val;
2516 vector<SCIPInterval> jac(data->int_f.Jacobian(data->int_x));
2518 for (
int i = 0; i < n; ++i)
2519 gradient[i] = jac[i];
2544 assert(exprint !=
NULL);
2545 assert(tree !=
NULL);
2546 assert(varvals !=
NULL);
2547 assert(sparsity !=
NULL);
2550 assert(data !=
NULL);
2558 if( data->need_retape_always )
2562 for(
int i = 0; i < nn; ++i )
2575 if( data->need_retape )
2583 vector<bool> r(nn,
false);
2584 for (
int i = 0; i < n; ++i)
2586 (void) data->f.ForSparseJac(n, r);
2590 vector<bool> s(1,
true);
2591 vector<bool> sparsehes(data->f.RevSparseHes(n, s));
2593 for(
int i = 0; i < nn; ++i )
2594 sparsity[i] = sparsehes[i];
2619 assert(exprint !=
NULL);
2620 assert(tree !=
NULL);
2621 assert(varvals !=
NULL || new_varvals ==
FALSE);
2622 assert(val !=
NULL);
2623 assert(hessian !=
NULL);
2626 assert(data !=
NULL);
2642 vector<double> hess(data->f.Hessian(data->x, 0));
2645 for (
int i = 0; i < nn; ++i)
2646 hessian[i] = hess[i];
2650 for(
int i = 0; i < n; ++i )
2651 for(
int j = 0; j < n; ++j )
2653 vector<int> ii(1,i);
2654 vector<int> jj(1,j);
2655 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