00001
00022 #include <iostream>
00023 #include "OSiLWriter.h"
00024 #include "OSnl2osil.h"
00025 #include "OSErrorClass.h"
00026
00027 #include "CoinHelperFunctions.hpp"
00028
00029
00030 #include "nlp.h"
00031 #include "getstub.h"
00032 #include "r_opn.hd"
00033 #include "opcode.hd"
00034
00035
00036 #ifdef HAVE_CMATH
00037 # include <cmath>
00038 #else
00039 # ifdef HAVE_CMATH_H
00040 # include <cmath.h>
00041 # endif
00042 #endif
00043
00044 #include <sstream>
00045
00046
00047 #define R_OPS ((ASL_fg*)asl)->I.r_ops_
00048 #define OBJ_DE ((ASL_fg*)asl)->I.obj_de_
00049 #define VAR_E ((ASL_fg*)asl)->I.var_e_
00050 #define CON_DE ((ASL_fg*)asl)->I.con_de_
00051
00052
00053 #include <asl.h>
00054
00055 using std::cerr;
00056 using std::cout;
00057 using std::endl;
00058
00059 #ifdef HAVE_STDINT_H
00060 #include <stdint.h>
00061 #endif
00062
00063
00064
00065
00066
00067 OSnl2osil::OSnl2osil(std::string nlfilename)
00068 : osinstance(0), stub(nlfilename)
00069 {
00070 efunc *r_ops_int[N_OPS];
00071 FILE *nl;
00072
00073
00074 asl = cw = ASL_alloc( ASL_read_fg);
00075
00076
00077 nl = jac0dim(const_cast<char*>(stub.c_str()), (fint)stub.length());
00078
00079
00080 A_vals = (real *)Malloc(nzc*sizeof(real));
00081
00082 #ifdef AMPLDEBUG
00083 cout << "number of nonzeros = " << nzc << endl;
00084 cout << "number of variable = " << n_var << endl;
00085 cout << "number of constraints = " << n_con << endl;
00086 cout << "number of objs = " << n_obj << endl;
00087 cout << "number of ranges = " << nranges << endl;
00088 cout << "number of equations = " << n_eqn << endl;
00089
00090 #endif
00091 if(N_OPS > 0)
00092 {
00093 for(int i = 0; i < N_OPS; i++)
00094 {
00095 r_ops_int[i] = (efunc*)(unsigned long)i;
00096 }
00097 R_OPS = r_ops_int;
00098 want_derivs = 0;
00099 fg_read(nl, 0);
00100 R_OPS = 0;
00101 }
00102
00103
00104 asl = rw = ASL_alloc( ASL_read_fg);
00105 nl = jac0dim((char*)stub.c_str(), (fint)stub.length());
00106 want_derivs = 0;
00107 qp_read(nl, 0);
00108
00109 asl = cw;
00110 numkount = 0;
00111 }
00112
00113 OSnl2osil::~OSnl2osil()
00114 {
00115 delete osinstance;
00116 osinstance = NULL;
00117
00118 free( A_vals);
00119 ASL_free(&cw);
00120 ASL_free(&rw);
00121 }
00122
00123 OSnLNode* OSnl2osil::walkTree (expr *e)
00124 {
00125 OSnLNode *nlNodePoint;
00126 OSnLNodeVariable *nlNodeVariablePoint;
00127 OSnLNodeNumber *nlNodeNumberPoint;
00128 efunc *op;
00129 expr **ep;
00130 int opnum;
00131 int i;
00132
00133 int j = ((expr_v *)e - VAR_E) - osinstance->getVariableNumber() ;
00134
00135 op = e->op;
00136 opnum = Intcast op;
00137
00138
00139 try
00140 {
00141 switch( opnum)
00142 {
00143 case OPPLUS:
00144
00145 nlNodePoint = new OSnLNodePlus();
00146 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00147 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00148 op_type.push_back( "PLUS");
00149 return nlNodePoint;
00150
00151 case OPSUMLIST:
00152 i = 0;
00153
00154 nlNodePoint = new OSnLNodeSum();
00155 nlNodePoint->inumberOfChildren = e->R.ep - e->L.ep;
00156 nlNodePoint->m_mChildren = new OSnLNode*[ e->R.ep - e->L.ep];
00157 for (ep = e->L.ep; ep < e->R.ep; *ep++)
00158 nlNodePoint->m_mChildren[i++] = walkTree ( *ep);
00159 return nlNodePoint;
00160
00161 case MAXLIST:
00162 i = 0;
00163
00164 nlNodePoint = new OSnLNodeMax();
00165 nlNodePoint->inumberOfChildren = e->R.ep - e->L.ep;
00166 nlNodePoint->m_mChildren = new OSnLNode*[ e->R.ep - e->L.ep];
00167 for (ep = e->L.ep; ep < e->R.ep; *ep++)
00168 nlNodePoint->m_mChildren[i++] = walkTree ( *ep);
00169 return nlNodePoint;
00170
00171 case OPMINUS:
00172 nlNodePoint = new OSnLNodeMinus();
00173
00174 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00175 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00176 op_type.push_back( "MINUS");
00177
00178 return nlNodePoint;
00179
00180 case OPUMINUS:
00181 nlNodePoint = new OSnLNodeNegate();
00182 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00183 return nlNodePoint;
00184
00185 case OPMULT:
00186
00187 nlNodePoint = new OSnLNodeTimes();
00188 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00189 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00190 op_type.push_back( "TIMES");
00191 return nlNodePoint;
00192
00193 case OPDIV:
00194 nlNodePoint = new OSnLNodeDivide();
00195 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00196 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00197 return nlNodePoint;
00198
00199 case OPPOW:
00200
00201 nlNodePoint = new OSnLNodePower();
00202 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00203 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00204 op_type.push_back( "POWER");
00205 return nlNodePoint;
00206
00207
00208 case OP1POW:
00209
00210
00211 nlNodePoint = new OSnLNodePower();
00212
00213
00214 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00215 nlNodeNumberPoint = new OSnLNodeNumber();
00216 nlNodeNumberPoint->value = e->R.en->v;
00217 nlNodePoint->m_mChildren[1] = nlNodeNumberPoint;
00218
00219 op_type.push_back( "NUMBER");
00220 op_type.push_back( os_dtoa_format( numkount) );
00221 operand.push_back( e->R.en->v );
00222 numkount++;
00223
00224 op_type.push_back( "POWER");
00225
00226
00227 return nlNodePoint;
00228
00229 case OP2POW:
00230
00231
00232
00233
00234
00235
00236 nlNodePoint = new OSnLNodeSquare();
00237
00238 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00239 op_type.push_back( "SQUARE");
00240 return nlNodePoint;
00241
00242 case OPCPOW:
00243
00244
00245 nlNodePoint = new OSnLNodePower();
00246 nlNodeNumberPoint = new OSnLNodeNumber();
00247 nlNodeNumberPoint->value = e->L.en->v;
00248 nlNodePoint->m_mChildren[0] = nlNodeNumberPoint;
00249 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00250 return nlNodePoint;
00251
00252 case OP_log:
00253 nlNodePoint = new OSnLNodeLn();
00254 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00255 op_type.push_back( "LOG");
00256 return nlNodePoint;
00257
00258 case OP_sqrt:
00259 nlNodePoint = new OSnLNodeSqrt();
00260 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00261 return nlNodePoint;
00262
00263 case OP_cos:
00264 nlNodePoint = new OSnLNodeCos();
00265 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00266 return nlNodePoint;
00267
00268 case OP_sin:
00269 nlNodePoint = new OSnLNodeSin();
00270 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00271 return nlNodePoint;
00272
00273 case OP_exp:
00274 nlNodePoint = new OSnLNodeExp();
00275 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00276 return nlNodePoint;
00277
00278 case ABS:
00279 nlNodePoint = new OSnLNodeAbs();
00280 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00281 return nlNodePoint;
00282
00283 case OPNUM:
00284
00285 nlNodeNumberPoint = new OSnLNodeNumber;
00286
00287 nlNodeNumberPoint->value = (double) ((expr_n*)e)->v;
00288 op_type.push_back( "NUMBER");
00289 op_type.push_back( os_dtoa_format( numkount ) );
00290
00291 operand.push_back( (double) ((expr_n*)e)->v );
00292 numkount++;
00293
00294
00295 return nlNodeNumberPoint;
00296
00297 case OPVARVAL:
00298
00299
00300 if( j >= 0 )
00301 {
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 if(j < ncom0)
00315 {
00316 struct cexp *common = ((const ASL_fg *) asl) -> I.cexps_ + j ;
00317
00318
00319
00320 int nlin = common -> nlin;
00321
00322
00323 if( nlin > 0)
00324 {
00325 nlNodePoint = new OSnLNodeSum();
00326 nlNodePoint->inumberOfChildren = nlin + 1;
00327 nlNodePoint->m_mChildren = new OSnLNode*[ nlin + 1];
00328
00329
00330 linpart *L = common -> L;
00331 for(int kj = 0; kj < nlin; kj++)
00332 {
00333
00334
00335
00336
00337
00338
00339
00340 nlNodePoint->m_mChildren[ kj] = new OSnLNodeVariable;
00341 nlNodeVariablePoint = (OSnLNodeVariable*)nlNodePoint->m_mChildren[ kj];
00342 nlNodeVariablePoint->coef = L [kj]. fac;
00343 nlNodeVariablePoint->idx = ((uintptr_t) (L [kj].v.rp) - (uintptr_t) VAR_E) / sizeof (expr_v);
00344 }
00345 nlNodePoint->m_mChildren[ nlin] = walkTree( common->e);
00346 return nlNodePoint;
00347 }
00348 else return walkTree( common->e);
00349 }
00350 else
00351 {
00352 struct cexp1 *common = ((const ASL_fg *) asl) -> I.cexps1_ + (j - ncom0);
00353
00354
00355
00356 int nlin = common -> nlin;
00357
00358
00359 if( nlin > 0)
00360 {
00361 nlNodePoint = new OSnLNodeSum();
00362 nlNodePoint->inumberOfChildren = nlin + 1;
00363 nlNodePoint->m_mChildren = new OSnLNode*[ nlin + 1];
00364
00365
00366 linpart *L = common -> L;
00367 for(int kj = 0; kj < nlin; kj++)
00368 {
00369
00370
00371
00372
00373
00374
00375
00376 nlNodePoint->m_mChildren[ kj] = new OSnLNodeVariable;
00377 nlNodeVariablePoint = (OSnLNodeVariable*)nlNodePoint->m_mChildren[ kj];
00378 nlNodeVariablePoint->coef = L [kj]. fac;
00379 nlNodeVariablePoint->idx = ((uintptr_t) (L [kj].v.rp) - (uintptr_t) VAR_E) / sizeof (expr_v);
00380 }
00381 nlNodePoint->m_mChildren[ nlin] = walkTree( common->e);
00382 return nlNodePoint;
00383 }
00384 else return walkTree( common->e);
00385 }
00386 }
00387
00388 nlNodeVariablePoint = new OSnLNodeVariable;
00389 nlNodeVariablePoint->idx = e->a;
00390 nlNodeVariablePoint->coef = 1.0;
00391
00392 op_type.push_back( "VARIABLE");
00393 op_type.push_back( os_dtoa_format( e->a ) );
00394
00395
00396 return nlNodeVariablePoint;
00397 break;
00398 default:
00399 std::ostringstream outStr;
00400 std::string error;
00401 outStr << endl;
00402 outStr << endl;
00403 error = "ERROR: An unsupported operator found, AMPL operator number = " ;
00404 outStr << error;
00405 outStr << opnum;
00406 outStr << endl;
00407 error = outStr.str();
00408 throw ErrorClass( error );
00409 }
00410 }
00411 catch(const ErrorClass& eclass)
00412 {
00413 throw;
00414 }
00415 }
00416
00417 static inline char integerOrBinary(real upper, real lower)
00418 {
00419 if (lower > -1.0 + OS_EPS && upper < 2.0 - OS_EPS)
00420 return 'B';
00421 return 'I';
00422 }
00423
00424 bool OSnl2osil::createOSInstance()
00425 {
00426 osinstance = new OSInstance();
00427 int i, j;
00428
00429
00430
00431 osinstance->setInstanceDescription("Generated from AMPL nl file");
00432
00433
00434
00435
00436
00437 std::string colName;
00438 char vartype = 'C';
00439 osinstance->setVariableNumber( n_var);
00440
00441
00442
00443
00444
00445
00446
00447 int lower;
00448 int upper;
00449 lower = 0;
00450 upper = nlvb - nlvbi;
00451 #ifdef AMPLDEBUG
00452 std::cout << "LOWER = " << lower << std::endl;
00453 std::cout << "UPPER = " << upper << std::endl;
00454 #endif
00455 for(i = lower; i < upper; i++)
00456 {
00457 vartype = 'C';
00458 osinstance->addVariable(i, var_name(i),
00459 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00460 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00461 vartype);
00462 }
00463
00464 lower = nlvb - nlvbi;
00465 upper = (nlvb - nlvbi) + nlvbi;
00466 upper = nlvb;
00467 #ifdef AMPLDEBUG
00468 std::cout << "LOWER = " << lower << std::endl;
00469 std::cout << "UPPER = " << upper << std::endl;
00470 #endif
00471 for(i = lower; i < upper; i++)
00472 {
00473 vartype = integerOrBinary(LUv[2*i], LUv[2*i+1]);
00474 osinstance->addVariable(i, var_name(i),
00475 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00476 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00477 vartype);
00478 }
00479
00480 lower = nlvb;
00481 upper = nlvb + (nlvc - (nlvb + nlvci)) ;
00482 upper = nlvc - nlvci;
00483 #ifdef AMPLDEBUG
00484 std::cout << "LOWER = " << lower << std::endl;
00485 std::cout << "UPPER = " << upper << std::endl;
00486 #endif
00487 for(i = lower; i < upper; i++)
00488 {
00489 vartype = 'C';
00490 osinstance->addVariable(i, var_name(i),
00491 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00492 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00493 vartype);
00494 }
00495
00496
00497 lower = nlvc - nlvci;
00498 upper = nlvc - nlvci + nlvci;
00499 upper = nlvc;
00500 #ifdef AMPLDEBUG
00501 std::cout << "LOWER = " << lower << std::endl;
00502 std::cout << "UPPER = " << upper << std::endl;
00503 #endif
00504 for(i = lower; i < upper; i++)
00505 {
00506 vartype = integerOrBinary(LUv[2*i], LUv[2*i+1]);
00507 osinstance->addVariable(i, var_name(i),
00508 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00509 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00510 vartype);
00511 }
00512
00513 lower = nlvc;
00514 upper = nlvc + ( nlvo - (nlvc + nlvoi) );
00515 upper = nlvo - nlvoi;
00516 #ifdef AMPLDEBUG
00517 std::cout << "LOWER = " << lower << std::endl;
00518 std::cout << "UPPER = " << upper << std::endl;
00519 #endif
00520 for(i = lower; i < upper; i++)
00521 {
00522 vartype = 'C';
00523 osinstance->addVariable(i, var_name(i),
00524 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00525 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00526 vartype);
00527 }
00528
00529 lower = nlvo - nlvoi;
00530 upper = nlvo - nlvoi + nlvoi;
00531 upper = nlvo ;
00532 #ifdef AMPLDEBUG
00533 std::cout << "LOWER = " << lower << std::endl;
00534 std::cout << "UPPER = " << upper << std::endl;
00535 #endif
00536 for(i = lower; i < upper; i++)
00537 {
00538 vartype = integerOrBinary(LUv[2*i], LUv[2*i+1]);
00539 osinstance->addVariable(i, var_name(i),
00540 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00541 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00542 vartype);
00543 }
00544
00545
00546
00547
00548 lower = CoinMax(nlvc, nlvo);
00549 upper = CoinMax(nlvc, nlvo) + nwv;
00550 #ifdef AMPLDEBUG
00551 std::cout << "LOWER = " << lower << std::endl;
00552 std::cout << "UPPER = " << upper << std::endl;
00553 #endif
00554 for(i = lower; i < upper; i++)
00555 {
00556 vartype = 'C';
00557 osinstance->addVariable(i, var_name(i),
00558 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00559 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00560 vartype);
00561 }
00562
00563
00564 lower = CoinMax(nlvc, nlvo) + nwv;
00565 upper = CoinMax(nlvc, nlvo) + nwv + (n_var - (CoinMax(nlvc, nlvo) + niv + nbv + nwv) );
00566 upper = n_var - niv - nbv;
00567 #ifdef AMPLDEBUG
00568 std::cout << "LOWER = " << lower << std::endl;
00569 std::cout << "UPPER = " << upper << std::endl;
00570 #endif
00571 for(i = lower; i < upper; i++)
00572 {
00573 vartype = 'C';
00574 osinstance->addVariable(i, var_name(i),
00575 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00576 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00577 vartype);
00578 }
00579
00580
00581 lower = n_var - niv - nbv;
00582 upper = n_var - niv - nbv + nbv;
00583 upper = n_var - niv ;
00584 #ifdef AMPLDEBUG
00585 std::cout << "LOWER = " << lower << std::endl;
00586 std::cout << "UPPER = " << upper << std::endl;
00587 #endif
00588 for(i = lower; i < upper; i++)
00589 {
00590 vartype = 'B';
00591 osinstance->addVariable(i, var_name(i),
00592 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00593 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00594 vartype);
00595 }
00596
00597
00598
00599 lower = n_var - niv;
00600 upper = n_var - niv + niv;
00601 upper = n_var;
00602 #ifdef AMPLDEBUG
00603 std::cout << "LOWER = " << lower << std::endl;
00604 std::cout << "UPPER = " << upper << std::endl;
00605 #endif
00606 for(i = lower; i < upper; i++)
00607 {
00608 vartype = 'I';
00609 osinstance->addVariable(i, var_name(i),
00610 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00611 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00612 vartype);
00613 }
00614
00615
00616
00617
00618
00619
00620
00621 double objWeight = 1.0;
00622
00623 SparseVector* objectiveCoefficients = NULL;
00624
00625 osinstance->setObjectiveNumber( n_obj) ;
00626 for(i = 0; i < n_obj; i++)
00627 {
00628 int n_obj_coef = 0;
00629 for(og = Ograd[i]; og; og = og->next)
00630 {
00631 if (og->coef != 0) n_obj_coef++;
00632 }
00633 objectiveCoefficients = new SparseVector( n_obj_coef);
00634 int i_obj_coef = -1;
00635 for(og = Ograd[i]; og; og = og->next)
00636 {
00637 if (fabs(og->coef) > OS_EPS)
00638 {
00639 i_obj_coef++;
00640 objectiveCoefficients->values[i_obj_coef] = og->coef;
00641 objectiveCoefficients->indexes[i_obj_coef] = og->varno;
00642 }
00643 }
00644 osinstance->addObjective(-i-1, obj_name(i),
00645 (objtype[i] == 1)?"max":"min",
00646 objconst( i), objWeight, objectiveCoefficients) ;
00647 delete objectiveCoefficients;
00648 objectiveCoefficients = NULL;
00649 }
00650
00651
00652
00653 osinstance->setConstraintNumber( n_con);
00654
00655 double constant = 0.0;
00656 std::string rowName;
00657 for(i = 0; i < n_con; i++)
00658 {
00659 osinstance->addConstraint(i, con_name(i),
00660 LUrhs[2*i] > -OSDBL_MAX ? LUrhs[2*i] : -OSDBL_MAX,
00661 LUrhs[2*i+1] < OSDBL_MAX ? LUrhs[2*i+1] : OSDBL_MAX,
00662 constant);
00663 }
00664
00665
00666
00667 int colStart, colEnd, nCoefSqueezed;
00668 nCoefSqueezed = 0;
00669
00670 #ifdef AMPLDEBUG
00671 cout << "A-matrix elements: ";
00672 for (i = 0; i < A_colstarts[ n_var]; i++)
00673 cout << A_vals[i] << " ";
00674 cout << endl;
00675 cout << "A-matrix rowinfo: ";
00676 for (i = 0; i < A_colstarts[ n_var]; i++)
00677 cout << A_rownos[i] << " ";
00678 cout << endl;
00679 cout << "A-matrix colstart: ";
00680 for (i = 0; i <= n_var; i++)
00681 cout << A_colstarts[i] << " ";
00682 cout << endl;
00683 #endif
00684
00685 colEnd = 0;
00686 for (i = 0; i < n_var; i++)
00687 {
00688 colStart = colEnd;
00689 colEnd = A_colstarts[i+1];
00690 #ifdef AMPLDEBUG
00691 cout << "col " << i << " from " << colStart << " to " << colEnd - 1 << endl;
00692 #endif
00693 for (j = colStart; j < colEnd; j++)
00694 {
00695 if (fabs(A_vals[ j]) > OS_EPS)
00696 {
00697 A_vals[ j-nCoefSqueezed] = A_vals[ j];
00698 A_rownos[ j-nCoefSqueezed] = A_rownos[j];
00699 }
00700 else
00701 {
00702 #ifdef AMPLDEBUG
00703 cout << "squeeze out element " << j << endl;
00704 #endif
00705 nCoefSqueezed++;
00706 }
00707 }
00708 A_colstarts[i+1] = A_colstarts[i+1] - nCoefSqueezed;
00709 }
00710
00711 #ifdef AMPLDEBUG
00712 cout << "A-matrix elements: ";
00713 for (i = 0; i < A_colstarts[ n_var]; i++)
00714 cout << A_vals[i] << " ";
00715 cout << endl;
00716 cout << "A-matrix rowinfo: ";
00717 for (i = 0; i < A_colstarts[ n_var]; i++)
00718 cout << A_rownos[i] << " ";
00719 cout << endl;
00720 cout << "A-matrix colstart: ";
00721 for (i = 0; i <= n_var; i++)
00722 cout << A_colstarts[i] << " ";
00723 cout << endl;
00724 cout << "A-matrix nonzeroes: " << A_colstarts[ n_var] << "; nsqueezed: " << nCoefSqueezed << endl;
00725 #endif
00726
00727 if(A_colstarts[ n_var] > 0)
00728 {
00729 osinstance->setLinearConstraintCoefficients(A_colstarts[ n_var], true,
00730 A_vals, 0, A_colstarts[n_var] - 1,
00731 A_rownos, 0, A_colstarts[n_var] - 1,
00732 A_colstarts, 0, n_var);
00733 osinstance->instanceData->linearConstraintCoefficients->start->bDeleteArrays = false;
00734 osinstance->instanceData->linearConstraintCoefficients->rowIdx->bDeleteArrays = false;
00735 osinstance->instanceData->linearConstraintCoefficients->value->bDeleteArrays = false;
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 if((nlc + nlo) > 0)
00763 {
00764 OSnLNode* m_treeRoot;
00765
00766
00767 osinstance->instanceData->nonlinearExpressions->numberOfNonlinearExpressions = nlc + nlo;
00768 osinstance->instanceData->nonlinearExpressions->nl = new Nl*[ nlc + nlo ];
00769 int iNLidx = 0;
00770 std::cout << "WALK THE TREE FOR NONLINEAR CONSTRAINT TERMS: " << nlc << std::endl;
00771
00772
00773 if(nlc > 0)
00774 {
00775 while (iNLidx < nlc)
00776 {
00777 m_treeRoot = walkTree ((CON_DE + iNLidx)->e);
00778 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx] = new Nl();
00779 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->idx = iNLidx;
00780 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree = new OSExpressionTree();
00781 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree->m_treeRoot = m_treeRoot;
00782 iNLidx++;
00783
00784 }
00785 }
00786
00787 std::cout << "WALK THE TREE FOR NONLINEAR OBJECTIVE TERMS " << nlo << std::endl;
00788 if(nlo > 0)
00789 {
00790 while ( iNLidx < nlc + nlo)
00791 {
00792 m_treeRoot = walkTree ((OBJ_DE + iNLidx - nlc)->e);
00793
00794 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx] = new Nl();
00795 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->idx = -1 - (iNLidx - nlc);
00796 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree = new OSExpressionTree();
00797 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree->m_treeRoot = m_treeRoot;
00798 iNLidx++;
00799
00800 }
00801 }
00802
00803
00804
00805 }
00806
00807
00808
00809
00810
00811 #ifdef AMPLDEBUG
00812 OSiLWriter osilwriter;
00813 std::cout << "WRITE THE INSTANCE" << std::endl;
00814 osilwriter.m_bWhiteSpace = true;
00815 std::cout << osilwriter.writeOSiL( osinstance) << std::endl;
00816 std::cout << "DONE WRITE THE INSTANCE" << std::endl;
00817
00818 std::cout << osinstance->printModel() << std::endl;
00819
00820 #endif
00821
00822 return true;
00823 }