Changeset 3507 for trunk/test_more
 Timestamp:
 Dec 27, 2014 11:30:12 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r3504 r3507 1594 1594 // f(x) = x[0] + x[0] if x[0] >= 3 1595 1595 // = x[0] + x[1] otherwise 1596 vector< AD<double> > ax(2), ay( 2);1596 vector< AD<double> > ax(2), ay(3); 1597 1597 ax[0] = 1.0; 1598 1598 ax[1] = 2.0; … … 1600 1600 AD<double> three(3); 1601 1601 AD<double> value = ax[0] + ax[1]; 1602 // a simple value 1602 1603 ay[0] = CppAD::CondExpGe(ax[0], three, value, value); 1603 ay[1] = CppAD::CondExpGe(ax[0], three, ax[0]+ax[1], ax[0]+ax[1]); 1604 // a binary exprpression 1605 ay[1] = CppAD::CondExpGe(ax[0], three, ax[0]ax[1], ax[0]ax[1]); 1606 // a unary expression 1607 ay[2] = CppAD::CondExpGe(ax[0], three, exp(ax[0]), exp(ax[0]) ); 1604 1608 CppAD::ADFun<double> f(ax, ay); 1605 1609 f.optimize(); 1606 1610 1607 1611 // check case where x[0] >= 3 1608 vector<double> x(2), y( 2);1612 vector<double> x(2), y(3); 1609 1613 x[0] = 4.0; 1610 1614 x[1] = 2.0; 1611 1615 y = f.Forward(0, x); 1612 1616 ok &= y[0] == x[0] + x[1]; 1613 ok &= y[1] == x[0] + x[1]; 1617 ok &= y[1] == x[0]  x[1]; 1618 ok &= y[2] == exp(x[0]); 1614 1619 1615 1620 // check case where x[0] < 3 … … 1618 1623 y = f.Forward(0, x); 1619 1624 ok &= y[0] == x[0] + x[1]; 1620 ok &= y[1] == x[0] + x[1]; 1625 ok &= y[1] == x[0]  x[1]; 1626 ok &= y[2] == exp(x[0]); 1621 1627 1622 1628 return ok;
Note: See TracChangeset
for help on using the changeset viewer.