103 size = (int)(1.2 * size + 4);
115 assert(oracle !=
NULL);
122 assert(newsize >= minsize);
134 assert(oracle->
varssize >= minsize);
146 assert(oracle !=
NULL);
153 assert(newsize >= minsize);
171 assert(blkmem !=
NULL);
172 assert(cons !=
NULL);
179 assert(newsize >= minsize);
185 assert(cons->
linsize >= minsize);
198 assert(blkmem !=
NULL);
199 assert(cons !=
NULL);
206 assert(newsize >= minsize);
225 assert(blkmem !=
NULL);
226 assert(intarray !=
NULL);
234 assert(newsize >= minsize);
239 assert(*len >= minsize);
252 assert(oracle !=
NULL);
256 if( oracle->jacoffsets ==
NULL )
258 assert(oracle->jaccols ==
NULL);
262 assert(oracle->jaccols !=
NULL);
275 assert(oracle !=
NULL);
279 if( oracle->heslagoffsets ==
NULL )
281 assert(oracle->heslagcols ==
NULL);
285 assert(oracle->heslagcols !=
NULL);
301 assert(nidxs !=
NULL);
302 assert(idxs !=
NULL || *nidxs == 0);
303 assert(coefs !=
NULL || *nidxs == 0);
312 while( j+offset < *nidxs )
314 assert(idxs[j] >= 0);
319 idxs[j] = idxs[j+offset];
320 coefs[j] = coefs[j+offset];
324 while( j+offset+1 < *nidxs && idxs[j] == idxs[j+offset+1] )
326 coefs[j] += coefs[j+offset+1];
331 if( coefs[j] == 0.0 )
356 assert(blkmem !=
NULL);
357 assert(cons !=
NULL);
358 assert(nlinidxs >= 0);
359 assert(linidxs !=
NULL || nlinidxs == 0);
360 assert(lincoefs !=
NULL || nlinidxs == 0);
361 assert(nquadelems >= 0);
362 assert(quadelems !=
NULL || nquadelems == 0);
363 assert(exprvaridxs !=
NULL || exprtree ==
NULL);
367 assert(*cons !=
NULL);
379 assert((*cons)->linidxs[0] >= 0);
391 assert((*cons)->nquadelems == 0 || (*cons)->quadelems[0].idx1 >= 0);
392 assert((*cons)->nquadelems == 0 || (*cons)->quadelems[0].idx2 >= 0);
395 if( exprtree !=
NULL )
425 assert(blkmem !=
NULL);
426 assert(cons !=
NULL);
427 assert(*cons !=
NULL);
436 if( (*cons)->exprtree !=
NULL )
442 if( (*cons)->name !=
NULL )
448 assert(*cons ==
NULL);
459 assert(oracle !=
NULL);
463 for( i = 0; i < oracle->nconss; ++i )
466 assert(oracle->conss[i] ==
NULL);
471 oracle->consssize = 0;
485 assert(oracle !=
NULL);
489 assert(0 <= fromidx);
491 assert(fromidx < oracle->nvars);
492 assert(toidx < oracle->nvars);
494 assert(oracle->varlbs[toidx] <= -oracle->infinity);
495 assert(oracle->varubs[toidx] >= oracle->infinity);
496 assert(oracle->varnames ==
NULL || oracle->varnames[toidx] ==
NULL);
497 assert(!oracle->vardegreesuptodate || oracle->vardegrees[toidx] == -1);
499 oracle->varlbs[toidx] = oracle->varlbs[fromidx];
500 oracle->varubs[toidx] = oracle->varubs[fromidx];
502 oracle->varlbs[fromidx] = -oracle->infinity;
503 oracle->varubs[fromidx] = oracle->infinity;
505 oracle->vardegrees[toidx] = oracle->vardegrees[fromidx];
506 oracle->vardegrees[fromidx] = -1;
508 if( oracle->varnames !=
NULL )
510 oracle->varnames[toidx] = oracle->varnames[fromidx];
511 oracle->varnames[fromidx] =
NULL;
525 assert(oracle !=
NULL);
529 if( oracle->varnames !=
NULL )
531 for( i = 0; i < oracle->nvars; ++i )
533 if( oracle->varnames[i] !=
NULL )
541 oracle->vardegreesuptodate =
TRUE;
547 oracle->varssize = 0;
559 assert(oracle !=
NULL);
561 assert(cons !=
NULL);
563 for( j = 0; j < cons->
nlinidxs; ++j )
591 assert(oracle !=
NULL);
597 if( oracle->vardegreesuptodate || oracle->nvars == 0 )
604 for( c = 0; c < oracle->nconss; ++c )
607 oracle->vardegreesuptodate =
TRUE;
618 assert(indexmap !=
NULL);
619 assert(nindices == 0 || indices !=
NULL);
621 for( ; nindices ; --nindices, ++indices )
623 assert(indexmap[*indices] >= 0);
624 *indices = indexmap[*indices];
644 assert(blkmem !=
NULL);
645 assert(linidxs !=
NULL);
646 assert(*linidxs !=
NULL);
647 assert(coefs !=
NULL);
648 assert(*coefs !=
NULL);
649 assert(nidxs !=
NULL);
653 for( offset = 0; offset < *nidxs; ++offset )
654 if( (*linidxs)[offset] >= 0 )
662 for( i = 0; i < *nidxs - offset; ++i )
664 (*linidxs)[i] = (*linidxs)[i+offset];
665 (*coefs)[i] = (*coefs) [i+offset];
685 assert(blkmem !=
NULL);
686 assert(quadelems !=
NULL);
687 assert(*quadelems !=
NULL);
688 assert(nquadelems !=
NULL);
689 assert(*nquadelems > 0);
692 for( offset = 0; offset < *
nquadelems; ++offset )
695 assert(((*quadelems)[offset].idx1 >= 0) == ((*quadelems)[offset].idx2 >= 0));
696 if( (*quadelems)[offset].idx1 >= 0 )
705 for( i = 0; i < *nquadelems - offset; ++i )
706 (*quadelems)[i] = (*quadelems)[i+offset];
707 *nquadelems -= offset;
718 assert(indexmap !=
NULL);
719 assert(nelems == 0 || elems !=
NULL);
721 for( ; nelems ; --nelems, ++elems )
723 assert(indexmap[elems->
idx1] >= 0);
724 assert(indexmap[elems->
idx2] >= 0);
725 elems->
idx1 = indexmap[elems->
idx1];
726 elems->
idx2 = indexmap[elems->
idx2];
730 int tmp = elems->
idx2;
746 assert(oracle !=
NULL);
747 assert(cons !=
NULL);
764 assert(linidxs !=
NULL);
765 assert(lincoefs !=
NULL);
769 *val += *lincoefs * x[*linidxs];
779 assert(quadelems !=
NULL);
783 *val += quadelems->
coef * x[quadelems->
idx1] * x[quadelems->
idx2];
796 for( i = 0; i < nvars; ++i )
804 if( nlval != nlval || ABS(nlval) >= oracle->infinity )
826 assert(oracle !=
NULL);
829 assert(grad !=
NULL);
845 assert(linidxs !=
NULL);
846 assert(lincoefs !=
NULL);
851 *val += *lincoefs * x[*
linidxs];
852 assert(grad[*linidxs] == 0.0);
865 assert(quadelems !=
NULL);
870 tmp = quadelems->
coef * x[quadelems->
idx1];
871 *val += tmp * x[quadelems->
idx2];
872 grad[quadelems->
idx2] += tmp;
873 grad[quadelems->
idx1] += quadelems->
coef * x[quadelems->
idx2];
893 for( i = 0; i < nvars; ++i )
902 SCIPdebug(
if( isnewx ) {printf(
"\nx =");
for( i = 0; i < nvars; ++i) printf(
" %g", xx[i]); printf(
"\n");} )
906 SCIPdebug( printf(
"g =");
for( i = 0; i < nvars; ++i) printf(
" %g", g[i]); printf(
"\n"); )
908 if( nlval != nlval || ABS(nlval) >= oracle->infinity )
912 SCIPdebugMessage(
"gradient evaluation yield invalid function value %g\n", nlval);
918 for( i = 0; i < nvars; ++i )
921 SCIPdebugMessage(
"gradient evaluation yield invalid gradient value %g\n", g[i]);
953 SCIPdebugMessage(
"%p hess lag sparsity set nzflag for quad\n", (
void*)oracle);
955 assert(oracle !=
NULL);
956 assert(colnz !=
NULL);
957 assert(collen !=
NULL);
958 assert(colnnz !=
NULL);
959 assert(nzcount !=
NULL);
960 assert(quadelems !=
NULL);
963 for( ; length > 0; --length, ++
quadelems )
965 assert(quadelems->
idx1 <= quadelems->
idx2);
1002 assert(oracle !=
NULL);
1003 assert(colnz !=
NULL);
1004 assert(collen !=
NULL);
1005 assert(colnnz !=
NULL);
1006 assert(nzcount !=
NULL);
1007 assert(exprvaridx !=
NULL);
1008 assert(exprtree !=
NULL);
1011 SCIPdebugMessage(
"%p hess lag sparsity set nzflag for exprtree\n", (
void*)oracle);
1019 for( i = 0; i < nvars; ++i )
1024 for( i = 0; i < nvars; ++i )
1025 for( j = 0; j <= i; ++j )
1027 if( !hesnz[i*nvars + j] )
1030 row =
MAX(exprvaridx[i], exprvaridx[j]);
1031 col =
MIN(exprvaridx[i], exprvaridx[j]);
1065 assert(length >= 0);
1066 assert(quadelems !=
NULL || length == 0);
1067 assert(hesoffset !=
NULL);
1068 assert(hescol !=
NULL);
1069 assert(values !=
NULL);
1071 for( ; length > 0; --length, ++
quadelems )
1073 assert(quadelems->
idx1 <= quadelems->
idx2);
1079 values[hesoffset[quadelems->
idx2] + idx] += weight * ((quadelems->
idx1 == quadelems->
idx2) ? 2 * quadelems->
coef : quadelems->
coef);
1113 assert(oracle !=
NULL);
1120 assert(exprtree !=
NULL);
1121 assert(exprvaridx !=
NULL);
1122 assert(hesoffset !=
NULL);
1123 assert(hescol !=
NULL);
1124 assert(values !=
NULL);
1134 for( i = 0; i < nvars; ++i )
1136 assert(exprvaridx[i] >= 0);
1137 xx[i] = x[exprvaridx[i]];
1144 SCIPdebugMessage(
"hessian evaluation yield invalid function value %g\n", val);
1151 for( i = 0; i < nvars; ++i )
1153 for( j = 0; j <= i; ++j, ++hh )
1160 SCIPdebugMessage(
"hessian evaluation yield invalid hessian value %g\n", *hh);
1166 row =
MAX(exprvaridx[i], exprvaridx[j]);
1167 col =
MIN(exprvaridx[i], exprvaridx[j]);
1169 if( !
SCIPsortedvecFindInt(&hescol[hesoffset[row]], col, hesoffset[row+1] - hesoffset[row], &idx) )
1171 SCIPerrorMessage(
"Could not find entry (%d, %d) in hessian sparsity\n", row, col);
1177 values[hesoffset[row] + idx] += weight * *hh;
1202 sprintf(buffer,
"%c%05d%.*s%s", prefix, idx, suffix ? (
int)(57-strlen(suffix)) : 57, name, suffix ? suffix :
"");
1204 sprintf(buffer,
"%c%05d", prefix, idx);
1210 assert(strlen(name) + (suffix ? strlen(suffix) : 0) <= 64);
1211 sprintf(buffer,
"%s%s", name, suffix ? suffix :
"");
1214 sprintf(buffer,
"%c%d%s", prefix, idx, suffix ? suffix :
"");
1234 assert(oracle !=
NULL);
1235 assert(file !=
NULL);
1236 assert(cons !=
NULL);
1238 for( i = 0; i < cons->
nlinidxs; ++i )
1290 assert(expr !=
NULL);
1325 assert(blkmem !=
NULL);
1326 assert(oracle !=
NULL);
1333 (*oracle)->blkmem = blkmem;
1335 (*oracle)->vardegreesuptodate =
TRUE;
1341 SCIP_CALL(
createConstraint((*oracle)->blkmem, &(*oracle)->objective, 0,
NULL,
NULL, 0,
NULL,
NULL,
NULL, 0.0, 0.0,
NULL) );
1351 assert(oracle !=
NULL);
1352 assert(*oracle !=
NULL);
1365 if( (*oracle)->name !=
NULL )
1381 assert(oracle !=
NULL);
1382 assert(infinity > 0.0);
1396 assert(oracle !=
NULL);
1400 return oracle->infinity;
1409 assert(oracle !=
NULL);
1413 if( oracle->name !=
NULL )
1431 assert(oracle !=
NULL);
1435 return oracle->name;
1444 const char** varnames
1449 assert(oracle !=
NULL);
1465 for( i = 0; i < nvars; ++i )
1466 oracle->varlbs[oracle->nvars+i] = -oracle->infinity;
1473 for( i = oracle->nvars; i < oracle->nvars + nvars; ++i )
1475 if( oracle->varlbs[i] > oracle->varubs[i] )
1478 oracle->varlbs[i] = oracle->varubs[i];
1483 for( i = 0; i < nvars; ++i )
1484 oracle->varubs[oracle->nvars+i] = oracle->infinity;
1486 if( varnames !=
NULL )
1488 if( oracle->varnames ==
NULL )
1494 for( i = 0; i < nvars; ++i )
1496 if( varnames[i] !=
NULL )
1501 oracle->varnames[oracle->nvars+i] =
NULL;
1504 else if( oracle->varnames !=
NULL )
1514 oracle->nvars += nvars;
1529 const int* nlininds,
1530 int*
const* lininds,
1539 const char** consnames
1546 assert(oracle !=
NULL);
1560 for( c = 0; c < nconss; ++c )
1563 nlininds !=
NULL ? nlininds[c] : 0,
1564 lininds !=
NULL ? lininds[c] :
NULL,
1565 linvals != NULL ? linvals[c] : NULL,
1566 nquadelems != NULL ? nquadelems[c] : 0,
1567 quadelems != NULL ? quadelems[c] : NULL,
1568 exprvaridxs != NULL ? exprvaridxs[c] : NULL,
1569 exprtrees != NULL ? exprtrees[c] : NULL,
1570 lhss != NULL ? lhss[c] : -oracle->infinity,
1571 rhss != NULL ? rhss[c] : oracle->infinity,
1572 consnames != NULL ? consnames[c] : NULL
1585 if( oracle->vardegreesuptodate )
1588 oracle->conss[oracle->nconss+c] = cons;
1590 oracle->nconss += nconss;
1592 if( addednlcon ==
TRUE )
1614 assert(oracle !=
NULL);
1619 if( nquadelems > 0 || oracle->objective->quadsize > 0 || exprtree !=
NULL || oracle->objective->exprtree !=
NULL )
1626 nlin, lininds, linvals, nquadelems, quadelems, exprvaridxs, exprtree, constant, constant,
NULL) );
1628 if( oracle->objective->exprtree !=
NULL )
1633 oracle->vardegreesuptodate =
FALSE;
1649 assert(oracle !=
NULL);
1650 assert(indices !=
NULL || nvars == 0);
1654 for( i = 0; i < nvars; ++i )
1656 assert(indices !=
NULL);
1657 assert(indices[i] >= 0);
1658 assert(indices[i] < oracle->nvars);
1660 oracle->varlbs[indices[i]] = (lbs !=
NULL ? lbs[i] : -oracle->infinity);
1661 oracle->varubs[indices[i]] = (ubs !=
NULL ? ubs[i] : oracle->infinity);
1663 if( oracle->varlbs[indices[i]] > oracle->varubs[indices[i]] )
1667 oracle->varlbs[indices[i]] = oracle->varubs[indices[i]];
1685 assert(oracle !=
NULL);
1686 assert(indices !=
NULL || nconss == 0);
1690 for( i = 0; i < nconss; ++i )
1692 assert(indices !=
NULL);
1693 assert(indices[i] >= 0);
1694 assert(indices[i] < oracle->nconss);
1696 oracle->conss[indices[i]]->lhs = (lhss !=
NULL ? lhss[i] : -oracle->infinity);
1697 oracle->conss[indices[i]]->rhs = (rhss !=
NULL ? rhss[i] : oracle->infinity);
1698 if( oracle->conss[indices[i]]->lhs > oracle->conss[indices[i]]->rhs )
1701 oracle->conss[indices[i]]->lhs = oracle->conss[indices[i]]->rhs;
1719 assert(oracle !=
NULL);
1726 lastgood = oracle->nvars - 1;
1727 while( lastgood >= 0 && delstats[lastgood] == 1 )
1732 assert(oracle->nconss == 0);
1734 oracle->objective->nquadelems = 0;
1735 oracle->objective->nlinidxs = 0;
1736 for( c = 0; c < oracle->nvars; ++c )
1743 for( c = oracle->nvars - 1; c > lastgood; --c )
1745 if( oracle->varnames && oracle->varnames[c] !=
NULL )
1755 for( c = 0; c <= lastgood; ++c )
1757 if( delstats[c] == 0 )
1762 assert(delstats[c] == 1);
1764 if( oracle->varnames && oracle->varnames[c] !=
NULL )
1772 delstats[lastgood] = c;
1776 while( lastgood > c && delstats[lastgood] == 1)
1778 if( oracle->varnames && oracle->varnames[lastgood] !=
NULL )
1782 delstats[lastgood] = -1;
1786 assert(c == lastgood);
1788 for( c = -1; c < oracle->nconss; ++c )
1790 cons = c < 0 ? oracle->objective : oracle->conss[c];
1791 assert(cons !=
NULL);
1813 oracle->nvars = lastgood+1;
1828 assert(oracle !=
NULL);
1834 oracle->vardegreesuptodate =
FALSE;
1836 lastgood = oracle->nconss - 1;
1837 while( lastgood >= 0 && delstats[lastgood] == 1)
1842 for( c = 0; c < oracle->nconss; ++c )
1849 for( c = oracle->nconss - 1; c > lastgood; --c )
1852 assert(oracle->conss[c] ==
NULL);
1859 for( c = 0; c <= lastgood; ++c )
1861 if( delstats[c] == 0 )
1867 assert(delstats[c] == 1);
1870 assert(oracle->conss[c] ==
NULL);
1874 oracle->conss[c] = oracle->conss[lastgood];
1875 assert(oracle->conss[c] !=
NULL);
1876 delstats[lastgood] = c;
1877 oracle->conss[lastgood] =
NULL;
1881 while( lastgood > c && delstats[lastgood] == 1)
1884 assert(oracle->conss[lastgood] ==
NULL);
1885 delstats[lastgood] = -1;
1889 assert(c == lastgood);
1891 oracle->nconss = lastgood+1;
1911 assert(oracle !=
NULL);
1912 assert(varidxs !=
NULL || nentries == 0);
1913 assert(newcoefs !=
NULL || nentries == 0);
1914 assert(considx >= -1);
1915 assert(considx < oracle->nconss);
1920 SCIPdebugMessage(
"change %d linear coefficients in cons %d\n", nentries, considx);
1924 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
1943 for( i = 0; i < nentries; ++i )
1945 assert(varidxs[i] >= 0);
1946 assert(varidxs[i] < oracle->nvars);
1950 SCIPdebugMessage(
"replace coefficient of var %d at pos %d by %g\n", varidxs[i], pos, newcoefs[i]);
1955 needsort |= (newcoefs[i] == 0.0);
1957 else if( newcoefs[i] != 0.0 )
1982 oracle->vardegreesuptodate &= (cons->
nlinidxs == oldlen);
1985 if( oracle->vardegreesuptodate )
1986 for( i = 0; i < cons->
nlinidxs; ++i )
1987 oracle->vardegrees[varidxs[i]] =
MAX(1, oracle->vardegrees[varidxs[i]]);
2007 assert(oracle !=
NULL);
2008 assert(quadelems !=
NULL || nquadelems == 0);
2009 assert(considx >= -1);
2010 assert(considx < oracle->nconss);
2012 if( nquadelems == 0 )
2017 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
2036 assert(quadelems[i].idx1 >= 0);
2037 assert(quadelems[i].idx2 >= 0);
2038 assert(quadelems[i].idx1 < oracle->nvars);
2039 assert(quadelems[i].idx2 < oracle->nvars);
2044 SCIPdebugMessage(
"replace coefficient of var%d*var%d at pos %d by %g\n", quadelems[i].idx1, quadelems[i].idx2, pos, quadelems[i].coef);
2049 needsort |= (quadelems[i].
coef == 0.0);
2054 SCIPdebugMessage(
"add coefficient of var%d*var%d at pos %d, value %g\n", quadelems[i].idx1, quadelems[i].idx2, cons->
nquadelems, quadelems[i].
coef);
2077 oracle->vardegreesuptodate &= (cons->
nquadelems == oldsize);
2080 if( oracle->vardegreesuptodate )
2104 assert(oracle !=
NULL);
2105 assert(considx >= -1);
2106 assert(considx < oracle->nconss);
2107 assert((exprvaridxs !=
NULL) == (exprtree !=
NULL));
2112 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
2119 oracle->vardegreesuptodate =
FALSE;
2123 if( exprtree ==
NULL )
2126 assert(oracle->exprinterpreter !=
NULL);
2136 if( oracle->vardegreesuptodate )
2141 oracle->vardegrees[cons->
exprvaridxs[j]] = INT_MAX;
2158 assert(oracle !=
NULL);
2159 assert(considx >= -1);
2160 assert(considx < oracle->nconss);
2161 assert(paramidx >= 0);
2162 assert(considx >= 0 || oracle->objective->exprtree !=
NULL);
2164 assert(considx == -1 || oracle->conss[considx]->exprtree !=
NULL);
2167 SCIPexprtreeSetParamVal(considx >= 0 ? oracle->conss[considx]->exprtree : oracle->objective->exprtree, paramidx, paramval);
2179 assert(oracle !=
NULL);
2183 oracle->objective->lhs = objconstant;
2184 oracle->objective->rhs = objconstant;
2194 assert(oracle !=
NULL);
2196 return oracle->
nvars;
2204 assert(oracle !=
NULL);
2214 assert(oracle !=
NULL);
2224 assert(oracle !=
NULL);
2234 assert(oracle !=
NULL);
2247 assert(oracle !=
NULL);
2248 assert(varidx >= 0);
2249 assert(varidx < oracle->nvars);
2263 assert(oracle !=
NULL);
2276 assert(oracle !=
NULL);
2277 assert(considx >= 0);
2278 assert(considx < oracle->nconss);
2280 return oracle->
conss[considx]->
lhs;
2289 assert(oracle !=
NULL);
2290 assert(considx >= 0);
2291 assert(considx < oracle->nconss);
2293 return oracle->
conss[considx]->
rhs;
2302 assert(oracle !=
NULL);
2303 assert(considx >= 0);
2304 assert(considx < oracle->nconss);
2319 assert(oracle !=
NULL);
2320 assert(considx >= -1);
2321 assert(considx < oracle->nconss);
2351 assert(oracle !=
NULL);
2358 for( i = 0; i < oracle->nvars; ++i )
2359 if( oracle->vardegrees[i] > maxdegree )
2361 maxdegree = oracle->vardegrees[i];
2362 if( maxdegree == INT_MAX )
2377 assert(oracle !=
NULL);
2384 for( c = 0; c < oracle->
nconss; ++c )
2388 return evalcapability;
2398 assert(oracle !=
NULL);
2404 assert(oracle->objective->lhs == oracle->objective->rhs);
2405 *objval += oracle->objective->lhs;
2418 assert(oracle !=
NULL);
2419 assert(x !=
NULL || oracle->
nvars == 0);
2420 assert(conval !=
NULL);
2440 assert(oracle !=
NULL);
2441 assert(x !=
NULL || oracle->nvars == 0);
2442 assert(convals !=
NULL);
2444 for( i = 0; i < oracle->nconss; ++i )
2461 assert(oracle !=
NULL);
2467 assert(oracle->objective->lhs == oracle->objective->rhs);
2468 *objval += oracle->objective->lhs;
2483 assert(oracle !=
NULL);
2484 assert(x !=
NULL || oracle->
nvars == 0);
2485 assert(conval !=
NULL);
2512 assert(oracle !=
NULL);
2516 if( oracle->jacoffsets !=
NULL )
2518 assert(oracle->jaccols !=
NULL);
2519 if( offset !=
NULL )
2520 *offset = oracle->jacoffsets;
2522 *col = oracle->jaccols;
2528 maxnnz =
MIN(oracle->nvars, 10) * oracle->nconss;
2535 if( offset !=
NULL )
2536 *offset = oracle->jacoffsets;
2538 *col = oracle->jaccols;
2545 for( i = 0; i < oracle->nconss; ++i )
2547 oracle->jacoffsets[i] = nnz;
2549 cons = oracle->conss[i];
2550 assert(cons !=
NULL);
2587 for( j = 0; j < cons->
nlinidxs; ++j )
2604 for( j = 0; j < oracle->nvars; ++j )
2606 if( nzflag[j] ==
FALSE )
2610 oracle->jaccols[nnz] = j;
2615 oracle->jacoffsets[oracle->nconss] = nnz;
2625 if( offset !=
NULL )
2626 *offset = oracle->jacoffsets;
2628 *col = oracle->jaccols;
2658 assert(oracle !=
NULL);
2659 assert(jacobi !=
NULL);
2661 assert(oracle->jacoffsets !=
NULL);
2662 assert(oracle->jaccols !=
NULL);
2669 j = oracle->jacoffsets[0];
2671 for( i = 0; i < oracle->nconss; ++i )
2673 cons = oracle->conss[i];
2674 assert(cons !=
NULL);
2685 assert(j == oracle->jacoffsets[i+1]);
2697 assert(nvars <= oracle->nvars);
2709 for( l = 0; l < nvars; ++l )
2714 SCIPdebug(
if( isnewx ) {printf(
"\nx =");
for( l = 0; l < nvars; ++l) printf(
" %g", xx[l]); printf(
"\n");} )
2718 SCIPdebug( printf(
"g =");
for( l = 0; l < nvars; ++l) printf(
" %g", grad[l]); printf(
"\n"); )
2720 if( nlval != nlval || ABS(nlval) >= oracle->infinity )
2722 SCIPdebugMessage(
"gradient evaluation yield invalid function value %g\n", nlval);
2728 if( convals !=
NULL )
2730 for( l = 0; l < nvars; ++l )
2732 assert(oracle->jaccols[j+l] == cons->
exprvaridxs[l]);
2735 SCIPdebugMessage(
"gradient evaluation yield invalid gradient value %g\n", grad[l]);
2740 jacobi[k++] = grad[l];
2747 else if( convals !=
NULL )
2761 while( j < oracle->jacoffsets[i+1] )
2762 jacobi[k++] = grad[oracle->jaccols[j++]];
2791 assert(oracle !=
NULL);
2795 if( oracle->heslagoffsets !=
NULL )
2797 assert(oracle->heslagcols !=
NULL);
2798 if( offset !=
NULL )
2799 *offset = oracle->heslagoffsets;
2801 *col = oracle->heslagcols;
2815 if( oracle->objective->nquadelems != 0 )
2820 if( oracle->objective->exprtree !=
NULL )
2825 for( i = 0; i < oracle->nconss; ++i )
2827 if( oracle->conss[i]->nquadelems != 0 )
2832 if( oracle->conss[i]->exprtree !=
NULL )
2842 for( i = 0; i < oracle->nvars; ++i )
2844 oracle->heslagoffsets[i] = cnt;
2845 for( j = 0; j < colnnz[i]; ++j )
2848 oracle->heslagcols[cnt++] = colnz[i][j];
2853 oracle->heslagoffsets[oracle->nvars] = cnt;
2860 if( offset !=
NULL )
2861 *offset = oracle->heslagoffsets;
2863 *col = oracle->heslagcols;
2885 assert(oracle !=
NULL);
2887 assert(lambda !=
NULL || oracle->
nconss == 0);
2888 assert(hessian !=
NULL);
2895 for( i = oracle->heslagoffsets[oracle->nvars] - 1; i >= 0; --i )
2898 if( objfactor != 0.0 )
2900 SCIP_CALL(
hessLagAddQuad(objfactor, oracle->objective->nquadelems, oracle->objective->quadelems, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2901 SCIP_CALL_QUIET(
hessLagAddExprtree(oracle, objfactor, x, isnewx, oracle->objective->exprvaridxs, oracle->objective->exprtree, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2904 for( i = 0; i < oracle->nconss; ++i )
2906 assert( lambda !=
NULL );
2907 if( lambda[i] == 0.0 )
2909 SCIP_CALL(
hessLagAddQuad(lambda[i], oracle->conss[i]->nquadelems, oracle->conss[i]->quadelems, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2910 SCIP_CALL_QUIET(
hessLagAddExprtree(oracle, lambda[i], x, isnewx, oracle->conss[i]->exprvaridxs, oracle->conss[i]->exprtree, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2927 assert(oracle !=
NULL);
2934 SCIPmessageFPrintInfo(messagehdlr, file,
"NLPI Oracle %s: %d variables and %d constraints\n", oracle->name ? oracle->name :
"", oracle->nvars, oracle->nconss);
2935 for( i = 0; i < oracle->nvars; ++i )
2937 if( oracle->varnames !=
NULL && oracle->varnames[i] !=
NULL )
2942 if( oracle->vardegreesuptodate )
2949 if( oracle->objective->lhs != 0.0 )
2953 for( i = 0; i < oracle->nconss; ++i )
2955 if( oracle->conss[i]->name !=
NULL )
2960 lhs = oracle->conss[i]->lhs;
2961 rhs = oracle->conss[i]->rhs;
2963 if( lhs > -oracle->infinity && rhs < oracle->
infinity && lhs != rhs )
2972 else if( lhs > -oracle->infinity )
2995 static const char* nllevelname[4] = {
"LP",
"QCP",
"NLP",
"DNLP" };
2996 const char* problemname;
3003 assert(oracle !=
NULL);
3010 havelongvarnames =
FALSE;
3011 for( i = 0; i < oracle->nvars; ++i )
3012 if( oracle->varnames !=
NULL && oracle->varnames[i] !=
NULL && strlen(oracle->varnames[i]) > 9 )
3014 havelongvarnames =
TRUE;
3018 havelongequnames =
FALSE;
3019 for( i = 0; i < oracle->nconss; ++i )
3020 if( oracle->conss[i]->name && strlen(oracle->conss[i]->name) > 9 )
3022 havelongequnames =
TRUE;
3028 SCIPmessageFPrintInfo(messagehdlr, file,
"* NLPI Oracle Problem %s\n", oracle->name ? oracle->name :
"");
3030 for( i = 0; i < oracle->nvars; ++i )
3032 printName(namebuf, oracle->varnames !=
NULL ? oracle->varnames[i] :
NULL, i,
'x', NULL, havelongvarnames);
3038 for( i = 0; i < oracle->nvars; ++i )
3041 name = oracle->varnames !=
NULL ? oracle->varnames[i] :
NULL;
3042 if( oracle->varlbs[i] == oracle->varubs[i] )
3049 if( oracle->varlbs[i] > -oracle->infinity )
3054 if( oracle->varubs[i] < oracle->infinity )
3060 if( initval !=
NULL )
3070 for( i = 0; i < oracle->nconss; ++i )
3072 printName(namebuf, oracle->conss[i]->name, i,
'e',
NULL, havelongequnames);
3075 if( oracle->conss[i]->lhs > -oracle->infinity && oracle->conss[i]->rhs < oracle->infinity && oracle->conss[i]->lhs != oracle->conss[i]->rhs )
3078 printName(namebuf, oracle->conss[i]->name, i,
'e',
"_RNG", havelongequnames);
3087 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->objective, havelongvarnames, havelongequnames) );
3088 if( oracle->objective->lhs != 0.0 )
3092 for( i = 0; i < oracle->nconss; ++i )
3097 printName(namebuf, oracle->conss[i]->name, i,
'e',
NULL, havelongequnames);
3100 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->conss[i], havelongvarnames, havelongequnames) );
3102 lhs = oracle->conss[i]->lhs;
3103 rhs = oracle->conss[i]->rhs;
3109 else if( lhs > -oracle->infinity )
3115 if( lhs > -oracle->infinity && rhs < oracle->infinity && lhs != rhs )
3117 printName(namebuf, oracle->conss[i]->name, i,
'e',
"_RNG", havelongequnames);
3120 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->conss[i], havelongvarnames, havelongequnames) );
3125 if( nllevel <= 0 && oracle->conss[i]->
nquadelems > 0 )
3127 if( nllevel <= 1 && oracle->conss[i]->
exprtree !=
NULL )
3133 problemname = oracle->name ? oracle->name :
"m";
3138 SCIPmessageFPrintInfo(messagehdlr, file,
"Solve %s minimizing NLPIORACLEOBJVAR using %s;\n", problemname, nllevelname[nllevel]);
void SCIPquadelemSort(SCIP_QUADELEM *quadelems, int nquadelems)
SCIP_RETCODE SCIPnlpiOraclePrintProblemGams(SCIP_NLPIORACLE *oracle, SCIP_Real *initval, SCIP_MESSAGEHDLR *messagehdlr, FILE *file)
SCIP_RETCODE SCIPnlpiOracleEvalConstraintValues(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *convals)
#define BMSfreeBlockMemoryArrayNull(mem, ptr, num)
const char * SCIPexprintGetName(void)
const SCIP_Real * SCIPnlpiOracleGetVarUbs(SCIP_NLPIORACLE *oracle)
static void updateVariableDegrees(SCIP_NLPIORACLE *oracle)
methods to interpret (evaluate) an expression tree "fast"
SCIP_RETCODE SCIPnlpiOracleGetJacobianSparsity(SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
void SCIPexprtreePrint(SCIP_EXPRTREE *tree, SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char **varnames, const char **paramnames)
SCIP_EXPRINTCAPABILITY SCIPnlpiOracleGetEvalCapability(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleGetHessianLagSparsity(SCIP_NLPIORACLE *oracle, const int **offset, const int **col)
int SCIPnlpiOracleGetNVars(SCIP_NLPIORACLE *oracle)
SCIP_EXPROP SCIPexprGetOperator(SCIP_EXPR *expr)
static SCIP_Bool exprIsNonSmooth(SCIP_EXPR *expr)
static SCIP_RETCODE ensureConssSize(SCIP_NLPIORACLE *oracle, int minsize)
static SCIP_RETCODE ensureIntArraySize(BMS_BLKMEM *blkmem, int **intarray, int *len, int minsize)
SCIP_RETCODE SCIPnlpiOracleSetObjective(SCIP_NLPIORACLE *oracle, const SCIP_Real constant, int nlin, const int *lininds, const SCIP_Real *linvals, int nquadelems, const SCIP_QUADELEM *quadelems, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree)
static SCIP_RETCODE hessLagAddExprtree(SCIP_NLPIORACLE *oracle, SCIP_Real weight, const SCIP_Real *x, SCIP_Bool new_x, int *exprvaridx, SCIP_EXPRTREE *exprtree, int *hesoffset, int *hescol, SCIP_Real *values)
static void freeVariables(SCIP_NLPIORACLE *oracle)
methods to store an NLP and request function, gradient, and hessian values
static SCIP_RETCODE createConstraint(BMS_BLKMEM *blkmem, SCIP_NLPIORACLECONS **cons, int nlinidxs, const int *linidxs, const SCIP_Real *lincoefs, int nquadelems, const SCIP_QUADELEM *quadelems, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree, SCIP_Real lhs, SCIP_Real rhs, const char *name)
static SCIP_RETCODE ensureVarsSize(SCIP_NLPIORACLE *oracle, int minsize)
SCIP_Real SCIPnlpiOracleGetConstraintLhs(SCIP_NLPIORACLE *oracle, int considx)
static SCIP_RETCODE evalFunctionGradient(SCIP_NLPIORACLE *oracle, SCIP_NLPIORACLECONS *cons, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *val, SCIP_Real *grad)
static void printName(char *buffer, char *name, int idx, char prefix, const char *suffix, SCIP_Bool longnames)
static void freeConstraint(BMS_BLKMEM *blkmem, SCIP_NLPIORACLECONS **cons)
enum SCIP_Retcode SCIP_RETCODE
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveValue(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Real *objval)
SCIP_RETCODE SCIPexprtreeCopy(BMS_BLKMEM *blkmem, SCIP_EXPRTREE **targettree, SCIP_EXPRTREE *sourcetree)
SCIP_RETCODE SCIPexprintCompile(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
static SCIP_RETCODE evalFunctionValue(SCIP_NLPIORACLE *oracle, SCIP_NLPIORACLECONS *cons, const SCIP_Real *x, SCIP_Real *val)
static SCIP_RETCODE hessLagAddQuad(SCIP_Real weight, int length, SCIP_QUADELEM *quadelems, int *hesoffset, int *hescol, SCIP_Real *values)
static void invalidateJacobiSparsity(SCIP_NLPIORACLE *oracle)
static SCIP_RETCODE printFunction(SCIP_NLPIORACLE *oracle, SCIP_MESSAGEHDLR *messagehdlr, FILE *file, SCIP_NLPIORACLECONS *cons, SCIP_Bool longvarnames, SCIP_Bool longequnames)
SCIP_EXPRINTCAPABILITY SCIPexprintGetExprtreeCapability(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
static void mapIndices(int *indexmap, int nindices, int *indices)
SCIP_Bool SCIPquadelemSortedFind(SCIP_QUADELEM *quadelems, int idx1, int idx2, int nquadelems, int *pos)
unsigned int SCIP_EXPRINTCAPABILITY
#define BMSfreeMemory(ptr)
void SCIPexprtreeSetParamVal(SCIP_EXPRTREE *tree, int paramidx, SCIP_Real paramval)
SCIP_RETCODE SCIPnlpiOracleEvalObjectiveGradient(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *objval, SCIP_Real *objgrad)
const char * SCIPnlpiOracleGetProblemName(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleDelConsSet(SCIP_NLPIORACLE *oracle, int *delstats)
SCIP_RETCODE SCIPnlpiOracleChgObjConstant(SCIP_NLPIORACLE *oracle, SCIP_Real objconstant)
int SCIPnlpiOracleGetNConstraints(SCIP_NLPIORACLE *oracle)
static void mapIndicesQuad(int *indexmap, int nelems, SCIP_QUADELEM *elems)
static void clearDeletedQuadElements(BMS_BLKMEM *blkmem, SCIP_QUADELEM **quadelems, int *nquadelems)
public methods for expressions, expression trees, expression graphs, and related stuff ...
#define SCIP_DEFAULT_EPSILON
static int calcGrowSize(int num)
#define BMSduplicateBlockMemoryArray(mem, ptr, source, num)
int SCIPnlpiOracleGetConstraintDegree(SCIP_NLPIORACLE *oracle, int considx)
SCIP_RETCODE SCIPnlpiOracleChgExprtree(SCIP_NLPIORACLE *oracle, int considx, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree)
static void sortLinearCoefficients(int *nidxs, int *idxs, SCIP_Real *coefs)
SCIP_RETCODE SCIPnlpiOracleCreate(BMS_BLKMEM *blkmem, SCIP_NLPIORACLE **oracle)
SCIP_RETCODE SCIPexprintEval(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Real *val)
const SCIP_Real * SCIPnlpiOracleGetVarLbs(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPexprintCreate(BMS_BLKMEM *blkmem, SCIP_EXPRINT **exprint)
SCIP_RETCODE SCIPnlpiOracleChgVarBounds(SCIP_NLPIORACLE *oracle, int nvars, const int *indices, const SCIP_Real *lbs, const SCIP_Real *ubs)
static void invalidateHessianLagSparsity(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleAddVars(SCIP_NLPIORACLE *oracle, int nvars, const SCIP_Real *lbs, const SCIP_Real *ubs, const char **varnames)
int SCIPexprtreeGetNVars(SCIP_EXPRTREE *tree)
static SCIP_RETCODE ensureConsLinSize(BMS_BLKMEM *blkmem, SCIP_NLPIORACLECONS *cons, int minsize)
SCIP_Real SCIPnlpiOracleGetConstraintRhs(SCIP_NLPIORACLE *oracle, int considx)
SCIP_EXPR * SCIPexprtreeGetRoot(SCIP_EXPRTREE *tree)
SCIP_Bool SCIPsortedvecFindInt(int *intarray, int val, int len, int *pos)
SCIP_Real SCIPnlpiOracleGetInfinity(SCIP_NLPIORACLE *oracle)
SCIP_RETCODE SCIPnlpiOracleFree(SCIP_NLPIORACLE **oracle)
static SCIP_RETCODE moveVariable(SCIP_NLPIORACLE *oracle, int fromidx, int toidx)
#define BMSfreeBlockMemory(mem, ptr)
static void clearDeletedLinearElements(BMS_BLKMEM *blkmem, int **linidxs, SCIP_Real **coefs, int *nidxs)
SCIP_RETCODE SCIPnlpiOracleEvalConstraintGradient(SCIP_NLPIORACLE *oracle, const int considx, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *conval, SCIP_Real *congrad)
#define SCIP_EXPRINTCAPABILITY_ALL
public data structures and miscellaneous methods
static SCIP_RETCODE hessLagSparsitySetNzFlagForQuad(SCIP_NLPIORACLE *oracle, int **colnz, int *collen, int *colnnz, int *nzcount, int length, SCIP_QUADELEM *quadelems)
SCIP_RETCODE SCIPnlpiOraclePrintProblem(SCIP_NLPIORACLE *oracle, SCIP_MESSAGEHDLR *messagehdlr, FILE *file)
SCIP_EXPR ** SCIPexprGetChildren(SCIP_EXPR *expr)
SCIP_NLPIORACLECONS * objective
#define BMSallocBlockMemoryArray(mem, ptr, num)
SCIP_RETCODE SCIPnlpiOracleSetProblemName(SCIP_NLPIORACLE *oracle, const char *name)
static void updateVariableDegreesCons(SCIP_NLPIORACLE *oracle, SCIP_NLPIORACLECONS *cons)
SCIP_RETCODE SCIPnlpiOracleAddConstraints(SCIP_NLPIORACLE *oracle, int nconss, const SCIP_Real *lhss, const SCIP_Real *rhss, const int *nlininds, int *const *lininds, SCIP_Real *const *linvals, const int *nquadelems, SCIP_QUADELEM *const *quadelems, int *const *exprvaridxs, SCIP_EXPRTREE *const *exprtrees, const char **consnames)
#define BMSfreeBlockMemoryArray(mem, ptr, num)
void SCIPquadelemSqueeze(SCIP_QUADELEM *quadelems, int nquadelems, int *nquadelemsnew)
int SCIPexprGetNChildren(SCIP_EXPR *expr)
SCIP_RETCODE SCIPnlpiOracleEvalConstraintValue(SCIP_NLPIORACLE *oracle, int considx, const SCIP_Real *x, SCIP_Real *conval)
SCIP_RETCODE SCIPexprtreeFree(SCIP_EXPRTREE **tree)
SCIP_RETCODE SCIPnlpiOracleChgLinearCoefs(SCIP_NLPIORACLE *oracle, int considx, int nentries, const int *varidxs, const SCIP_Real *newcoefs)
#define BMScopyMemoryArray(ptr, source, num)
SCIP_RETCODE SCIPnlpiOracleChgQuadCoefs(SCIP_NLPIORACLE *oracle, int considx, int nquadelems, const SCIP_QUADELEM *quadelems)
SCIP_RETCODE SCIPexprintHessianDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *hessian)
static SCIP_RETCODE hessLagSparsitySetNzFlagForExprtree(SCIP_NLPIORACLE *oracle, int **colnz, int *collen, int *colnnz, int *nzcount, int *exprvaridx, SCIP_EXPRTREE *exprtree, int dim)
SCIP_RETCODE SCIPnlpiOracleChgConsSides(SCIP_NLPIORACLE *oracle, int nconss, const int *indices, const SCIP_Real *lhss, const SCIP_Real *rhss)
#define BMSclearMemory(ptr)
SCIP_RETCODE SCIPexprintGrad(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *gradient)
static void freeConstraints(SCIP_NLPIORACLE *oracle)
static SCIP_RETCODE ensureConsQuadSize(BMS_BLKMEM *blkmem, SCIP_NLPIORACLECONS *cons, int minsize)
#define SCIP_CALL_QUIET(x)
SCIP_RETCODE SCIPnlpiOracleDelVarSet(SCIP_NLPIORACLE *oracle, int *delstats)
char * SCIPnlpiOracleGetConstraintName(SCIP_NLPIORACLE *oracle, int considx)
#define SCIP_DEFAULT_INFINITY
SCIP_QUADELEM * quadelems
SCIP_RETCODE SCIPnlpiOracleChgExprParam(SCIP_NLPIORACLE *oracle, int considx, int paramidx, SCIP_Real paramval)
int SCIPnlpiOracleGetVarDegree(SCIP_NLPIORACLE *oracle, int varidx)
SCIP_RETCODE SCIPnlpiOracleEvalHessianLag(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real objfactor, const SCIP_Real *lambda, SCIP_Real *hessian)
public methods for message output
SCIP_Bool vardegreesuptodate
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
#define BMSallocMemory(ptr)
SCIP_EXPRINT * exprinterpreter
SCIP_RETCODE SCIPexprintHessianSparsityDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool *sparsity)
SCIP_RETCODE SCIPnlpiOracleSetInfinity(SCIP_NLPIORACLE *oracle, SCIP_Real infinity)
int SCIPexprtreeGetNParams(SCIP_EXPRTREE *tree)
SCIP_RETCODE SCIPnlpiOracleEvalJacobian(SCIP_NLPIORACLE *oracle, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *convals, SCIP_Real *jacobi)
#define BMSallocBlockMemory(mem, ptr)
SCIP_RETCODE SCIPexprintFree(SCIP_EXPRINT **exprint)
#define BMSclearMemoryArray(ptr, num)
struct BMS_BlkMem BMS_BLKMEM
char ** SCIPnlpiOracleGetVarNames(SCIP_NLPIORACLE *oracle)
#define SCIP_CALL_ABORT(x)
int * SCIPnlpiOracleGetVarDegrees(SCIP_NLPIORACLE *oracle)
void SCIPsortedvecInsertInt(int *intarray, int keyval, int *len, int *pos)
#define BMSreallocBlockMemoryArray(mem, ptr, oldnum, newnum)
int SCIPnlpiOracleGetMaxDegree(SCIP_NLPIORACLE *oracle)
SCIP_NLPIORACLECONS ** conss
void SCIPsortIntReal(int *intarray, SCIP_Real *realarray, int len)