506 int *A_rowstarts = NULL;
507 int *A_colptr = NULL;
508 double *A_nzelem = NULL;
510 std::ostringstream outStr;
516 osinstance->setInstanceDescription(
"Generated from AMPL nl file");
547 std::vector<int> fidxs, v1idxs, v2idxs;
548 std::vector<double> coeffs;
549 std::vector<Nl> nlExprs;
558 bool fill_in =
false;
560 if (nlvc > 0 || nlvo > 0)
568 for (osNLIdx = -nlo, aNLIdx = nlo-1; osNLIdx < 0; osNLIdx++, aNLIdx--)
570 if (nqpcheck(aNLIdx, &rowqp, &colqp, &delsqp) > 0)
572 for (
int v1 = 0; v1 < n_var; v1++)
574 for (
int* psV2 = (
int*)&rowqp[colqp[v1]]; psV2 < (
int*)&rowqp[colqp[v1+1]]; psV2++, delsqp++)
576 if (std::abs(*delsqp) >
OS_EPS)
578 fidxs.push_back(osNLIdx);
579 v1idxs.push_back(v1);
580 v2idxs.push_back(*psV2);
581 coeffs.push_back(0.5 * *delsqp);
589 expr* e = aNLIdx < 0 ?
CON_DE[osNLIdx].e :
OBJ_DE[aNLIdx].e;
598 nlExprs.push_back(nl);
605 double* A_row_temp =
new double[n_var];
607 for (osNLIdx = 0, aNLIdx = -1; osNLIdx < nlc; osNLIdx++, aNLIdx--)
614 for(cg = Cgrad[osNLIdx]; cg; cg = cg->next)
616 if (cg->coef != 0) A_row_temp[cg->varno] = cg->coef;
620 nqpchk = nqpcheck(aNLIdx, &rowqp, &colqp, &delsqp);
623 for (
int v1 = 0; v1 < n_var; v1++)
625 for (
int* psV2 = (
int*)&rowqp[colqp[v1]]; psV2 < (
int*)&rowqp[colqp[v1+1]]; psV2++, delsqp++)
627 if (std::abs(*delsqp) >
OS_EPS)
629 fidxs.push_back(osNLIdx);
630 v1idxs.push_back(v1);
631 v2idxs.push_back(*psV2);
632 coeffs.push_back(0.5 * *delsqp);
638 for(cg = Cgrad[osNLIdx]; cg; cg = cg->next)
641 if (cg->coef != A_row_temp[cg->varno])
650 if (nqpchk < 0) isQP =
false;
656 expr* e = aNLIdx < 0 ?
CON_DE[osNLIdx].e :
OBJ_DE[aNLIdx].e;
665 nlExprs.push_back(nl);
668 delete [] A_row_temp;
672 Nl** ppsNl =
new Nl*[ nlExprs.size() ];
673 for (
size_t k = 0; k < nlExprs.size(); k++)
675 ppsNl[k] =
new Nl(nlExprs[k]);
678 if (
osinstance->instanceData->nonlinearExpressions == NULL)
680 osinstance->instanceData->nonlinearExpressions->nl = ppsNl;
681 osinstance->instanceData->nonlinearExpressions->numberOfNonlinearExpressions = nlExprs.size();
685 osinstance->setQuadraticCoefficients((
int)fidxs.size(), &fidxs[0], &v1idxs[0], &v2idxs[0], &coeffs[0], 0, (
int)fidxs.size()-1);
697 double objWeight = 1.0;
702 for(i = 0; i < n_obj; i++)
705 for(
og = Ograd[i];
og;
og =
og->next)
707 if (
og->coef != 0) n_obj_coef++;
711 for(
og = Ograd[i];
og;
og =
og->next)
716 objectiveCoefficients->
values[i_obj_coef] =
og->coef;
717 objectiveCoefficients->
indexes[i_obj_coef] =
og->varno;
721 (objtype[i] == 1)?
"max":
"min",
722 objconst( i), objWeight, objectiveCoefficients) ;
723 delete objectiveCoefficients;
724 objectiveCoefficients = NULL;
732 double constant = 0.0;
734 for(i = 0; i < n_con; i++)
749 A_rowstarts =
new int[n_con+1];
751 for (
int i=0; i < n_con; i++)
754 for(cg = Cgrad[i]; cg; cg = cg->next)
756 if (cg->coef != 0) row_len++;
758 A_rowstarts[i+1] = A_rowstarts[i] + row_len;
760 A_colptr =
new int[A_rowstarts[n_con]];
761 A_nzelem =
new double[A_rowstarts[n_con]];
762 for (
int i=0; i < n_con; i++)
765 for(cg = Cgrad[i]; cg; cg = cg->next)
769 A_colptr[A_rowstarts[i]+row_len] = cg->varno;
770 A_nzelem[A_rowstarts[i]+row_len] = cg->coef;
776 if(A_rowstarts[ n_con] > 0)
778 osinstance->setLinearConstraintCoefficients(A_rowstarts[ n_con],
false,
779 A_nzelem, 0, A_rowstarts[n_con] - 1,
780 A_colptr, 0, A_rowstarts[n_con] - 1,
781 A_rowstarts, 0, n_con);
784 osinstance->instanceData->linearConstraintCoefficients->start->bDeleteArrays =
true;
785 osinstance->instanceData->linearConstraintCoefficients->colIdx->bDeleteArrays =
true;
786 osinstance->instanceData->linearConstraintCoefficients->value->bDeleteArrays =
true;
793 outStr <<
"A-matrix elements: ";
794 for (
int i = 0; i < A_rowstarts[ n_con]; i++)
795 outStr << A_nzelem[i] <<
" ";
797 outStr <<
"A-matrix col index: ";
798 for (
int i = 0; i < A_rowstarts[ n_con]; i++)
799 outStr << A_colptr[i] <<
" ";
801 outStr <<
"A-matrix rowstart: ";
802 for (
int i = 0; i <= n_con; i++)
803 outStr << A_rowstarts[i] <<
" ";
812 int colStart, colEnd, nCoefSqueezed;
818 outStr <<
"A-matrix elements: ";
819 for (
int i = 0; i < A_colstarts[ n_var]; i++)
820 outStr << A_vals[i] <<
" ";
822 outStr <<
"A-matrix rowinfo: ";
823 for (
int i = 0; i < A_colstarts[ n_var]; i++)
824 outStr << A_rownos[i] <<
" ";
826 outStr <<
"A-matrix colstart: ";
827 for (
int i = 0; i <= n_var; i++)
828 outStr << A_colstarts[i] <<
" ";
834 for (i = 0; i < n_var; i++)
837 colEnd = A_colstarts[i+1];
841 outStr <<
"col " << i <<
" from " << colStart <<
" to " << colEnd - 1 << endl;
844 for (j = colStart; j < colEnd; j++)
846 if (fabs(A_vals[ j]) >
OS_EPS)
848 A_vals[ j-nCoefSqueezed] = A_vals[ j];
849 A_rownos[ j-nCoefSqueezed] = A_rownos[j];
856 outStr <<
"squeeze out element " << j << endl;
862 A_colstarts[i+1] = A_colstarts[i+1] - nCoefSqueezed;
868 outStr <<
"A-matrix elements: ";
869 for (i = 0; i < A_colstarts[ n_var]; i++)
870 outStr << A_vals[i] <<
" ";
872 outStr <<
"A-matrix rowinfo: ";
873 for (i = 0; i < A_colstarts[ n_var]; i++)
874 outStr << A_rownos[i] <<
" ";
876 outStr <<
"A-matrix colstart: ";
877 for (i = 0; i <= n_var; i++)
878 outStr << A_colstarts[i] <<
" ";
880 outStr <<
"A-matrix nonzeroes: " << A_colstarts[ n_var] <<
"; nsqueezed: " << nCoefSqueezed << endl;
884 if(A_colstarts[ n_var] > 0)
886 osinstance->setLinearConstraintCoefficients(A_colstarts[ n_var],
true,
887 A_vals, 0, A_colstarts[n_var] - 1,
888 A_rownos, 0, A_colstarts[n_var] - 1,
889 A_colstarts, 0, n_var);
890 osinstance->instanceData->linearConstraintCoefficients->start->bDeleteArrays =
false;
891 osinstance->instanceData->linearConstraintCoefficients->rowIdx->bDeleteArrays =
false;
892 osinstance->instanceData->linearConstraintCoefficients->value->bDeleteArrays =
false;
909 int suffixType, nOther, nOtherIdx;
918 bool have_primal =
false;
919 for (i=0; i < n_var; i++)
928 bool have_dual =
false;
929 for (i=0; i < n_con; i++)
940 if ((
asl->i.suffixes[ASL_Sufkind_var] != NULL) ||
941 (
asl->i.suffixes[ASL_Sufkind_con] != NULL) ||
942 (
asl->i.suffixes[ASL_Sufkind_obj] != NULL) ||
943 (
asl->i.suffixes[ASL_Sufkind_prob] != NULL) ||
944 ( have_primal ) || ( have_dual ) )
967 std::string *otherOptionNames = NULL;
970 suffixType = ASL_Sufkind_var;
971 if ( (
asl->i.suffixes[suffixType] != NULL) )
977 osoption->optimization->variables != NULL &&
978 osoption->optimization->variables->numberOfOtherVariableOptions > 0)
980 otherOptionNames =
new std::string[
osoption->optimization->variables->numberOfOtherVariableOptions];
981 for (
int i=0; i <
osoption->optimization->variables->numberOfOtherVariableOptions; i++)
982 if (
osoption->optimization->variables->other[i]->numberOfVar > 0)
983 otherOptionNames[nOther++] =
osoption->optimization->variables->other[i]->name;
986 for (d=
asl->i.suffixes[suffixType]; d; d=d->next)
991 outStr <<
"Detected suffix " << d->sufname <<
"; kind = " << d->kind << std::endl;
996 if (strcmp(d->sufname,
"sstatus") == 0)
1022 outStr <<
"Original basis (in AMPL codes):";
1023 for (
int k=0; k<n_var; k++)
1024 outStr <<
" " << d->u.i[k];
1025 outStr << std::endl;
1032 osoption->optimization->variables != NULL &&
1033 osoption->optimization->variables->initialBasisStatus != NULL)
1041 IBS =
new int[nIndexes];
1044 for (
int k=0; k < nIndexes; k++)
1051 outStr <<
"After processing state " << i <<
":";
1052 for (
int k=0; k<n_var; k++)
1053 outStr <<
" " << d->u.i[k];
1054 outStr << std::endl;
1062 outStr <<
"Merged basis (in AMPL codes):";
1063 for (
int k=0; k<n_var; k++)
1064 outStr <<
" " << d->u.i[k];
1065 outStr << std::endl;
1078 for (
int k=0; k < n_var; k++)
1086 IBS2[i] =
new int[nidx[i]];
1090 for (
int k=0; k < n_var; k++)
1092 IBS2[d->u.i[k]][kidx[d->u.i[k]]++] = k;
1111 varopt->
name = d->sufname;
1118 for (iopt=0; iopt < nOther; iopt++)
1120 if (d->sufname == otherOptionNames[iopt])
1131 otherOption =
osoption->getOtherVariableOption(iopt);
1142 varopt->
description =
"combined from osol and .nl data";
1147 varopt->
description =
"transferred from .nl file";
1154 for (
int k=0; k < n_var; k++)
1159 varopt->
var[nOtherIdx]->
idx = k;
1169 for (
int k=0; k < n_var; k++)
1174 varopt->
var[nOtherIdx]->
idx = k;
1186 for (
int k=0; k <
osoption->optimization->variables->other[iopt]->numberOfVar; k++)
1187 delete osoption->optimization->variables->other[iopt]->var[k];
1188 delete []
osoption->optimization->variables->other[iopt]->var;
1189 osoption->optimization->variables->other[iopt]->var = varopt->
var;
1190 osoption->optimization->variables->other[iopt]->numberOfVar = nOtherIdx;
1196 if (!
osoption->setAnOtherVariableOption(varopt))
1197 throw ErrorClass(
"OSnl2OS: Error transfering suffixes on variables" );
1204 delete [] otherOptionNames;
1205 otherOptionNames = NULL;
1209 suffixType = ASL_Sufkind_con;
1210 if ( (
asl->i.suffixes[suffixType] != NULL) )
1216 osoption->optimization->constraints != NULL &&
1217 osoption->optimization->constraints->numberOfOtherConstraintOptions > 0)
1219 otherOptionNames =
new std::string[
osoption->optimization->constraints->numberOfOtherConstraintOptions];
1220 for (
int i=0; i <
osoption->optimization->constraints->numberOfOtherConstraintOptions; i++)
1221 if (
osoption->optimization->constraints->other[i]->numberOfCon > 0)
1222 otherOptionNames[nOther++] =
osoption->optimization->constraints->other[i]->name;
1225 for (d=
asl->i.suffixes[suffixType]; d; d=d->next)
1230 outStr <<
"Detected suffix " << d->sufname <<
"; kind = " << d->kind << std::endl;
1234 if (strcmp(d->sufname,
"sstatus") == 0)
1261 outStr <<
"Original basis (in AMPL codes):";
1262 for (
int k=0; k<n_con; k++)
1263 outStr <<
" " << d->u.i[k];
1264 outStr << std::endl;
1270 osoption->optimization->constraints != NULL &&
1271 osoption->optimization->constraints->initialBasisStatus != NULL)
1280 IBS =
new int[nIndexes];
1283 for (
int k=0; k < nIndexes; k++)
1290 outStr <<
"After processing state " << i <<
":";
1291 for (
int k=0; k<n_con; k++)
1292 outStr <<
" " << d->u.i[k];
1293 outStr << std::endl;
1301 outStr <<
"Merged basis (in AMPL codes):";
1302 for (
int k=0; k<n_con; k++)
1303 outStr <<
" " << d->u.i[k];
1304 outStr << std::endl;
1317 for (
int k=0; k < n_con; k++)
1325 IBS2[i] =
new int[nidx[i]];
1329 for (
int k=0; k < n_con; k++)
1331 IBS2[d->u.i[k]][kidx[d->u.i[k]]++] = k;
1350 conopt->
name = d->sufname;
1357 for (iopt=0; iopt < nOther; iopt++)
1359 if (d->sufname == otherOptionNames[iopt])
1370 otherOption =
osoption->getOtherConstraintOption(iopt);
1381 conopt->
description =
"combined from osol and .nl data";
1386 conopt->
description =
"transferred from .nl file";
1393 for (
int k=0; k < n_con; k++)
1398 conopt->
con[nOtherIdx]->
idx = k;
1408 for (
int k=0; k < n_con; k++)
1413 conopt->
con[nOtherIdx]->
idx = k;
1425 for (
int k=0; k <
osoption->optimization->constraints->other[iopt]->numberOfCon; k++)
1426 delete osoption->optimization->constraints->other[iopt]->con[k];
1427 delete []
osoption->optimization->constraints->other[iopt]->con;
1428 osoption->optimization->constraints->other[iopt]->con = conopt->
con;
1429 osoption->optimization->constraints->other[iopt]->numberOfCon = nOtherIdx;
1435 if (!
osoption->setAnOtherConstraintOption(conopt))
1436 throw ErrorClass(
"OSnl2OS: Error transfering suffixes on constraints" );
1443 delete [] otherOptionNames;
1444 otherOptionNames = NULL;
1448 suffixType = ASL_Sufkind_obj;
1449 if ( (
asl->i.suffixes[suffixType] != NULL) )
1455 osoption->optimization->objectives != NULL &&
1456 osoption->optimization->objectives->numberOfOtherObjectiveOptions > 0)
1458 otherOptionNames =
new std::string[
osoption->optimization->objectives->numberOfOtherObjectiveOptions];
1459 for (
int i=0; i <
osoption->optimization->objectives->numberOfOtherObjectiveOptions; i++)
1460 if (
osoption->optimization->objectives->other[i]->numberOfObj > 0)
1461 otherOptionNames[nOther++] =
osoption->optimization->objectives->other[i]->name;
1464 for (d=
asl->i.suffixes[suffixType]; d; d=d->next)
1469 outStr <<
"Detected suffix " << d->sufname <<
"; kind = " << d->kind << std::endl;
1476 objopt->
name = d->sufname;
1483 for (iopt=0; iopt < nOther; iopt++)
1485 if (d->sufname == otherOptionNames[iopt])
1496 otherOption =
osoption->getOtherObjectiveOption(iopt);
1507 d->u.i[-1 - otherOption->
obj[i]->
idx] = atoi(otherOption->
obj[i]->
value.c_str());
1510 objopt->
description =
"combined from osol and .nl data";
1515 objopt->
description =
"transferred from .nl file";
1522 for (
int k=0; k < n_obj; k++)
1527 objopt->
obj[nOtherIdx]->
idx = -1 - k;
1537 for (
int k=0; k < n_obj; k++)
1542 objopt->
obj[nOtherIdx]->
idx = -1 - k;
1554 for (
int k=0; k <
osoption->optimization->objectives->other[iopt]->numberOfObj; k++)
1555 delete osoption->optimization->objectives->other[iopt]->obj[k];
1556 delete []
osoption->optimization->objectives->other[iopt]->obj;
1557 osoption->optimization->objectives->other[iopt]->obj = objopt->
obj;
1558 osoption->optimization->objectives->other[iopt]->numberOfObj = nOtherIdx;
1564 if (!
osoption->setAnOtherObjectiveOption(objopt))
1565 throw ErrorClass(
"OSnl2OS: Error transfering suffixes on objectives" );
1571 delete [] otherOptionNames;
1572 otherOptionNames = NULL;
1577 suffixType = ASL_Sufkind_prob;
1578 if ( (
asl->i.suffixes[suffixType] != NULL) )
1580 std::string opttype, optvalue, optdesc;
1581 optdesc =
"transferred from .nl file";
1582 for (d=
asl->i.suffixes[suffixType]; d; d=d->next)
1587 outStr <<
"Detected suffix " << d->sufname <<
"; kind = " << d->kind << std::endl;
1598 opttype =
"integer";
1602 if (!
osoption->setAnotherSolverOption(d->sufname,optvalue,
"",
"",opttype,optdesc))
1603 throw ErrorClass(
"OSnl2OS: Error transfering problem-indexed suffixes" );
1612 osoption->optimization->variables != NULL &&
1613 osoption->optimization->variables->initialVariableValues != NULL &&
1614 osoption->optimization->variables->initialVariableValues->numberOfVar > 0)
1616 int n_prev =
osoption->optimization->variables->initialVariableValues->numberOfVar;
1617 for (
int i=0; i < n_prev; i++)
1618 havex0[
osoption->optimization->variables->initialVariableValues->var[i]->idx] = 0;
1623 for (
int i=0; i < n_var; i++)
1624 if (havex0[i] != 0) n_x0++;
1633 for (
int i=0; i < n_var; i++)
1638 x_init[n_x0]->
idx = i;
1639 x_init[n_x0]->
value = X0[i];
1646 throw ErrorClass(
"OSnl2OS: Error merging initial primal variable values" );
1648 for (
int i=0; i < n_x0; i++)
1660 osoption->optimization->constraints != NULL &&
1661 osoption->optimization->constraints->initialDualValues != NULL &&
1662 osoption->optimization->constraints->initialDualValues->numberOfCon > 0)
1664 int n_prev =
osoption->optimization->constraints->initialDualValues->numberOfCon;
1665 for (
int i=0; i < n_prev; i++)
1666 havepi0[
osoption->optimization->constraints->initialDualValues->con[i]->idx] = 0;
1671 for (
int i=0; i < n_con; i++)
1672 if (havepi0[i] != 0) n_pi0++;
1681 for (
int i=0; i < n_con; i++)
1683 if (havepi0[i] != 0)
1686 pi_init[n_pi0]->
idx = i;
1695 throw ErrorClass(
"OSnl2OS: Error merging initial dual variable values" );
1697 for (
int i=0; i < n_pi0; i++)