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);
748 assert(x != NULL || oracle->
nvars == 0);
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 )
829 assert(oracle != NULL);
830 assert(x != NULL || oracle->
nvars == 0);
832 assert(grad != NULL);
848 assert(linidxs != NULL);
849 assert(lincoefs != NULL);
854 *val += *lincoefs * x[*
linidxs];
855 assert(grad[*linidxs] == 0.0);
868 assert(quadelems != NULL);
873 tmp = quadelems->
coef * x[quadelems->
idx1];
874 *val += tmp * x[quadelems->
idx2];
875 grad[quadelems->
idx2] += tmp;
876 grad[quadelems->
idx1] += quadelems->
coef * x[quadelems->
idx2];
896 for( i = 0; i < nvars; ++i )
905 SCIPdebug(
if( isnewx ) {printf(
"\nx =");
for( i = 0; i < nvars; ++i) printf(
" %g", xx[i]); printf(
"\n");} )
909 SCIPdebug( printf(
"g =");
for( i = 0; i < nvars; ++i) printf(
" %g", g[i]); printf(
"\n"); )
911 if( nlval != nlval || ABS(nlval) >= oracle->infinity )
915 SCIPdebugMessage(
"gradient evaluation yield invalid function value %g\n", nlval);
921 for( i = 0; i < nvars; ++i )
924 SCIPdebugMessage(
"gradient evaluation yield invalid gradient value %g\n", g[i]);
956 SCIPdebugMessage(
"%p hess lag sparsity set nzflag for quad\n", (
void*)oracle);
958 assert(oracle != NULL);
959 assert(colnz != NULL);
960 assert(collen != NULL);
961 assert(colnnz != NULL);
962 assert(nzcount != NULL);
963 assert(quadelems != NULL);
966 for( ; length > 0; --length, ++
quadelems )
968 assert(quadelems->
idx1 <= quadelems->
idx2);
1005 assert(oracle != NULL);
1006 assert(colnz != NULL);
1007 assert(collen != NULL);
1008 assert(colnnz != NULL);
1009 assert(nzcount != NULL);
1010 assert(exprvaridx != NULL);
1011 assert(exprtree != NULL);
1014 SCIPdebugMessage(
"%p hess lag sparsity set nzflag for exprtree\n", (
void*)oracle);
1022 for( i = 0; i < nvars; ++i )
1027 for( i = 0; i < nvars; ++i )
1028 for( j = 0; j <= i; ++j )
1030 if( !hesnz[i*nvars + j] )
1033 row =
MAX(exprvaridx[i], exprvaridx[j]);
1034 col = MIN(exprvaridx[i], exprvaridx[j]);
1068 assert(length >= 0);
1069 assert(quadelems != NULL || length == 0);
1070 assert(hesoffset != NULL);
1071 assert(hescol != NULL);
1072 assert(values != NULL);
1074 for( ; length > 0; --length, ++
quadelems )
1076 assert(quadelems->
idx1 <= quadelems->
idx2);
1082 values[hesoffset[quadelems->
idx2] + idx] += weight * ((quadelems->
idx1 == quadelems->
idx2) ? 2 * quadelems->
coef : quadelems->
coef);
1116 assert(oracle != NULL);
1117 assert(x != NULL || new_x ==
FALSE);
1123 assert(exprtree != NULL);
1124 assert(exprvaridx != NULL);
1125 assert(hesoffset != NULL);
1126 assert(hescol != NULL);
1127 assert(values != NULL);
1137 for( i = 0; i < nvars; ++i )
1139 assert(exprvaridx[i] >= 0);
1140 xx[i] = x[exprvaridx[i]];
1147 SCIPdebugMessage(
"hessian evaluation yield invalid function value %g\n", val);
1154 for( i = 0; i < nvars; ++i )
1156 for( j = 0; j <= i; ++j, ++hh )
1163 SCIPdebugMessage(
"hessian evaluation yield invalid hessian value %g\n", *hh);
1169 row =
MAX(exprvaridx[i], exprvaridx[j]);
1170 col = MIN(exprvaridx[i], exprvaridx[j]);
1172 if( !
SCIPsortedvecFindInt(&hescol[hesoffset[row]], col, hesoffset[row+1] - hesoffset[row], &idx) )
1174 SCIPerrorMessage(
"Could not find entry (%d, %d) in hessian sparsity\n", row, col);
1180 values[hesoffset[row] + idx] += weight * *hh;
1202 assert(idx >= 0 && idx < 100000);
1207 sprintf(buffer,
"%c%05d%.*s%s", prefix, idx, suffix ? (
int)(57-strlen(suffix)) : 57, name, suffix ? suffix :
"");
1209 sprintf(buffer,
"%c%05d", prefix, idx);
1215 assert(strlen(name) + (suffix ? strlen(suffix) : 0) <= 64);
1216 sprintf(buffer,
"%s%s", name, suffix ? suffix :
"");
1219 sprintf(buffer,
"%c%d%s", prefix, idx, suffix ? suffix :
"");
1239 assert(oracle != NULL);
1240 assert(file != NULL);
1241 assert(cons != NULL);
1243 for( i = 0; i < cons->
nlinidxs; ++i )
1245 printName(namebuf, oracle->varnames != NULL ? oracle->varnames[cons->
linidxs[i]] : NULL, cons->
linidxs[i],
'x', NULL, longvarnames);
1295 assert(expr != NULL);
1330 assert(blkmem != NULL);
1331 assert(oracle != NULL);
1338 (*oracle)->blkmem = blkmem;
1340 (*oracle)->vardegreesuptodate =
TRUE;
1346 SCIP_CALL(
createConstraint((*oracle)->blkmem, &(*oracle)->objective, 0, NULL, NULL, 0, NULL, NULL, NULL, 0.0, 0.0, NULL) );
1356 assert(oracle != NULL);
1357 assert(*oracle != NULL);
1370 if( (*oracle)->name != NULL )
1386 assert(oracle != NULL);
1387 assert(infinity > 0.0);
1401 assert(oracle != NULL);
1405 return oracle->infinity;
1414 assert(oracle != NULL);
1418 if( oracle->name != NULL )
1436 assert(oracle != NULL);
1440 return oracle->name;
1449 const char** varnames
1454 assert(oracle != NULL);
1470 for( i = 0; i < nvars; ++i )
1471 oracle->varlbs[oracle->nvars+i] = -oracle->infinity;
1478 for( i = oracle->nvars; i < oracle->nvars + nvars; ++i )
1480 if( oracle->varlbs[i] > oracle->varubs[i] )
1483 oracle->varlbs[i] = oracle->varubs[i];
1488 for( i = 0; i < nvars; ++i )
1489 oracle->varubs[oracle->nvars+i] = oracle->infinity;
1491 if( varnames != NULL )
1493 if( oracle->varnames == NULL )
1499 for( i = 0; i < nvars; ++i )
1501 if( varnames[i] != NULL )
1506 oracle->varnames[oracle->nvars+i] = NULL;
1509 else if( oracle->varnames != NULL )
1519 oracle->nvars += nvars;
1534 const int* nlininds,
1535 int*
const* lininds,
1544 const char** consnames
1551 assert(oracle != NULL);
1565 for( c = 0; c < nconss; ++c )
1568 nlininds != NULL ? nlininds[c] : 0,
1569 lininds != NULL ? lininds[c] : NULL,
1570 linvals != NULL ? linvals[c] : NULL,
1571 nquadelems != NULL ? nquadelems[c] : 0,
1572 quadelems != NULL ? quadelems[c] : NULL,
1573 exprvaridxs != NULL ? exprvaridxs[c] : NULL,
1574 exprtrees != NULL ? exprtrees[c] : NULL,
1575 lhss != NULL ? lhss[c] : -oracle->infinity,
1576 rhss != NULL ? rhss[c] : oracle->infinity,
1577 consnames != NULL ? consnames[c] : NULL
1590 if( oracle->vardegreesuptodate )
1593 oracle->conss[oracle->nconss+c] = cons;
1595 oracle->nconss += nconss;
1597 if( addednlcon ==
TRUE )
1619 assert(oracle != NULL);
1624 if( nquadelems > 0 || oracle->objective->quadsize > 0 || exprtree != NULL || oracle->objective->exprtree != NULL )
1631 nlin, lininds, linvals, nquadelems, quadelems, exprvaridxs, exprtree, constant, constant, NULL) );
1633 if( oracle->objective->exprtree != NULL )
1638 oracle->vardegreesuptodate =
FALSE;
1654 assert(oracle != NULL);
1655 assert(indices != NULL || nvars == 0);
1659 for( i = 0; i < nvars; ++i )
1661 assert(indices != NULL);
1662 assert(indices[i] >= 0);
1663 assert(indices[i] < oracle->nvars);
1665 oracle->varlbs[indices[i]] = (lbs != NULL ? lbs[i] : -oracle->infinity);
1666 oracle->varubs[indices[i]] = (ubs != NULL ? ubs[i] : oracle->infinity);
1668 if( oracle->varlbs[indices[i]] > oracle->varubs[indices[i]] )
1672 oracle->varlbs[indices[i]] = oracle->varubs[indices[i]];
1690 assert(oracle != NULL);
1691 assert(indices != NULL || nconss == 0);
1695 for( i = 0; i < nconss; ++i )
1697 assert(indices != NULL);
1698 assert(indices[i] >= 0);
1699 assert(indices[i] < oracle->nconss);
1701 oracle->conss[indices[i]]->lhs = (lhss != NULL ? lhss[i] : -oracle->infinity);
1702 oracle->conss[indices[i]]->rhs = (rhss != NULL ? rhss[i] : oracle->infinity);
1703 if( oracle->conss[indices[i]]->lhs > oracle->conss[indices[i]]->rhs )
1706 oracle->conss[indices[i]]->lhs = oracle->conss[indices[i]]->rhs;
1724 assert(oracle != NULL);
1731 lastgood = oracle->nvars - 1;
1732 while( lastgood >= 0 && delstats[lastgood] == 1 )
1737 assert(oracle->nconss == 0);
1738 assert(oracle->objective->exprtree == NULL ||
SCIPexprtreeGetNVars(oracle->objective->exprtree) == 0);
1739 oracle->objective->nquadelems = 0;
1740 oracle->objective->nlinidxs = 0;
1741 for( c = 0; c < oracle->nvars; ++c )
1748 for( c = oracle->nvars - 1; c > lastgood; --c )
1750 if( oracle->varnames && oracle->varnames[c] != NULL )
1760 for( c = 0; c <= lastgood; ++c )
1762 if( delstats[c] == 0 )
1767 assert(delstats[c] == 1);
1769 if( oracle->varnames && oracle->varnames[c] != NULL )
1777 delstats[lastgood] = c;
1781 while( lastgood > c && delstats[lastgood] == 1)
1783 if( oracle->varnames && oracle->varnames[lastgood] != NULL )
1787 delstats[lastgood] = -1;
1791 assert(c == lastgood);
1793 for( c = -1; c < oracle->nconss; ++c )
1795 cons = c < 0 ? oracle->objective : oracle->conss[c];
1796 assert(cons != NULL);
1818 oracle->nvars = lastgood+1;
1833 assert(oracle != NULL);
1839 oracle->vardegreesuptodate =
FALSE;
1841 lastgood = oracle->nconss - 1;
1842 while( lastgood >= 0 && delstats[lastgood] == 1)
1847 for( c = 0; c < oracle->nconss; ++c )
1854 for( c = oracle->nconss - 1; c > lastgood; --c )
1857 assert(oracle->conss[c] == NULL);
1864 for( c = 0; c <= lastgood; ++c )
1866 if( delstats[c] == 0 )
1872 assert(delstats[c] == 1);
1875 assert(oracle->conss[c] == NULL);
1879 oracle->conss[c] = oracle->conss[lastgood];
1880 assert(oracle->conss[c] != NULL);
1881 delstats[lastgood] = c;
1882 oracle->conss[lastgood] = NULL;
1886 while( lastgood > c && delstats[lastgood] == 1)
1889 assert(oracle->conss[lastgood] == NULL);
1890 delstats[lastgood] = -1;
1894 assert(c == lastgood);
1896 oracle->nconss = lastgood+1;
1916 assert(oracle != NULL);
1917 assert(varidxs != NULL || nentries == 0);
1918 assert(newcoefs != NULL || nentries == 0);
1919 assert(considx >= -1);
1920 assert(considx < oracle->nconss);
1925 SCIPdebugMessage(
"change %d linear coefficients in cons %d\n", nentries, considx);
1929 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
1934 assert(cons->
linidxs == NULL);
1948 for( i = 0; i < nentries; ++i )
1950 assert(varidxs[i] >= 0);
1951 assert(varidxs[i] < oracle->nvars);
1955 SCIPdebugMessage(
"replace coefficient of var %d at pos %d by %g\n", varidxs[i], pos, newcoefs[i]);
1960 needsort |= (newcoefs[i] == 0.0);
1962 else if( newcoefs[i] != 0.0 )
1987 oracle->vardegreesuptodate &= (cons->
nlinidxs == oldlen);
1990 if( oracle->vardegreesuptodate )
1991 for( i = 0; i < cons->
nlinidxs; ++i )
1992 oracle->vardegrees[varidxs[i]] =
MAX(1, oracle->vardegrees[varidxs[i]]);
2012 assert(oracle != NULL);
2013 assert(quadelems != NULL || nquadelems == 0);
2014 assert(considx >= -1);
2015 assert(considx < oracle->nconss);
2017 if( nquadelems == 0 )
2022 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
2041 assert(quadelems[i].idx1 >= 0);
2042 assert(quadelems[i].idx2 >= 0);
2043 assert(quadelems[i].idx1 < oracle->nvars);
2044 assert(quadelems[i].idx2 < oracle->nvars);
2049 SCIPdebugMessage(
"replace coefficient of var%d*var%d at pos %d by %g\n", quadelems[i].idx1, quadelems[i].idx2, pos, quadelems[i].coef);
2054 needsort |= (quadelems[i].
coef == 0.0);
2059 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);
2082 oracle->vardegreesuptodate &= (cons->
nquadelems == oldsize);
2085 if( oracle->vardegreesuptodate )
2109 assert(oracle != NULL);
2110 assert(considx >= -1);
2111 assert(considx < oracle->nconss);
2112 assert((exprvaridxs != NULL) == (exprtree != NULL));
2117 cons = considx < 0 ? oracle->objective : oracle->conss[considx];
2124 oracle->vardegreesuptodate =
FALSE;
2128 if( exprtree == NULL )
2131 assert(oracle->exprinterpreter != NULL);
2141 if( oracle->vardegreesuptodate )
2146 oracle->vardegrees[cons->
exprvaridxs[j]] = INT_MAX;
2163 assert(oracle != NULL);
2164 assert(considx >= -1);
2165 assert(considx < oracle->nconss);
2166 assert(paramidx >= 0);
2167 assert(considx >= 0 || oracle->objective->exprtree != NULL);
2169 assert(considx == -1 || oracle->conss[considx]->exprtree != NULL);
2172 SCIPexprtreeSetParamVal(considx >= 0 ? oracle->conss[considx]->exprtree : oracle->objective->exprtree, paramidx, paramval);
2184 assert(oracle != NULL);
2188 oracle->objective->lhs = objconstant;
2189 oracle->objective->rhs = objconstant;
2199 assert(oracle != NULL);
2201 return oracle->
nvars;
2209 assert(oracle != NULL);
2219 assert(oracle != NULL);
2229 assert(oracle != NULL);
2239 assert(oracle != NULL);
2252 assert(oracle != NULL);
2253 assert(varidx >= 0);
2254 assert(varidx < oracle->nvars);
2268 assert(oracle != NULL);
2281 assert(oracle != NULL);
2282 assert(considx >= 0);
2283 assert(considx < oracle->nconss);
2285 return oracle->
conss[considx]->
lhs;
2294 assert(oracle != NULL);
2295 assert(considx >= 0);
2296 assert(considx < oracle->nconss);
2298 return oracle->
conss[considx]->
rhs;
2307 assert(oracle != NULL);
2308 assert(considx >= 0);
2309 assert(considx < oracle->nconss);
2324 assert(oracle != NULL);
2325 assert(considx >= -1);
2326 assert(considx < oracle->nconss);
2356 assert(oracle != NULL);
2363 for( i = 0; i < oracle->nvars; ++i )
2364 if( oracle->vardegrees[i] > maxdegree )
2366 maxdegree = oracle->vardegrees[i];
2367 if( maxdegree == INT_MAX )
2382 assert(oracle != NULL);
2389 for( c = 0; c < oracle->
nconss; ++c )
2393 return evalcapability;
2403 assert(oracle != NULL);
2409 assert(oracle->objective->lhs == oracle->objective->rhs);
2410 *objval += oracle->objective->lhs;
2423 assert(oracle != NULL);
2424 assert(x != NULL || oracle->
nvars == 0);
2425 assert(conval != NULL);
2445 assert(oracle != NULL);
2446 assert(x != NULL || oracle->nvars == 0);
2447 assert(convals != NULL);
2449 for( i = 0; i < oracle->nconss; ++i )
2469 assert(oracle != NULL);
2475 assert(oracle->objective->lhs == oracle->objective->rhs);
2476 *objval += oracle->objective->lhs;
2494 assert(oracle != NULL);
2495 assert(x != NULL || oracle->
nvars == 0);
2496 assert(conval != NULL);
2523 assert(oracle != NULL);
2527 if( oracle->jacoffsets != NULL )
2529 assert(oracle->jaccols != NULL);
2530 if( offset != NULL )
2531 *offset = oracle->jacoffsets;
2533 *col = oracle->jaccols;
2539 maxnnz = MIN(oracle->nvars, 10) * oracle->nconss;
2546 if( offset != NULL )
2547 *offset = oracle->jacoffsets;
2549 *col = oracle->jaccols;
2556 for( i = 0; i < oracle->nconss; ++i )
2558 oracle->jacoffsets[i] = nnz;
2560 cons = oracle->conss[i];
2561 assert(cons != NULL);
2598 for( j = 0; j < cons->
nlinidxs; ++j )
2615 for( j = 0; j < oracle->nvars; ++j )
2617 if( nzflag[j] ==
FALSE )
2621 oracle->jaccols[nnz] = j;
2626 oracle->jacoffsets[oracle->nconss] = nnz;
2636 if( offset != NULL )
2637 *offset = oracle->jacoffsets;
2639 *col = oracle->jaccols;
2671 assert(oracle != NULL);
2672 assert(jacobi != NULL);
2674 assert(oracle->jacoffsets != NULL);
2675 assert(oracle->jaccols != NULL);
2682 j = oracle->jacoffsets[0];
2684 for( i = 0; i < oracle->nconss; ++i )
2686 cons = oracle->conss[i];
2687 assert(cons != NULL);
2698 assert(j == oracle->jacoffsets[i+1]);
2710 assert(nvars <= oracle->nvars);
2722 for( l = 0; l < nvars; ++l )
2727 SCIPdebug(
if( isnewx ) {printf(
"\nx =");
for( l = 0; l < nvars; ++l) printf(
" %g", xx[l]); printf(
"\n");} )
2731 SCIPdebug( printf(
"g =");
for( l = 0; l < nvars; ++l) printf(
" %g", grad[l]); printf(
"\n"); )
2733 if( nlval != nlval || ABS(nlval) >= oracle->infinity )
2735 SCIPdebugMessage(
"gradient evaluation yield invalid function value %g\n", nlval);
2741 if( convals != NULL )
2743 for( l = 0; l < nvars; ++l )
2745 assert(oracle->jaccols[j+l] == cons->
exprvaridxs[l]);
2748 SCIPdebugMessage(
"gradient evaluation yield invalid gradient value %g\n", grad[l]);
2753 jacobi[k++] = grad[l];
2760 else if( convals != NULL )
2774 while( j < oracle->jacoffsets[i+1] )
2775 jacobi[k++] = grad[oracle->jaccols[j++]];
2804 assert(oracle != NULL);
2808 if( oracle->heslagoffsets != NULL )
2810 assert(oracle->heslagcols != NULL);
2811 if( offset != NULL )
2812 *offset = oracle->heslagoffsets;
2814 *col = oracle->heslagcols;
2828 if( oracle->objective->nquadelems != 0 )
2833 if( oracle->objective->exprtree != NULL )
2838 for( i = 0; i < oracle->nconss; ++i )
2840 if( oracle->conss[i]->nquadelems != 0 )
2845 if( oracle->conss[i]->exprtree != NULL )
2855 for( i = 0; i < oracle->nvars; ++i )
2857 oracle->heslagoffsets[i] = cnt;
2858 for( j = 0; j < colnnz[i]; ++j )
2861 oracle->heslagcols[cnt++] = colnz[i][j];
2866 oracle->heslagoffsets[oracle->nvars] = cnt;
2873 if( offset != NULL )
2874 *offset = oracle->heslagoffsets;
2876 *col = oracle->heslagcols;
2900 assert(oracle != NULL);
2902 assert(lambda != NULL || oracle->
nconss == 0);
2903 assert(hessian != NULL);
2910 for( i = oracle->heslagoffsets[oracle->nvars] - 1; i >= 0; --i )
2913 if( objfactor != 0.0 )
2915 SCIP_CALL(
hessLagAddQuad(objfactor, oracle->objective->nquadelems, oracle->objective->quadelems, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2916 SCIP_CALL_QUIET(
hessLagAddExprtree(oracle, objfactor, x, isnewx, oracle->objective->exprvaridxs, oracle->objective->exprtree, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2919 for( i = 0; i < oracle->nconss; ++i )
2921 assert( lambda != NULL );
2922 if( lambda[i] == 0.0 )
2924 SCIP_CALL(
hessLagAddQuad(lambda[i], oracle->conss[i]->nquadelems, oracle->conss[i]->quadelems, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2925 SCIP_CALL_QUIET(
hessLagAddExprtree(oracle, lambda[i], x, isnewx, oracle->conss[i]->exprvaridxs, oracle->conss[i]->exprtree, oracle->heslagoffsets, oracle->heslagcols, hessian) );
2942 assert(oracle != NULL);
2949 SCIPmessageFPrintInfo(messagehdlr, file,
"NLPI Oracle %s: %d variables and %d constraints\n", oracle->name ? oracle->name :
"", oracle->nvars, oracle->nconss);
2950 for( i = 0; i < oracle->nvars; ++i )
2952 if( oracle->varnames != NULL && oracle->varnames[i] != NULL )
2957 if( oracle->vardegreesuptodate )
2964 if( oracle->objective->lhs != 0.0 )
2968 for( i = 0; i < oracle->nconss; ++i )
2970 if( oracle->conss[i]->name != NULL )
2975 lhs = oracle->conss[i]->lhs;
2976 rhs = oracle->conss[i]->rhs;
2978 if( lhs > -oracle->infinity && rhs < oracle->
infinity && lhs != rhs )
2987 else if( lhs > -oracle->infinity )
3010 static const char* nllevelname[4] = {
"LP",
"QCP",
"NLP",
"DNLP" };
3018 assert(oracle != NULL);
3025 havelongvarnames =
FALSE;
3026 for( i = 0; i < oracle->nvars; ++i )
3027 if( oracle->varnames != NULL && oracle->varnames[i] != NULL && strlen(oracle->varnames[i]) > 9 )
3029 havelongvarnames =
TRUE;
3033 havelongequnames =
FALSE;
3034 for( i = 0; i < oracle->nconss; ++i )
3035 if( oracle->conss[i]->name && strlen(oracle->conss[i]->name) > 9 )
3037 havelongequnames =
TRUE;
3043 SCIPmessageFPrintInfo(messagehdlr, file,
"* NLPI Oracle Problem %s\n", oracle->name ? oracle->name :
"");
3045 for( i = 0; i < oracle->nvars; ++i )
3047 printName(namebuf, oracle->varnames != NULL ? oracle->varnames[i] : NULL, i,
'x', NULL, havelongvarnames);
3053 for( i = 0; i < oracle->nvars; ++i )
3056 name = oracle->varnames != NULL ? oracle->varnames[i] : NULL;
3057 if( oracle->varlbs[i] == oracle->varubs[i] )
3059 printName(namebuf, name, i,
'x', NULL, havelongvarnames);
3064 if( oracle->varlbs[i] > -oracle->infinity )
3066 printName(namebuf, name, i,
'x', NULL, havelongvarnames);
3069 if( oracle->varubs[i] < oracle->infinity )
3071 printName(namebuf, name, i,
'x', NULL, havelongvarnames);
3075 if( initval != NULL )
3077 printName(namebuf, name, i,
'x', NULL, havelongvarnames);
3085 for( i = 0; i < oracle->nconss; ++i )
3087 printName(namebuf, oracle->conss[i]->name, i,
'e', NULL, havelongequnames);
3090 if( oracle->conss[i]->lhs > -oracle->infinity && oracle->conss[i]->rhs < oracle->infinity && oracle->conss[i]->lhs != oracle->conss[i]->rhs )
3093 printName(namebuf, oracle->conss[i]->name, i,
'e',
"_RNG", havelongequnames);
3102 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->objective, havelongvarnames, havelongequnames) );
3103 if( oracle->objective->lhs != 0.0 )
3107 for( i = 0; i < oracle->nconss; ++i )
3112 printName(namebuf, oracle->conss[i]->name, i,
'e', NULL, havelongequnames);
3115 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->conss[i], havelongvarnames, havelongequnames) );
3117 lhs = oracle->conss[i]->lhs;
3118 rhs = oracle->conss[i]->rhs;
3124 else if( lhs > -oracle->infinity )
3130 if( lhs > -oracle->infinity && rhs < oracle->infinity && lhs != rhs )
3132 printName(namebuf, oracle->conss[i]->name, i,
'e',
"_RNG", havelongequnames);
3135 SCIP_CALL(
printFunction(oracle, messagehdlr, file, oracle->conss[i], havelongvarnames, havelongequnames) );
3140 if( nllevel <= 0 && oracle->conss[i]->
nquadelems > 0 )
3142 if( nllevel <= 1 && oracle->conss[i]->
exprtree != NULL )
3153 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 void printName(char *buffer, char *name, int idx, char prefix, const char *suffix, SCIP_Bool longnames)
int SCIPsnprintf(char *t, int len, const char *s,...)
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 evalFunctionGradient(SCIP_NLPIORACLE *oracle, SCIP_NLPIORACLECONS *cons, const SCIP_Real *x, SCIP_Bool isnewx, SCIP_Real *RESTRICT val, SCIP_Real *RESTRICT grad)
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)