12 #include "CoinHelperFunctions.hpp"
13 #include "OsiSolverInterface.hpp"
14 #include "IpLapack.hpp"
19 using namespace Couenne;
54 *indexmap =
new int [p -> nVars ()],
55 *indices =
new int [nDiag];
58 CoinFillN (indexmap, p -> nVars (), -1);
61 double *diam =
new double [nDiag];
63 bool changed_bounds =
false;
65 for (std::map <
exprVar *, std::pair <CouNumber, CouNumber> >::iterator i =
bounds_.begin ();
66 i !=
bounds_.end (); ++i, k++) {
69 printf (
"b%04d. [%20g, %20g]\n", i->first->Index(), i->second.first, i->second.second);
72 int index = i -> first ->
Index ();
77 lb = i -> first -> lb (),
78 ub = i -> first -> ub ();
89 printf (
"unbounded, bailing out\n");
96 if (fabs (lb - i->second.first) >
COUENNE_EPS) {i -> second.first = lb; changed_bounds =
true;}
97 if (fabs (ub - i->second.second) >
COUENNE_EPS) {i -> second.second = ub; changed_bounds =
true;}
101 printf (
"diam %4d - %4d = %g - %g = %g\n", index, k, ub, lb, diam [k]);
105 if (!changed_bounds) {
116 double *matrix =
new double [nDiag * nDiag];
118 CoinFillN (matrix, nDiag * nDiag, 0.);
120 for (sparseQ::iterator row =
matrix_.begin (); row !=
matrix_.end (); ++row) {
123 xind = row -> first ->
Index (),
124 irow = indexmap [xind];
126 for (sparseQcol::iterator col = row -> second.begin (); col != row -> second.end (); ++col) {
129 yind = col -> first ->
Index (),
130 icol = indexmap [yind];
132 double cell = col -> second * diam [
irow] * diam [icol];
134 matrix [icol * nDiag +
irow] = cell;
136 matrix [
irow * nDiag + icol] = cell;
148 double* eigval =
new double [nDiag];
152 printf (
"nDiag = %d\n", nDiag);
153 for (
int i=0; i<nDiag; i++) {
154 for (
int j=0;
j<nDiag;
j++)
155 printf (
"%6.2f ", matrix [i*nDiag +
j]);
160 Ipopt::IpLapackDsyev (
true,
168 printf (
"exprQuad::alphaConvexify, warning: problem computing eigenvalue, info=%d\n", info);
176 for (
int i=0; i<nDiag; i++) {
178 std::pair <CouNumber, std::vector <std::pair <exprVar *, CouNumber> > > eigenCoord;
180 eigenCoord. first = eigval [i];
182 for (
int j=0;
j<nDiag;
j++) {
187 eigenCoord. second. push_back (std::pair <exprVar *, CouNumber>
188 (p -> Var (indices [
j]), elem));
191 eigen_.push_back (eigenCoord);
196 std::vector <std::pair <exprVar *, CouNumber> > > >::iterator i =
eigen_.begin ();
197 i !=
eigen_.end (); ++i) {
198 printf (
" [%g] -- ", i -> first);
199 for (std::vector <std::pair <exprVar *, CouNumber> >::iterator
j = i -> second. begin();
200 j != i -> second.
end (); ++
j)
201 printf (
"(%d,%g) ",
j -> first ->
Index (),
j -> second);
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
virtual int Index() const
Return index of variable (only valid for exprVar and exprAux)
Class for MINLP problems with symbolic information.
std::vector< std::pair< CouNumber, std::vector< std::pair< exprVar *, CouNumber > > > > eigen_
eigenvalues and eigenvectors
std::map< exprVar *, std::pair< CouNumber, CouNumber > > bounds_
current bounds (checked before re-computing eigenvalues/vectors)
double CouNumber
main number type in Couenne
virtual bool alphaConvexify(const CouenneProblem *)
Compute data for -convexification of a quadratic form (fills in dCoeff_ and dIndex_ for the convex un...