128 char* vartypes =
new char[gmoN(
gmo)];
129 std::string* varnames =
new std::string[gmoN(
gmo)];
130 for(i = 0; i < gmoN(
gmo); ++i)
132 switch (gmoGetVarTypeOne(
gmo, i))
146 gevLogStat(
gev,
"Error: Unsupported variable type.");
150 gmoGetVarNameOne(
gmo, i, buffer);
151 varnames[i] = buffer;
154 double* varlow =
new double[gmoN(
gmo)];
155 double* varup =
new double[gmoN(
gmo)];
156 gmoGetVarLower(
gmo, varlow);
157 gmoGetVarUpper(
gmo, varup);
167 if (gmoModelType(
gmo) == Proc_cns)
177 int* colidx =
new int[gmoObjNZ(
gmo)];
178 double* val =
new double[gmoObjNZ(
gmo)];
179 int* nlflag =
new int[gmoObjNZ(
gmo)];
180 int* dummy =
new int[gmoObjNZ(
gmo)];
182 if (gmoObjNZ(
gmo)) nlflag[0] = 0;
183 gmoGetObjSparse(
gmo, colidx, val, nlflag, dummy, dummy);
184 for (i = 0, j = 0; i < gmoObjNZ(
gmo); ++i)
186 if (nlflag[i])
continue;
187 objectiveCoefficients->
indexes[j] = colidx[i];
188 objectiveCoefficients->
values[j] = val[i];
190 assert(j <= gmoObjNZ(
gmo) - gmoObjNLNZ(
gmo));
192 assert(j == gmoObjNZ(
gmo) - gmoObjNLNZ(
gmo));
199 std::string objname =
"objective";
202 delete objectiveCoefficients;
205 delete objectiveCoefficients;
211 for (i = 0; i < gmoM(
gmo); ++i)
213 switch (gmoGetEquTypeOne(
gmo, i))
216 lb = ub = gmoGetRhsOne(
gmo, i);
220 ub = gmoGetRhsOne(
gmo, i);
223 lb = gmoGetRhsOne(
gmo, i);
231 gevLogStat(
gev,
"Error: Unknown row type. Exiting ...");
235 gmoGetEquNameOne(
gmo, i, buffer);
242 double* values =
new double[nz];
243 int* colstarts =
new int[gmoN(
gmo)+1];
244 int* rowindexes =
new int[nz];
245 int* nlflags =
new int[nz];
247 gmoGetMatrixCol(
gmo, colstarts, rowindexes, values, nlflags);
250 colstarts[gmoN(
gmo)] = nz;
253 for (
int col = 0; col < gmoN(
gmo); ++col)
255 colstarts[col+1] -= shift;
256 int k = colstarts[col];
257 while (k < colstarts[col+1])
259 values[k] = values[k+shift];
260 rowindexes[k] = rowindexes[k+shift];
261 if (nlflags[k+shift])
277 colstarts, 0, gmoN(
gmo)))
286 if (!gmoObjNLNZ(
gmo) && !gmoNLNZ(
gmo))
293 int* opcodes =
new int[gmoMaxSingleFNL(
gmo)+1];
294 int* fields =
new int[gmoMaxSingleFNL(
gmo)+1];
295 int constantlen = gmoNLConst(
gmo);
296 double* constants = (
double*)gmoPPool(
gmo);
302 std::clog <<
"parsing nonlinear objective instructions" << std::endl;
303 gmoDirtyGetObjFNLInstr(
gmo, &codelen, opcodes, fields);
306 if (!nl)
return false;
308 double objjacval = gmoObjJacVal(
gmo);
309 std::clog <<
"obj jac val: " << objjacval << std::endl;
316 else if (objjacval != -1.)
319 numbernode->
value = -1/objjacval;
325 assert(iNLidx < osinstance->instanceData->nonlinearExpressions->numberOfNonlinearExpressions);
333 for (i = 0; i < gmoM(
gmo); ++i)
335 if (gmoDirtyGetRowFNLInstr(
gmo, i, &codelen, opcodes, fields))
337 std::clog <<
"got nonzero return at constraint " << i << std::endl;
339 if (!codelen)
continue;
342 if (!nl)
return false;
343 assert(iNLidx < osinstance->instanceData->nonlinearExpressions->numberOfNonlinearExpressions);
364 std::vector<OSnLNode*> nlNodeVec;
366 const bool debugoutput =
false;
371 nlNodeVec.reserve(codelen);
373 for (
int i=0; i<codelen; ++i)
375 GamsOpCode opcode = (GamsOpCode)opcodes[i];
376 int address = fields[i]-1;
378 if (debugoutput) std::clog <<
'\t' << GamsOpCodeName[opcode] <<
": ";
387 if (debugoutput) std::clog <<
"ignored" << std::endl;
392 address = gmoGetjSolver(
gmo, address);
396 nlNodeVec.push_back( nlNode );
401 if (debugoutput) std::clog <<
"push constant " << constants[address] << std::endl;
403 nlNode->
value = constants[address];
404 nlNodeVec.push_back( nlNode );
409 if (debugoutput) std::clog <<
"ignored" << std::endl;
414 if (debugoutput) std::clog <<
"add" << std::endl;
420 address = gmoGetjSolver(
gmo, address);
424 nlNodeVec.push_back( nlNode );
430 if (debugoutput) std::clog <<
"add constant " << constants[address] << std::endl;
432 nlNode->
value = constants[address];
433 nlNodeVec.push_back( nlNode );
439 if (debugoutput) std::clog <<
"minus" << std::endl;
445 address = gmoGetjSolver(
gmo, address);
449 nlNodeVec.push_back( nlNode );
455 if (debugoutput) std::clog <<
"substract constant " << constants[address] << std::endl;
457 nlNode->
value = constants[address];
458 nlNodeVec.push_back( nlNode );
464 if (debugoutput) std::clog <<
"multiply" << std::endl;
470 address = gmoGetjSolver(
gmo, address);
474 nlNodeVec.push_back( nlNode );
480 if (debugoutput) std::clog <<
"multiply constant " << constants[address] << std::endl;
482 nlNode->
value = constants[address];
483 nlNodeVec.push_back( nlNode );
489 if (debugoutput) std::clog <<
"divide" << std::endl;
495 address = gmoGetjSolver(
gmo, address);
499 nlNodeVec.push_back( nlNode );
505 if (debugoutput) std::clog <<
"divide constant " << constants[address] << std::endl;
507 nlNode->
value = constants[address];
508 nlNodeVec.push_back( nlNode );
514 if (debugoutput) std::clog <<
"negate" << std::endl;
520 address = gmoGetjSolver(
gmo, address);
523 nlNode->
idx = address;
525 nlNodeVec.push_back( nlNode );
532 if (debugoutput) std::clog <<
"call function ";
533 GamsFuncCode func = GamsFuncCode(address+1);
538 if (debugoutput) std::clog <<
"min" << std::endl;
544 if (debugoutput) std::clog <<
"max" << std::endl;
550 if (debugoutput) std::clog <<
"square" << std::endl;
558 if (debugoutput) std::clog <<
"exp" << std::endl;
564 if (debugoutput) std::clog <<
"ln" << std::endl;
572 if (debugoutput) std::clog <<
"log10 = ln * 1/ln(10)" << std::endl;
575 nlNode->
value = 1./log(10.);
576 nlNodeVec.push_back( nlNode );
582 if (debugoutput) std::clog <<
"log2 = ln * 1/ln(2)" << std::endl;
585 nlNode->
value = 1./log(2.);
586 nlNodeVec.push_back( nlNode );
592 if (debugoutput) std::clog <<
"sqrt" << std::endl;
598 if (debugoutput) std::clog <<
"abs" << std::endl;
604 if (debugoutput) std::clog <<
"cos" << std::endl;
610 if (debugoutput) std::clog <<
"sin" << std::endl;
619 if (debugoutput) std::clog <<
"power" << std::endl;
625 if (debugoutput) std::clog <<
"pi" << std::endl;
638 if (debugoutput) std::clog <<
"divide" << std::endl;
642 nlNodeVec.push_back( nlNode );
700 if (debugoutput) std::cerr <<
"nr. " << func <<
" - unsupported. Error." << std::endl;
708 if (debugoutput) std::clog <<
"multiply constant " << constants[address] <<
" and add " << std::endl;
710 nlNode->
value = constants[address];
711 nlNodeVec.push_back( nlNode );
718 if (debugoutput) std::clog <<
"ignored" << std::endl;
723 if (debugoutput) std::clog <<
"ignored" << std::endl;
728 if (debugoutput) std::clog <<
"ignored" << std::endl;
733 if (debugoutput) std::clog <<
"push constant zero" << std::endl;
739 if (debugoutput) std::clog <<
"ignored" << std::endl;
759 std::cerr <<
"not supported - Error." << std::endl;
765 if (!nlNodeVec.size())
return NULL;
bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
set linear constraint coefficients