10 #include "CoinHelperFunctions.hpp"
17 using namespace Couenne;
52 lamI_ = (
int **) malloc (
nnz_ *
sizeof (
int *));
55 for (
int i=0; i<
nnz_; i++) {
81 for (
int i=0; i<
nnz_; i++) {
103 std::set <int> &globList);
121 printf (
"creating Hessian\n");
128 std::set <int> *deplist =
new std::set <int> [1 + p -> nVars () + p -> nCons ()];
137 p -> Obj (0) -> Body () -> DepList (deplist [nLevels++],
STOP_AT_AUX);
141 for (
int i = 0; i < p -> nCons (); i++) {
157 for (
int i = 0; i < p -> nVars (); i++) {
161 if ((e -> Type () !=
AUX) ||
162 (e -> Multiplicity () <= 0))
165 e -> Image () -> DepList (deplist [nLevels++],
STOP_AT_AUX);
169 for (
int i=0; i<nLevels; i++) {
170 printf (
"level %d: ", i);
171 for (std::set <int>::iterator
j = deplist [i]. begin () ;
j != deplist [i].end (); ++
j)
186 nVars = p -> nVars (),
190 for (
int i=0; i < nVars; i++) {
192 if (p -> Var (i) -> Multiplicity () <= 0)
196 int *rnz = (
int *) malloc (nVars *
sizeof (
int));
197 int **
lam = (
int **) malloc (nVars *
sizeof (
int *));
200 std::set <int> globDepList;
202 CoinFillN (rnz, nVars, 0);
205 for (
int j=nVars;
j--;) {
217 HessElemFill (i, 0, deplist [0], p -> Obj (0) -> Body (), rnz, lam, eee, p, globDepList);
221 for (
int j = 0;
j < p -> nCons ();
j++) {
224 enum nodeType ctype = c -> Body () -> Type ();
230 HessElemFill (i, level, deplist [level], c -> Body (), rnz, lam, eee, p, globDepList);
237 for (
int j = 0;
j < p -> nVars ();
j++) {
241 if ((e -> Type () !=
AUX) ||
242 (e -> Multiplicity () <= 0))
245 HessElemFill (i, level, deplist [level], e -> Image (), rnz, lam, eee, p, globDepList);
252 for (std::set <int>::iterator
j = globDepList.begin ();
j != globDepList.
end (); ++
j) {
262 lamI_ [
nnz_] = (
int *) realloc (lam [*j], rnz [*j] *
sizeof (
int));
276 printf (
"hessian: %d nonzeros\n",
nnz_);
278 for (
int i=0; i<
nnz_; i++) {
280 printf (
"[%d,%d]: %d lambdas: ",
286 printf (
"(%d,",
lamI_ [i][
j]);
298 #define reallocStep 100
304 std::set <int> &list,
310 std::set <int> &globList) {
312 if (list. find (i) == list.end () ||
313 (expr -> Linearity () <=
LINEAR))
319 *
d1 = expr -> differentiate (i),
320 *sd1 = d1 -> simplify (),
321 *rd1 = (sd1 ? sd1 :
d1);
325 for (std::set <int>::iterator
k = list.begin ();
k != list.
end (); ++
k) {
333 *d2 = rd1 -> differentiate (*
k),
334 *sd2 = d2 -> simplify (),
335 *rd2 = (sd2 ? sd2 : d2);
338 printf (
" rd2 [x_%d, x_%d]: d/d x_%d = ", *
k, i, *
k); fflush (stdout);
339 rd1 -> print (); printf (
" -> d/(d x_%d,d x_%d) = ", *
k, i);
340 rd2 -> print (); printf (
"\n");
345 if ((rd2 -> Type () !=
CONST) ||
346 (rd2 -> Value () != 0.)) {
350 int &curNNZ = nnz [*
k];
353 globList.find (*
k) == globList.
end ())
354 globList.insert (*
k);
358 lam [*
k] = (
int *) realloc (lam [*
k], (curNNZ + reallocStep) *
sizeof (
int));
364 lam [*
k] [curNNZ] = level;
365 eee [*
k] [curNNZ++] = rd2;
380 r = (
int *) realloc (r, nMax *
sizeof (
int));
381 c = (
int *) realloc (c, nMax *
sizeof (
int));
382 n = (
int *) realloc (n, nMax *
sizeof (
int));
383 l = (
int **) realloc (l, nMax *
sizeof (
int *));
int * numL_
There are m+1 (m constraints + 1 obj) components:
static void reAlloc(int nCur, int &nMax, int *&r, int *&c, int *&n, int **&l, expression ***&e)
code for refilling arrays through realloc
ExprHess()
empty constructor
expression *** expr_
list of lists of pointers to expression
void fint fint fint real fint real real real real real real real real real * e
Class to represent nonlinear constraints.
Class for MINLP problems with symbolic information.
void fint fint fint real fint real real real real real real real * r
ExprHess * clone()
Cloning operator.
int nnz_
number of (symbolic) nonzeroes
int ** lamI_
vector of indices in the lambda vector whose constraint has nonzero entry in this position of the hes...
nodeType
type of a node in an expression tree
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real * lam
void HessElemFill(int i, int level, std::set< int > &list, expression *expr, int *row, int **lam, expression ***eee, CouenneProblem *, std::set< int > &globList)
code for refilling jacobian
int nnz
ATTENTION: Filter expect the jacobian to be ordered by row.
int * iRow_
row indices (read this way by eval_h)
ExprHess & operator=(const ExprHess &)
code for refilling jacobian