| 1 |
// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006 |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// Pierre Bonami, Carnegie Mellon University, |
| 7 |
// Andreas Waechter, International Business Machines Corporation |
| 8 |
// |
| 9 |
// Date : 02/15/2006 |
| 10 |
|
| 11 |
#include "BonIpoptWarmStart.hpp" |
| 12 |
#include "CoinHelperFunctions.hpp" |
| 13 |
|
| 14 |
#include "BonTMINLP2TNLP.hpp" |
| 15 |
#include "BonIpoptInteriorWarmStarter.hpp" |
| 16 |
|
| 17 |
using namespace Ipopt; |
| 18 |
|
| 19 |
namespace Bonmin |
| 20 |
{ |
| 21 |
/// Default constructor |
| 22 |
IpoptWarmStart::IpoptWarmStart |
| 23 |
(bool empty, int numvars, int numcont): |
| 24 |
CoinWarmStartPrimalDual(), |
| 25 |
CoinWarmStartBasis(), |
| 26 |
warm_starter_(NULL), |
| 27 |
empty_(empty) |
| 28 |
{ |
| 29 |
setSize(numvars,numcont); |
| 30 |
} |
| 31 |
/// Usefull constructor |
| 32 |
IpoptWarmStart::IpoptWarmStart(const Ipopt::SmartPtr<TMINLP2TNLP> tnlp, |
| 33 |
SmartPtr<IpoptInteriorWarmStarter> warm_starter): |
| 34 |
CoinWarmStartPrimalDual(tnlp->num_variables(), |
| 35 |
2*tnlp->num_variables()+tnlp->num_constraints(), |
| 36 |
tnlp->x_sol(), tnlp->duals_sol() ), |
| 37 |
CoinWarmStartBasis(), |
| 38 |
warm_starter_(warm_starter), |
| 39 |
empty_(false) |
| 40 |
{ |
| 41 |
int numcols = tnlp->num_variables(); |
| 42 |
int numrows = tnlp->num_constraints(); |
| 43 |
// initialize the size in the CoinWarmStartBasis part |
| 44 |
setSize(numcols,numrows); |
| 45 |
} |
| 46 |
|
| 47 |
/// Another usefull constructor, stores the passed point |
| 48 |
IpoptWarmStart::IpoptWarmStart(int primal_size, int dual_size, |
| 49 |
const double * primal, const double * dual): |
| 50 |
CoinWarmStartPrimalDual(primal_size, dual_size, primal, dual), |
| 51 |
CoinWarmStartBasis(), |
| 52 |
warm_starter_(NULL), |
| 53 |
empty_(false) |
| 54 |
{ |
| 55 |
setSize(primal_size, dual_size - 2* primal_size); |
| 56 |
} |
| 57 |
/// Copy constructor |
| 58 |
IpoptWarmStart::IpoptWarmStart( const IpoptWarmStart &other, bool ownValues): |
| 59 |
CoinWarmStartPrimalDual(other), |
| 60 |
CoinWarmStartBasis(other), |
| 61 |
warm_starter_(NULL /*other.warm_starter_*/), |
| 62 |
empty_(other.empty_) |
| 63 |
{ |
| 64 |
// if(ownValues_ && other.values_ != NULL) |
| 65 |
} |
| 66 |
|
| 67 |
/// A constructor from a CoinWarmStartPrimalDual |
| 68 |
IpoptWarmStart::IpoptWarmStart(const CoinWarmStartPrimalDual& pdws) : |
| 69 |
CoinWarmStartPrimalDual(pdws), |
| 70 |
CoinWarmStartBasis(), |
| 71 |
warm_starter_(NULL), |
| 72 |
empty_(false) |
| 73 |
{ |
| 74 |
} |
| 75 |
|
| 76 |
CoinWarmStartDiff* |
| 77 |
IpoptWarmStart::generateDiff(const CoinWarmStart *const oldCWS) const |
| 78 |
{ |
| 79 |
const IpoptWarmStart * const ws = |
| 80 |
dynamic_cast< const IpoptWarmStart * const > (oldCWS); |
| 81 |
DBG_ASSERT(ws); |
| 82 |
|
| 83 |
CoinWarmStartDiff * diff = CoinWarmStartPrimalDual::generateDiff(ws); |
| 84 |
|
| 85 |
CoinWarmStartPrimalDualDiff * pdDiff = |
| 86 |
dynamic_cast<CoinWarmStartPrimalDualDiff*>(diff); |
| 87 |
|
| 88 |
CoinWarmStartDiff* retval = |
| 89 |
new IpoptWarmStartDiff(pdDiff, NULL);//warm_starter_); |
| 90 |
delete diff; |
| 91 |
|
| 92 |
return retval; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
void |
| 97 |
IpoptWarmStart::applyDiff (const CoinWarmStartDiff *const cwsdDiff) |
| 98 |
{ |
| 99 |
IpoptWarmStartDiff const * const ipoptDiff = |
| 100 |
dynamic_cast<IpoptWarmStartDiff const * const > (cwsdDiff); |
| 101 |
DBG_ASSERT(ipoptDiff); |
| 102 |
CoinWarmStartPrimalDual::applyDiff(ipoptDiff); |
| 103 |
warm_starter_ = ipoptDiff->warm_starter(); |
| 104 |
} |
| 105 |
|
| 106 |
IpoptWarmStart::~IpoptWarmStart() |
| 107 |
{} |
| 108 |
|
| 109 |
void |
| 110 |
IpoptWarmStart::flushPoint() |
| 111 |
{ |
| 112 |
CoinWarmStartPrimalDual::clear(); |
| 113 |
} |
| 114 |
|
| 115 |
void |
| 116 |
IpoptWarmStartDiff::flushPoint() |
| 117 |
{ |
| 118 |
CoinWarmStartPrimalDualDiff::clear(); |
| 119 |
} |
| 120 |
} |