28 #include <adolc/drivers/drivers.h>    29 #include <adolc/adolc_sparse.h>    40 #define CONSTRAIN_START_LOOP(pVector,cn) \    41   for (uint r1=0;r1<l2r.size();r1++){ \    42     for (uint r2=0;r2<l2r[r1].size();r2++){ \    43       for (uint p=0;p<(pVector).size();p++){ \    44         int psec = p+nPriPr; \    45         cix = gix((cn), r1, r2, p);    46 #define CONSTRAIN_END_LOOP \    50 using namespace Ipopt;
    52 typedef std::map<string, endvar>        
VarMap;
    53 typedef std::pair<std::string, endvar > 
VarPair;
    69     declareVariable(
"da", 
DOM_SEC_PR,    
"Demand from abroad (imports)");
    70     declareVariable(
"dc", 
DOM_SEC_PR,    
"Demand, composite");
    71     declareVariable(
"dl", 
DOM_ALL_PR,    
"Demand from local");
    72     declareVariable(
"pc", 
DOM_ALL_PR,    
"Price, composite");
    73     declareVariable(
"pl", 
DOM_ALL_PR,    
"Price, local") ;
    75     declareVariable(
"sa", 
DOM_PRI_PR,    
"Supply to abroad (exports)");
    76     declareVariable(
"sc", 
DOM_PRI_PR,    
"Supply, composite");
    77     declareVariable(
"sl", 
DOM_ALL_PR,    
"Supply to locals");
    89   mkeq2.
comment=
"[h1] Conservation of matters of transformed products";
    96   mkeq3.
comment=
"[h2] Conservation of matters of raw products";
   103   mkeq4.
comment=
"[eq 13] Leontief transformation function";
   109   mkeq5.
comment=
"[eq 21] Raw product supply function";
   115   mkeq6.
comment=
"[eq 20] Trasformed products demand function";
   121   mkeq7.
comment=
"[h7 and h3] Transformed products import function";
   127   mkeq8.
comment=
"[h8 and h4] Raw products export function";
   132   mkeq13.
name=
"mkeq13";
   133   mkeq13.
comment=
"[h9] Calculation of the composite price of transformed products (PPC_Dp)";
   138   mkeq14.
name=
"mkeq14";
   139   mkeq14.
comment=
"[h10] Calculation of the composite price of raw products (PPC_Sw)";
   144   mkeq17.
name=
"mkeq17";
   145   mkeq17.
comment=
"[h16] Constrain of the transformaton supply (lower than the regional maximal production capacity)";
   151   mkeq23.
name=
"mkeq23";
   152   mkeq23.
comment=
"[h3] Composit demand eq. (Dp)";
   157   mkeq24.
name=
"mkeq24";
   158   mkeq24.
comment=
"[h4] Composite supply eq. (Sw)";
   163   mkeq26.
name=
"mkeq26";
   164   mkeq26.
comment=
"[eq ] Verification of the null transport agents supply";
   169   mkeq25.
name=
"mkeq25";
   170   mkeq25.
comment=
"Verification of the null trasformers supply (price of raw product + trasf product > trasf product)";
   175   mkeq18.
name=
"mkeq18";
   176   mkeq18.
comment=
"Constrain on raw material supply (lower than inventory)";
   181   resbounds.
name=
"resbounds";
   182   resbounds.
comment=
"Constrain on raw material supply (lower than inventory, for each possible combination of primary products)";
   194   cons.push_back(mkeq2);
   195   cons.push_back(mkeq6);
   196   cons.push_back(mkeq7);
   197   cons.push_back(mkeq13);
   198   cons.push_back(mkeq23);
   199   cons.push_back(mkeq3);
   200   cons.push_back(mkeq4);
   201   cons.push_back(mkeq5);
   202   cons.push_back(mkeq8);
   203   cons.push_back(mkeq14);
   204   cons.push_back(mkeq24);
   205   cons.push_back(mkeq17);
   206   cons.push_back(mkeq26);
   207   cons.push_back(mkeq25);
   209   cons.push_back(resbounds);
   219 template<
class T> 
bool   222   double aa, bb, dc0, sigma, a_pr, ct, m, zeromax,supCorr2;
   226   for (uint r1=0;r1<l2r.size();r1++){
   227     for (uint r2=0;r2<l2r[r1].size();r2++){
   239       for (uint p=0;p<secPr.size();p++){
   240         aa = gpd(
"aa",l2r[r1][r2],secPr[p]);
   241         sigma = gpd(
"sigma",l2r[r1][r2],secPr[p]);
   242         dc0 = gpd(
"dc",l2r[r1][r2],secPr[p],secondYear);
   244         obj_value += aa*pow(mymax(zeromax,x[gix(
"dc",r1,r2,p)]),(sigma+1)/sigma)-x[gix(
"pc",r1,r2,p+nPriPr)]*x[gix(
"dc",r1,r2,p)];
   252       for (uint p=0;p<priPr.size();p++){
   253         bb = gpd(
"bb",l2r[r1][r2],priPr[p]);
   254         sigma = gpd(
"sigma",l2r[r1][r2],priPr[p]);
   256         obj_value += x[gix(
"pc",r1,r2,p)]*x[gix(
"sc",r1,r2,p)] - bb*pow(mymax(zeromax,x[gix(
"sc",r1,r2,p)]),((sigma+1)/sigma));
   264       for (uint p1=0;p1<priPr.size();p1++){
   265         for (uint p2=0;p2<priPr.size();p2++){
   266           a_pr = gpd(
"a_pr",l2r[r1][r2],priPr[p1],
DATA_NOW,priPr[p2]);
   267           bb = gpd(
"bb",l2r[r1][r2],priPr[p2]);
   268           sigma = gpd(
"sigma",l2r[r1][r2],priPr[p2]);
   269           obj_value += x[gix(
"pc",r1,r2,p2)]*a_pr*x[gix(
"sc",r1,r2,p1)]-bb*pow(mymax(zeromax,a_pr*x[gix(
"sc",r1,r2,p1)]),(sigma+1)/sigma);
   274       for (uint p=0;p<allPr.size();p++){
   275         for (uint r2To=0;r2To<l2r[r1].size();r2To++){
   276           ct = (gpd(
"ct",l2r[r1][r2],allPr[p],
DATA_NOW,i2s(l2r[r1][r2To])) * gpd(
"pol_tcSub",l2r[r1][r2],allPr[p]));
   277           obj_value += (x[gix(
"pl",r1,r2To,p)]-x[gix(
"pl",r1,r2,p)]-ct)*x[gix(
"rt",r1,r2,p,r2To)];
   283       for (uint p=0;p<secPr.size();p++){
   284         m = (gpd(
"m",l2r[r1][r2],secPr[p]) * gpd(
"pol_trSub",l2r[r1][r2],secPr[p]));
   285         obj_value += (x[gix(
"pl",r1,r2,p+nPriPr)]-m)*x[gix(
"sl",r1,r2,p+nPriPr)];
   288       for (uint p=0;p<priPr.size();p++){
   289         obj_value -= x[gix(
"pl",r1,r2,p)]*x[gix(
"dl",r1,r2,p)];
   310 template<
class T> 
bool   313   double a_pr, a, sigma, ff, pol_mktDirInt_s, pol_mktDirInt_d, pol_mktDirInt_d_pSubstituted, pol_mktDirInt_d_1, pol_mktDirInt_d_1_pSubstituted, gg, q1, p1v, t1, r1v, psi, eta, pworld, ct, k, dispor, mv, in, in_1, supCorr, es_d, pc_1, pc_pSubstituted, pc_1_pSubstituted, additionalDemand;
   320     g[cix] = x[gix(
"dl",r1,r2,psec)]-x[gix(
"sl",r1,r2,psec)];
   321     for (uint r2To=0;r2To<l2r[r1].size();r2To++){
   322       g[cix] += x[gix(
"rt",r1,r2,psec,r2To)]-x[gix(
"rt",r1,r2To,psec,r2)];
   330     gg         = gpd(
"gg",l2r[r1][r2],secPr[p]);
   331     sigma      = gpd(
"sigma",l2r[r1][r2],secPr[p]);
   332     pc_1       = gpd(
"pc",l2r[r1][r2],secPr[p],previousYear);
   333     pol_mktDirInt_d   = gpd(
"pol_mktDirInt_d",l2r[r1][r2],secPr[p]);              
   334     pol_mktDirInt_d_1 = gpd(
"pol_mktDirInt_d",l2r[r1][r2],secPr[p],previousYear); 
   335     additionalDemand = gpd(
"additionalDemand",l2r[r1][r2],secPr[p]);
   336     g[cix]     = - gg*pow(x[gix(
"pc",r1,r2,psec)]*pol_mktDirInt_d,sigma);  
   337     vector<string> debug = secPr;
   339     for (uint p2=0;p2<secPr.size();p2++){
   340       es_d     = gpd(
"es_d",l2r[r1][r2],secPr[p],
DATA_NOW,secPr[p2]);
   342         pc_1_pSubstituted    = gpd(
"pc",l2r[r1][r2],secPr[p2],previousYear);
   343         pol_mktDirInt_d_pSubstituted   = gpd(
"pol_mktDirInt_d",l2r[r1][r2],secPr[p2]);               
   344         pol_mktDirInt_d_1_pSubstituted = gpd(
"pol_mktDirInt_d",l2r[r1][r2],secPr[p2],previousYear);  
   348                    ((x[gix(
"pc",r1,r2,psec)]*pol_mktDirInt_d) / (x[gix(
"pc",r1,r2,priPr.size()+p2)]*pol_mktDirInt_d_pSubstituted))
   350                    ((pc_1*pol_mktDirInt_d_1) / (pc_1_pSubstituted*pol_mktDirInt_d_1_pSubstituted))
   356     for (uint p3=0;p3<othPr.size();p3++){
   357       es_d     = gpd(
"es_d",l2r[r1][r2],secPr[p],
DATA_NOW,othPr[p3]);
   359         pc_pSubstituted    = gpd(
"pl",l2r[r1][r2],othPr[p3],
DATA_NOW);
   360         pc_1_pSubstituted  = gpd(
"pl",l2r[r1][r2],othPr[p3],previousYear);
   364                    (x[gix(
"pc",r1,r2,psec)]*pol_mktDirInt_d / pc_pSubstituted)
   366                    (pc_1*pol_mktDirInt_d_1 / pc_1_pSubstituted)
   372     g[cix] += x[gix(
"dc",r1,r2,p)]-additionalDemand;
   378     q1 = gpd(
"q1_polCorr",l2r[r1][r2],secPr[p]);
   380     psi = gpd(
"psi",l2r[r1][r2],secPr[p]);
   381     pworld = gpd(
"pl", worldCodeLev2,secPr[p]);
   382     g[cix] = x[gix(
"da",r1,r2,p)]/x[gix(
"dl",r1,r2,psec)] - pow((q1*x[gix(
"pl",r1,r2,psec)])/(p1v*pworld),psi);
   387     pworld = gpd(
"pl", worldCodeLev2,secPr[p]);
   388     g[cix] = x[gix(
"pc",r1,r2,psec)]*x[gix(
"dc",r1,r2,p)]-x[gix(
"dl",r1,r2,psec)]*x[gix(
"pl",r1,r2,psec)]-x[gix(
"da",r1,r2,p)]*pworld;
   393     q1 = gpd(
"q1_polCorr",l2r[r1][r2],secPr[p]);
   394     psi = gpd(
"psi",l2r[r1][r2],secPr[p]);
   396     g[cix] = x[gix(
"dc",r1,r2,p)] -
   398             q1 * pow(x[gix(
"da",r1,r2,p)],(psi-1)/psi)
   399           + p1v * pow(x[gix(
"dl",r1,r2,psec)],(psi-1)/psi),
   407     g[cix] = x[gix(
"dl",r1,r2,p)]-x[gix(
"sl",r1,r2,p)];
   408     for (uint r2To=0;r2To<l2r[r1].size();r2To++){
   409       g[cix] += x[gix(
"rt",r1,r2,p,r2To)]-x[gix(
"rt",r1,r2To,p,r2)];
   411     for (uint p2=0;p2<priPr.size();p2++){
   412       a_pr = gpd(
"a_pr",l2r[r1][r2],priPr[p2],
DATA_NOW,priPr[p]);
   413       g[cix] -= a_pr*x[gix(
"sl",r1,r2,p2)];
   419     g[cix] = x[gix(
"dl",r1,r2,p)];
   420     for (uint p2=0;p2<secPr.size();p2++){
   421       a = gpd(
"a",l2r[r1][r2],priPr[p],
DATA_NOW,secPr[p2]);
   422       g[cix] -= a*x[gix(
"sl",r1,r2,p2+nPriPr)];
   432     ff = gpd(
"ff",l2r[r1][r2],priPr[p]);
   433     pol_mktDirInt_s = gpd(
"pol_mktDirInt_s",l2r[r1][r2],priPr[p]);
   434     sigma = gpd(
"sigma",l2r[r1][r2],priPr[p]);
   437     double carbonPrice = gpd(
"carbonPrice",l2r[r1][r2],
"",
DATA_NOW); 
   438     double intRate     = MTHREAD->MD->getDoubleSetting(
"ir");
   439     double Pct         = carbonPrice*intRate;
   440     double omega       = gpd(
"co2content_products", l2r[r1][r2], priPr[p])/1000;  
   443     g[cix] = x[gix(
"sc",r1,r2,p)]-ff*pow((x[gix(
"pc",r1,r2,p)]-omega*Pct)*pol_mktDirInt_s,sigma);
   452     t1 = gpd(
"t1_polCorr",l2r[r1][r2],priPr[p]);
   454     eta = gpd(
"eta",l2r[r1][r2],priPr[p]);
   455     pworld = gpd(
"pl", worldCodeLev2,priPr[p]);
   456     g[cix] = x[gix(
"sa",r1,r2,p)]/x[gix(
"sl",r1,r2,p)] - pow((t1*x[gix(
"pl",r1,r2,p)])/(r1v*pworld),eta);
   461     pworld = gpd(
"pl", worldCodeLev2,priPr[p]);
   462     g[cix] = x[gix(
"pc",r1,r2,p)]*x[gix(
"sc",r1,r2,p)]-x[gix(
"sl",r1,r2,p)]*x[gix(
"pl",r1,r2,p)]-x[gix(
"sa",r1,r2,p)]*pworld;
   467     t1 = gpd(
"t1_polCorr",l2r[r1][r2],priPr[p]);
   469     eta = gpd(
"eta",l2r[r1][r2],priPr[p]);
   470     g[cix] = x[gix(
"sc",r1,r2,p)] -
   472              t1 * pow(x[gix(
"sa",r1,r2,p)],(eta-1)/eta)
   473           + r1v * pow(x[gix(
"sl",r1,r2,p)],(eta-1)/eta),
   480     k = gpd(
"k",l2r[r1][r2],secPr[p]);
   481     g[cix] = x[gix(
"sl",r1,r2,p+nPriPr)]-k;
   486     for (uint r2To=0;r2To<l2r[r1].size();r2To++){
   487       cix = gix(12, r1, r2, p,r2To); 
   488       ct = (gpd(
"ct",l2r[r1][r2],allPr[p],
DATA_NOW,i2s(l2r[r1][r2To])) *  gpd(
"pol_tcSub",l2r[r1][r2],allPr[p])) ;
   489       g[cix] = (x[gix(
"pl",r1,r2To,p)]-x[gix(
"pl",r1,r2,p)]-ct);
   495     mv = (gpd(
"m",l2r[r1][r2],secPr[p]) * gpd(
"pol_trSub",l2r[r1][r2],secPr[p]));
   496     g[cix] = mv - x[gix(
"pl",r1,r2,p+nPriPr)];
   497     for (uint p2=0;p2<priPr.size();p2++){
   498       a = gpd(
"a",l2r[r1][r2],priPr[p2],
DATA_NOW,secPr[p]);
   499       g[cix] += a * x[gix(
"pl",r1,r2,p2)];
   520     for(uint i=0;i<priPrCombs[p].size();i++){
   521       g[cix] += x[gix(
"sa",r1,r2,priPrCombs[p][i])]+x[gix(
"sl",r1,r2,priPrCombs[p][i])];
   523     g[cix] -= overharvestingAllowance; 
   541   debugRunOnce = 
false;
   552                   Index& nnz_h_lag, IndexStyleEnum& index_style){
   557     priPr = MTHREAD->MD->getStringVectorSetting(
"priProducts");
   558     secPr = MTHREAD->MD->getStringVectorSetting(
"secProducts");
   559     othPr = MTHREAD->MD->getStringVectorSetting(
"othExogenousProducts");
   561     allPr.insert( allPr.end(), secPr.begin(), secPr.end() );
   562     nPriPr = priPr.size();
   563     nSecPr = secPr.size();
   564     nAllPr = allPr.size();
   565     nOthPr = othPr.size();
   566     std::vector<int> l1regIds =  MTHREAD->MD->getRegionIds(1, 
true);
   567     nL2r =  MTHREAD->MD->getRegionIds(2, 
true).size();
   568     firstYear = MTHREAD->MD->getIntSetting(
"initialYear");
   569     secondYear = firstYear+1;
   570     worldCodeLev2 = MTHREAD->MD->getIntSetting(
"worldCodeLev2");
   572     for(uint i=0;i<l1regIds.size();i++){
   573       std::vector<int> l2ChildrenIds;
   574       ModelRegion* l1Region = MTHREAD->MD->getRegion(l1regIds[i]);
   575       std::vector<ModelRegion*> l2Childrens = l1Region->
getChildren(
true);
   576       for(uint j=0;j<l2Childrens.size();j++){
   577         l2ChildrenIds.push_back(l2Childrens[j]->getRegId());
   579       if(l2ChildrenIds.size()){
   580         l2r.push_back(l2ChildrenIds);
   585     priPrCombs = MTHREAD->MD->createCombinationsVector(nPriPr);
   586     nPriPrCombs = priPrCombs.size();
   595     calculateNumberVariablesConstrains();
   598     cacheInitialPosition();
   609   previousYear = MTHREAD->SCD->getYear()-1; 
   614   overharvestingAllowance = MTHREAD->MD->getDoubleSetting(
"overharvestingAllowance",
DATA_NOW);
   616   copyInventoryResourses();
   618   generate_tapes(n, m, nnz_jac_g, nnz_h_lag);
   627   index_style = C_STYLE;
   637   for (Index i=0; i<n; i++) {
   638     x_l[i] =  getBoundByIndex(
LBOUND,i);
   639     x_u[i] =  getBoundByIndex(
UBOUND,i);
   643   for (Index i=0; i<m; i++) {
   644     int direction = getConstrainDirectionByIndex(i);
   665                         Index m, 
bool init_lambda, Number* lambda){
   676   assert(init_x == 
true);
   677   assert(init_z == 
false);
   678   assert(init_lambda == 
false);
   680   VarMap::iterator viter;
   683   for (viter = vars.begin(); viter != vars.end(); ++viter) {
   685     int vdomtype = viter->second.domain;
   687       for(uint r1=0;r1<l2r.size();r1++){
   688         for(uint r2=0;r2<l2r[r1].size();r2++){
   689           for(uint p=0;p<priPr.size();p++){
   690             x[gix(viter->first,r1,r2,p)]= gpd(viter->first,l2r[r1][r2],priPr[p],previousYear);
   695       for(uint r1=0;r1<l2r.size();r1++){
   696         for(uint r2=0;r2<l2r[r1].size();r2++){
   697           for(uint p=0;p<secPr.size();p++){
   698             x[gix(viter->first,r1,r2,p)]= gpd(viter->first,l2r[r1][r2],secPr[p],previousYear);
   703       for(uint r1=0;r1<l2r.size();r1++){
   704         for(uint r2=0;r2<l2r[r1].size();r2++){
   705           for(uint p=0;p<allPr.size();p++){
   706             x[gix(viter->first,r1,r2,p)]= gpd(viter->first,l2r[r1][r2],allPr[p],previousYear);
   711       for(uint r1=0;r1<l2r.size();r1++){
   712         for(uint r2=0;r2<l2r[r1].size();r2++){
   713           for(uint p=0;p<allPr.size();p++){
   714             for(uint r2To=0;r2To<l2r[r1].size();r2To++){
   715               x[gix(viter->first,r1,r2,p,r2To)]= gpd(viter->first,l2r[r1][r2],allPr[p],previousYear,i2s(l2r[r1][r2To]));
   721       msgOut(
MSG_CRITICAL_ERROR,
"Try to setting the initial value of a variable of unknow type ("+viter->first+
")");
   733                        Index n, 
const Number* x, 
const Number* z_L, 
const Number* z_U,
   734                        Index m, 
const Number* g, 
const Number* lambda,
   735                        Number obj_value, 
const IpoptData* ip_data, IpoptCalculatedQuantities* ip_cq){
   737   printf(
"\n\nObjective value\n");
   738   printf(
"f(x*) = %e\n", obj_value);
   742   VarMap::iterator viter;
   745   for (viter = vars.begin(); viter != vars.end(); ++viter) {
   747     int vdomtype = viter->second.domain;
   749       for(uint r1=0;r1<l2r.size();r1++){
   750         for(uint r2=0;r2<l2r[r1].size();r2++){
   751           for(uint p=0;p<priPr.size();p++){
   752             spd(x[gix(viter->first,r1,r2,p)],viter->first,l2r[r1][r2],priPr[p]);
   757       for(uint r1=0;r1<l2r.size();r1++){
   758         for(uint r2=0;r2<l2r[r1].size();r2++){
   759           for(uint p=0;p<secPr.size();p++){
   760             spd(x[gix(viter->first,r1,r2,p)],viter->first,l2r[r1][r2],secPr[p]);
   766       for(uint r1=0;r1<l2r.size();r1++){
   767         for(uint r2=0;r2<l2r[r1].size();r2++){
   768           for(uint p=0;p<allPr.size();p++){
   769             spd(x[gix(viter->first,r1,r2,p)],viter->first,l2r[r1][r2],allPr[p]);
   774       for(uint r1=0;r1<l2r.size();r1++){
   775         for(uint r2=0;r2<l2r[r1].size();r2++){
   776           for(uint p=0;p<allPr.size();p++){
   777             for(uint r2To=0;r2To<l2r[r1].size();r2To++){
   781               spd(x[gix(viter->first,r1,r2,p,r2To)],viter->first,l2r[r1][r2],allPr[p],
DATA_NOW,
false,i2s(l2r[r1][r2To]));
   787       msgOut(
MSG_CRITICAL_ERROR,
"Try to setting the solved value of a variable of unknow type ("+viter->first+
")");
   805     for (
int i=0;i<n+m+1;i++) {
   822 Opt::eval_f(Index n, 
const Number* x, 
bool new_x, Number& obj_value){
   823   eval_obj(n,x,obj_value);
   831   gradient(
tag_f,n,x,grad_f);
   837 Opt::eval_g(Index n, 
const Number* x, 
bool new_x, Index m, Number* g){
   839   eval_constraints(n,x,m,g);
   846                 Index* iRow, Index *jCol, Number* values){
   847   if (values == NULL) {
   850     for(Index idx=0; idx<nnz_jac; idx++)
   852   iRow[idx] = rind_g[idx];
   853   jCol[idx] = cind_g[idx];
   859     sparse_jac(
tag_g, m, n, 1, x, &nnz_jac, &rind_g, &cind_g, &jacval, options_g);
   861     for(Index idx=0; idx<nnz_jac; idx++)
   863   values[idx] = jacval[idx];
   871 Opt::eval_h(Index n, 
const Number* x, 
bool new_x, Number obj_factor, Index m, 
const Number* lambda,
   872             bool new_lambda, Index nele_hess, Index* iRow, Index* jCol, Number* values){
   876   if (values == NULL) {
   880     for(Index idx=0; idx<nnz_L; idx++)
   882   iRow[idx] = rind_L[idx];
   883   jCol[idx] = cind_L[idx];
   890     for(Index idx = 0; idx<n ; idx++)
   892     for(Index idx = 0; idx<m ; idx++)
   893       x_lam[n+idx] = lambda[idx];
   894     x_lam[n+m] = obj_factor;
   896     sparse_hess(
tag_L, n+m+1, 1, x_lam, &nnz_L_total, &rind_L_total, &cind_L_total, &hessval, options_L);
   899     for(Index idx_total = 0; idx_total <nnz_L_total ; idx_total++)
   901   if((rind_L_total[idx_total] < (
unsigned int) n) && (cind_L_total[idx_total] < (
unsigned int) n))
   903       values[idx] = hessval[idx_total];
   920     Number *xp    = 
new double[n];
   921     Number *lamp  = 
new double[m];
   922     Number *zl    = 
new double[m];
   923     Number *zu    = 
new double[m];
   925     adouble *xa   = 
new adouble[n];
   926     adouble *g    = 
new adouble[m];
   927     adouble *lam  = 
new adouble[m];
   936     x_lam   = 
new double[n+m+1];
   939     get_starting_point(n, 1, xp, 0, zl, zu, m, 0, lamp);
   945     for(Index idx=0;idx<n;idx++)
   948     eval_obj(n,xa,obj_value);
   956     for(Index idx=0;idx<n;idx++)
   959     eval_constraints(n,xa,m,g);
   962     for(Index idx=0;idx<m;idx++)
   969     for(Index idx=0;idx<n;idx++)
   971     for(Index idx=0;idx<m;idx++)
   975     eval_obj(n,xa,obj_value);
   978     eval_constraints(n,xa,m,g);
   980     for(Index idx=0;idx<m;idx++)
   981         obj_value += g[idx]*lam[idx];
  1000     sparse_jac(
tag_g, m, n, 0, xp, &nnz_jac, &rind_g, &cind_g, &jacval, options_g);
  1003     nnz_jac_g = nnz_jac;
  1005     unsigned int  **JP_f=NULL;                
  1006     unsigned int  **JP_g=NULL;                
  1007     unsigned int  **HP_f=NULL;                
  1008     unsigned int  **HP_g=NULL;                
  1009     unsigned int  *HP_length=NULL;            
  1010     unsigned int  *temp=NULL;                 
  1014     JP_f = (
unsigned int **) malloc(
sizeof(
unsigned int*));
  1015     JP_g = (
unsigned int **) malloc(m*
sizeof(
unsigned int*));
  1016     HP_f = (
unsigned int **) malloc(n*
sizeof(
unsigned int*));
  1017     HP_g = (
unsigned int **) malloc(n*
sizeof(
unsigned int*));
  1018     HP_t = (
unsigned int **) malloc((n+m+1)*
sizeof(
unsigned int*));
  1019     HP_length = (
unsigned int *) malloc((n)*
sizeof(
unsigned int));
  1022     hess_pat(
tag_f, n, xp, HP_f, ctrl_H);
  1024     indopro_forward_safe(
tag_f, 1, n, xp, JP_f);
  1025     indopro_forward_safe(
tag_g, m, n, xp, JP_g);
  1026     nonl_ind_forward_safe(
tag_g, m, n, xp, HP_g);
  1030         if (HP_f[i][0]+HP_g[i][0]!=0)
  1034                 HP_t[i] = (
unsigned int *) malloc((HP_g[i][0]+
HPOFF)*
sizeof(
unsigned int));
  1035                 for(j=0;j<=(int) HP_g[i][0];j++)
  1037                     HP_t[i][j] = HP_g[i][j];
  1039                 HP_length[i] = HP_g[i][0]+
HPOFF;
  1045                     HP_t[i] = (
unsigned int *) malloc((HP_f[i][0]+
HPOFF)*
sizeof(
unsigned int));
  1046                     for(j=0;j<=(int) HP_f[i][0];j++)
  1048                         HP_t[i][j] = HP_f[i][j];
  1050                     HP_length[i] = HP_f[i][0]+
HPOFF;
  1054                     HP_t[i] = (
unsigned int *) malloc((HP_f[i][0]+HP_g[i][0]+
HPOFF)*
sizeof(
unsigned int));
  1056                     while ((k<=(
int) HP_f[i][0]) && (l <= (
int) HP_g[i][0]))
  1058                         if (HP_f[i][k] < HP_g[i][l])
  1060                             HP_t[i][j]=HP_f[i][k];
  1065                             if (HP_f[i][k] == HP_g[i][l])
  1067                                 HP_t[i][j]=HP_f[i][k];
  1072                                 HP_t[i][j]=HP_g[i][l];
  1079                     for(ii=k;ii<=(int) HP_f[i][0];ii++)
  1081                         HP_t[i][j] = HP_f[i][ii];
  1086                     for(ii=l;ii<=(int) HP_g[i][0];ii++)
  1088                         HP_t[i][j] = HP_g[i][ii];
  1095             HP_length[i] = HP_f[i][0]+HP_g[i][0]+
HPOFF; 
  1099             HP_t[i] = (
unsigned int *) malloc((
HPOFF+1)*
sizeof(
unsigned int));
  1118         HP_t[n+i] = (
unsigned int *) malloc((JP_g[i][0]+1)*
sizeof(
unsigned int));
  1119         HP_t[n+i][0]=JP_g[i][0];
  1123         for(j=1;j<= (int) JP_g[i][0];j++)
  1125             HP_t[n+i][j]=JP_g[i][j];
  1130             if (HP_length[JP_g[i][j]] <= HP_t[JP_g[i][j]][0]+1) 
  1137                 temp = (
unsigned int *) malloc((HP_t[JP_g[i][j]][0]+1)*
sizeof(
unsigned int));
  1138                 for(l=0;l<=(int)HP_t[JP_g[i][j]][0];l++)
  1140                     temp[l] = HP_t[JP_g[i][j]][l]; 
  1154                 unsigned int machin = JP_g[i][j];
  1158                 HP_t[JP_g[i][j]] = (
unsigned int *) malloc(2*HP_length[JP_g[i][j]]*
sizeof(
unsigned int));
  1159                 HP_length[JP_g[i][j]] = 2*HP_length[JP_g[i][j]];
  1162                 for(l=0;l<=(int)temp[0];l++)
  1163                     HP_t[JP_g[i][j]][l] =temp[l];
  1169             HP_t[JP_g[i][j]][0] = HP_t[JP_g[i][j]][0]+1; 
  1170             HP_t[JP_g[i][j]][HP_t[JP_g[i][j]][0]] = i+n; 
  1175     for(j=1;j<= (int) JP_f[0][0];j++)
  1177         if (HP_length[JP_f[0][j]] <= HP_t[JP_f[0][j]][0]+1) 
  1179             temp = (
unsigned int *) malloc((HP_t[JP_f[0][j]][0])*
sizeof(
unsigned int));
  1180             for(l=0;l<=(int)HP_t[JP_f[0][j]][0];l++)
  1181                 temp[l] = HP_t[JP_f[0][j]][l];
  1182             free(HP_t[JP_f[0][j]]);
  1183             HP_t[JP_f[0][j]] = (
unsigned int *) malloc(2*HP_length[JP_f[0][j]]*
sizeof(
unsigned int));
  1184             HP_length[JP_f[0][j]] = 2*HP_length[JP_f[0][j]];
  1185             for(l=0;l<=(int)temp[0];l++)
  1186                 HP_t[JP_f[0][j]][l] =temp[l];
  1189         HP_t[JP_f[0][j]][0] = HP_t[JP_f[0][j]][0]+1;
  1190         HP_t[JP_f[0][j]][HP_t[JP_f[0][j]][0]] = n+m;
  1193     HP_t[n+m] = (
unsigned int *) malloc((JP_f[0][0]+2)*
sizeof(
unsigned int));
  1194     HP_t[n+m][0]=JP_f[0][0]+1;
  1195     for(j=1;j<= (int) JP_f[0][0];j++)
  1196         HP_t[n+m][j]=JP_f[0][j];
  1197     HP_t[n+m][JP_f[0][0]+1]=n+m;
  1199     set_HP(
tag_L,n+m+1,HP_t); 
  1204         for (j=1;j<=(int) HP_t[i][0];j++)
  1205             if ((
int) HP_t[i][j] <= i)
  1215     rind_L_total = NULL;
  1216     cind_L_total = NULL;
  1219     sparse_hess(
tag_L, n+m+1, -1, xp, &nnz_L_total, &rind_L_total, &cind_L_total, &hessval, options_L);
  1221     rind_L = 
new unsigned int[nnz_L];
  1222     cind_L = 
new unsigned int[nnz_L];
  1223     rind_L_total = (
unsigned int*) malloc(nnz_L_total*
sizeof(
unsigned int)); 
  1224     cind_L_total = (
unsigned int*) malloc(nnz_L_total*
sizeof(
unsigned int)); 
  1226     unsigned int ind = 0;
  1228     for (
int i=0;i<n;i++)
  1229         for (
unsigned int j=1;j<=HP_t[i][0];j++)
  1231         if (((
int) HP_t[i][j]>=i) &&((
int) HP_t[i][j]<n))
  1234             cind_L[ind++] = HP_t[i][j];
  1239     for (
int i=0;i<n+m+1;i++)
  1240         for (
unsigned int j=1;j<=HP_t[i][0];j++)
  1242         if ((
int) HP_t[i][j]>=i)
  1244             rind_L_total[ind] = i;
  1245             cind_L_total[ind++] = HP_t[i][j];
  1275   map<string, int>::const_iterator p;
  1276   p=initPos.find(varName);
  1277   if(p != initPos.end()) {
  1281     msgOut(
MSG_CRITICAL_ERROR, 
"Asking the initial position in the concatenated array of a variable ("+varName+
") that doesn't exist!");
  1288   return cInitPos.at(cn);
  1293   VarMap::const_iterator p;
  1294   p=vars.find(varName);
  1295   if(p != vars.end()) {
  1296     return p->second.domain;
  1299     msgOut(
MSG_CRITICAL_ERROR, 
"Asking the domain type of a variable ("+varName+
") that doesn't exist!");
  1306   return cons.at(cn).domain;
  1309 template<
class T> 
const int  1314   int dType = gdt(v_or_c);
  1315   int othCountriesRegions = 0;
  1316   int othCountriesRegions_r2case = 0;
  1317   for (uint i=0;i<r1Ix;i++){
  1318     othCountriesRegions += l2r[i].size();
  1320   for (uint i=0;i<r1Ix;i++){
  1321     othCountriesRegions_r2case +=l2r[i].size()*l2r[i].size();
  1326       return gip(v_or_c)+(othCountriesRegions+r2Ix)*nPriPr+prIx;
  1328       return gip(v_or_c)+(othCountriesRegions+r2Ix)*nSecPr+prIx;;
  1330       return gip(v_or_c)+(othCountriesRegions+r2Ix)*nAllPr+prIx;
  1332       return gip(v_or_c)+(othCountriesRegions_r2case)*nAllPr+(r2Ix*nPriPr+prIx)*l2r[r1Ix].size()+r2IxTo;
  1334       return gip(v_or_c)+(othCountriesRegions_r2case)*nAllPr+(r2Ix*nSecPr+prIx)*l2r[r1Ix].size()+r2IxTo;
  1336       return gip(v_or_c)+(othCountriesRegions_r2case)*nAllPr+(r2Ix*nAllPr+prIx)*l2r[r1Ix].size()+r2IxTo; 
  1342       return gip(v_or_c)+(othCountriesRegions+r2Ix)*nPriPrCombs+prIx;
  1344     msgOut(
MSG_CRITICAL_ERROR,
"Try to calculate the position of a variable (or constrain) of unknow type.");
  1351 Opt::gix(
const string &varName, 
const int& r1Ix, 
const int& r2Ix, 
const int& prIx, 
const int& r2IxTo)
 const{
  1353   map <string, vector < vector < vector < vector <int> > > > >::const_iterator p;
  1354   p=vpositions.find(varName);
  1355   if(p != vpositions.end()) {
  1356     return p->second[r1Ix][r2Ix][prIx][r2IxTo];
  1359     msgOut(
MSG_CRITICAL_ERROR, 
"Asking the position of a variable ("+varName+
") that doesn't exist!");
  1365 Opt::gix(
const int &cn, 
const int& r1Ix, 
const int& r2Ix, 
const int& prIx, 
const int& r2IxTo)
 const{
  1366   return cpositions[cn][r1Ix][r2Ix][prIx][r2IxTo];
  1371   int vInitialPosition = 0;
  1372   int cInitialPosition = 0;
  1373   VarMap::iterator viter;
  1374   for (viter = vars.begin(); viter != vars.end(); ++viter) {
  1375     initPos.insert(pair<string, int>(viter->first, vInitialPosition));
  1376     initPos_rev.insert(pair<int, string>(vInitialPosition,viter->first));
  1377     vInitialPosition += getDomainElements(viter->second.domain);
  1379   for (uint i=0;i<cons.size();i++){
  1380     cInitPos.push_back(cInitialPosition);
  1381     cInitialPosition += getDomainElements(cons[i].domain);
  1389   VarMap::iterator viter;
  1390   for (viter = vars.begin(); viter != vars.end(); ++viter) {
  1391     vpositions.insert(pair<
string, vector < vector < vector < vector <int> > > > >(viter->first,  buildPositionVector(viter->first, viter->second.domain)));
  1394   for (uint i=0; i<cons.size();i++){
  1395     cpositions.push_back(buildPositionVector(i, cons[i].domain));
  1400 template<
class T> vector < vector < vector < vector <int> > > >
  1406       pVectorSize= priPr.size();
  1409       pVectorSize= secPr.size();
  1412       pVectorSize= allPr.size();
  1415       pVectorSize= priPr.size();
  1418       pVectorSize= secPr.size();
  1421       pVectorSize= allPr.size();
  1424       pVectorSize= allPr.size(); 
  1427       pVectorSize= priPrCombs.size();
  1430       msgOut(
MSG_CRITICAL_ERROR,
"Try to build the position of a variable (or contrain) of unknow type.");
  1434   vector < vector < vector < vector <int> > > > positionsToAdd;
  1435   for(uint r1=0;r1<l2r.size();r1++){
  1436     vector < vector < vector <int> > > dim1;
  1437     for(uint r2=0;r2<l2r[r1].size();r2++){
  1438       vector < vector <int> > dim2;
  1439       for(uint p=0;p<pVectorSize;p++){
  1441           for(uint r2To=0;r2To<l2r[r1].size();r2To++){
  1442             dim3.push_back(gix_uncached(v_or_c,r1,r2,p,r2To));
  1444         dim2.push_back(dim3);
  1446       dim1.push_back(dim2);
  1448     positionsToAdd.push_back(dim1);
  1450   return positionsToAdd;
  1458     VarMap::iterator viter;
  1459     for (viter = vars.begin(); viter != vars.end(); ++viter) {
  1460         nVar += getDomainElements(viter->second.domain);
  1465     nEqualityConstrains = 0;
  1466     nLowerEqualZeroConstrains = 0;
  1467     nGreaterEqualZeroConstrains = 0;
  1468     for(uint i=0;i<cons.size();i++){
  1469       nCons += getDomainElements(cons[i].domain);
  1471         nEqualityConstrains += getDomainElements(cons[i].domain);
  1473       } 
else if (cons[i].direction == 
CONSTR_LE0) {
  1474         nLowerEqualZeroConstrains += getDomainElements(cons[i].domain);
  1476       } 
else if (cons[i].direction == 
CONSTR_GE0) {
  1477         nGreaterEqualZeroConstrains += getDomainElements(cons[i].domain);
  1480         msgOut(
MSG_CRITICAL_ERROR, 
"Asking for a constrain with unknown direction ("+i2s(cons[i].direction)+
")");
  1484     msgOut(
MSG_INFO,
"The model will work with "+i2s(nVar)+
" variables and "+i2s(nCons)+
" constrains ("+i2s(nEqualityConstrains)+
" equalities, "+i2s(nLowerEqualZeroConstrains)+
" lower than 0 and "+i2s(nGreaterEqualZeroConstrains)+
" greater than 0)");
  1498       for(uint r1=0;r1<l2r.size();r1++){
  1499           elements += l2r[r1].size()*l2r[r1].size()*nPriPr; 
  1503       for(uint r1=0;r1<l2r.size();r1++){
  1504           elements += l2r[r1].size()*l2r[r1].size()*nSecPr; 
  1508       for(uint r1=0;r1<l2r.size();r1++){
  1509           elements += l2r[r1].size()*l2r[r1].size()*nAllPr; 
  1515       return nL2r*nPriPrCombs;
  1523   for(uint i=0;i<cons.size();i++){
  1524     if(i!=cons.size()-1){
  1525       if (idx >= gip(i) && idx < gip(i+1)){
  1526         return cons[i].direction;
  1529       if (idx >= gip(i) && idx < nCons){
  1530       return cons[i].direction;
  1534   msgOut(
MSG_CRITICAL_ERROR, 
"Asking contrain direction for an out of range contrain index!");
  1540   map <int, string>::const_iterator p;
  1541   p=initPos_rev.upper_bound(idx);
  1543   VarMap::const_iterator p2;
  1544   p2=vars.find(p->second);
  1545   if(p2 != vars.end()) {
  1547       if (p2->second.l_bound_var == 
""){ 
  1548         return p2->second.l_bound;
  1550         return getDetailedBoundByVarAndIndex(p2->second,idx,
LBOUND);
  1552     } 
else if (bound_type==
UBOUND){
  1553       if (p2->second.u_bound_var == 
""){ 
  1554         return p2->second.u_bound;
  1556         return getDetailedBoundByVarAndIndex(p2->second,idx,
UBOUND);
  1559       msgOut(
MSG_CRITICAL_ERROR, 
"Asking the bound with a type ("+i2s(bound_type)+
") that I don't know how to handle !");
  1563     msgOut(
MSG_CRITICAL_ERROR, 
"Asking the bound from a variable ("+p->second+
") that doesn't exist!");
  1572   unpack(idx,var.
domain,gip(var.
name),r1,r2,p,r2to,
true);
  1593   for(uint i=0;i<cons.size();i++){
  1594     if(i!=cons.size()-1){
  1595       if (idx >= gip(i) && idx < gip(i+1)){
  1599       if (idx >= gip(i) && idx < nCons){
  1604   msgOut(
MSG_CRITICAL_ERROR, 
"Asking contrain direction for an out of range contrain index!");
  1609 Opt::unpack(
int ix_h, 
int domain, 
int initial, 
int &r1_h, 
int &r2_h, 
int&p_h, 
int&r2to_h, 
bool fullp){
  1610   ix_h = ix_h-initial;
  1612   bool r2flag = 
false;
  1613   int pIndexToAdd = 0;
  1622     r1_h=0;r2_h=0;p_h=0;r2to_h=0;
  1631     pIndexToAdd = nPriPr;
  1635   for (uint r1=0;r1<l2r.size();r1++){
  1636     for (uint r2=0;r2<l2r[r1].size();r2++){
  1637       for (uint p=0;p<np;p++){
  1648           for (uint r2To=0;r2To<l2r[r1].size();r2To++){
  1662   msgOut(
MSG_CRITICAL_ERROR, 
"Error in unpack() function. Ix ("+i2s(ix_h)+
") can not be unpacked");
  1667   for(uint i=0;i<cons.size();i++){
  1668     if(   cons[i].name       == con->
name  1669        && cons[i].comment    == con->
comment  1670        && cons[i].domain     == con->
domain  1671        && cons[i].direction  == con->
direction){
  1682   unsigned int  **jacpat=NULL; 
  1690   jacpat = 
new unsigned int* [nCons];
  1691   x = 
new double[nVar];
  1693   nzjelements.clear();
  1695   retv_j = jac_pat(
tag_g, nCons, nVar,  x, jacpat, options_j);
  1697   for (
int i=0;i<nCons;i++) {
  1698     for (
int j=1;j<=jacpat[i][0];j++){
  1699       vector <int> nzjelement;
  1700       nzjelement.push_back(i);
  1701       nzjelement.push_back(jacpat[i][j]);
  1702       nzjelements.push_back(nzjelement);
  1710   unsigned int  **hesspat=NULL; 
  1715   hesspat = 
new unsigned int* [(nVar+nCons+1)];
  1716   x = 
new double[(nVar+nCons+1)];
  1718   retv_h = hess_pat(
tag_L,nVar+nCons+1,  x, hesspat, options_h);
  1720   for (
int i=0;i<(nVar);i++) {
  1721     for (
int j=1;j<=hesspat[i][0];j++){
  1722       if(hesspat[i][j]<=i){
  1723         vector <int> nzhelement;
  1724         nzhelement.push_back(i);
  1725         nzhelement.push_back(hesspat[i][j]);
  1726         nzhelements.push_back(nzhelement);
  1735   cout << 
"Num of variables: " <<  nVar << 
" - Num of constrains:" << nCons << endl;
  1736   cout << 
"IDX;ROW;COL" << endl;
  1737   for(uint i=0;i<nzhelements.size();i++){
  1738     cout << i << 
";" << nzhelements[i][0] << 
";" << nzhelements[i][1] << endl;
  1741   cout << 
"Dense jacobian: " << nCons * nVar << 
" elements" << endl;
  1742   cout << 
"Dense hessian:  " << nVar*(nVar-1)/2+nVar << 
" elements" << endl;
  1759 Opt::intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, 
const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq){
  1760     int itnumber = iter;
  1762         msgOut(
MSG_DEBUG,
"Running ("+i2s(itnumber)+
" iter) ..");
  1769   return getDomainElements(gdt(varName));
  1791 Opt::declareVariable(
const string &name, 
const int & domain, 
const string &desc, 
const double & l_bound, 
const double & u_bound, 
const string & l_bound_var, 
const string & u_bound_var){
  1793    end_var.
name = name;
  1800    vars.insert(std::pair<std::string, endvar >(name, end_var));
  1849   vector < vector < vector <double> > >  in_temp;
  1850   for (uint r1=0;r1<l2r.size();r1++){
  1851      vector < vector <double> > dim1;
  1852     for (uint r2=0;r2<l2r[r1].size();r2++){
  1853       vector <double> dim2;
  1854       ModelRegion* REG = MTHREAD->MD->getRegion(l2r[r1][r2]);
  1855       for (uint p=0;p<priPrCombs.size();p++){
  1857         dim2.push_back(this_in);
  1859       dim1.push_back(dim2);
  1861     in_temp.push_back(dim1);
 virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)
 
int getConNumber(constrain *con)
Return the position in the cons vector. 
 
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)
 
The required data is for the current year. 
 
void declareConstrains()
declare the constrains, their domain, their direction and their associated evaluation function ...
 
double l_bound
A fixed numerical lower bound for all the domain. 
 
double u_bound
A fixed numerical upper bound for all the domain. 
 
string desc
Description of the variable. 
 
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)
 
#define CONSTRAIN_START_LOOP(pVector, cn)
 
double getDetailedBoundByVarAndIndex(const endvar &var, const int &idx, const int &bType)
Return the bound of a given variable given the variable and the required index. Called by getBoundByI...
 
const int gdt(const string &varName)
Get the domain type of a given variable. 
 
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)
 
virtual void finalize_solution(SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
 
int getVarInstances(const string &varName)
build the matrix of the positions for a given variable or contrain 
 
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
 
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
 
void declareVariables()
declare the variables, their domains and their bounds 
 
Thread manager. Responsable to manage the main thread and "speak" with the GUI. 
 
Primary products // domain of variables and constrains: primary, secondary, all products or all produ...
 
vector< double > inResByAnyCombination
Vector of inventory resource for each possible combination of primary products. This store both alive...
 
void unpack(int ix_h, int domain, int initial, int &r1_h, int &r2_h, int &p_h, int &r2to_h, bool fullp=false)
Return the dimensions given a certain index, domain type and initial position. 
 
Opt(ThreadManager *MTHREAD_h)
Constructor. 
 
std::pair< std::string, endvar > VarPair
 
Print an error message and stop the model. 
 
const int gip(const string &varName) const 
Get the initial index position of a given variable in the concatenated array. 
 
constrain * getConstrainByIndex(int idx)
 
#define CONSTRAIN_END_LOOP
 
Secondary products over r2 couple regions (in-country commercial flows) 
 
string u_bound_var
A variable giving the upper bound. If present, the value defined in the variable overrides u_bound...
 
int getDomainElements(int domain)
return the number of elements of a domain 
 
vector< vector< vector< vector< int > > > > buildPositionVector(const T &v_or_c, int dType)
build the matrix of the positions for a given variable or contrain 
 
bool eval_obj(Index n, const T *x, T &obj_value)
 
Print a debug message, normally filtered out. 
 
Primary products over r2 couple regions (in-country commercial flows) 
 
const int gix_uncached(const T &v_or_c, int r1Ix, int r2Ix, int prIx, int r2IxTo=0)
Get the index in the concatenated array gived a certain var name (string) or constrain index (int)...
 
Scalar variable (not used) 
 
bool eval_constraints(Index n, const T *x, Index m, T *g)
 
All products over r2 couple regions (in-country commercial flows) 
 
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
 
void cachePositions()
cache the exact position index (initial+f(r1,r2,p,r2To) for each variable and constrain ...
 
const Number & mymax(const Number &a, const Number &b)
 
All possible combinations of primary products (2^ number of primary products) 
 
const int gix(const string &varName, const int &r1Ix, const int &r2Ix, const int &prIx, const int &r2IxTo=0) const 
Get the index in the concatenated array gived a certain var name, the reg lev1 index, the reg lev2 index and the prod. index. 
 
vector< ModelRegion * > getChildren(bool excludeResidual=true)
Returns a pointer to the parent regions. 
 
double getBoundByIndex(const int &bound_type, const int &idx)
Return the bound of a given variable (by index) 
 
string l_bound_var
A variable giving the lower bound. If present, the value defined in the variable overrides l_bound...
 
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
 
std::map< string, endvar > VarMap
 
All products (primary+secondary) 
 
void copyInventoryResourses()
Copy the inventoried resources in the in vector for better performances. 
 
void declareVariable(const string &name, const int &domain, const string &desc="", const double &l_bound=0.0, const double &u_bound=UBOUND_MAX, const string &l_bound_var="", const string &u_bound_var="")
Declare a single variable, its domain and its bounds. 
 
int getConstrainDirectionByIndex(int idx)
Return the direction of a given constrain. 
 
void calculateSparsityPatternJ()
 
void calculateSparsityPatternH()
 
virtual void generate_tapes(Index n, Index m, Index &nnz_jac_g, Index &nnz_h_lag)
 
void calculateNumberVariablesConstrains()
calculate the number of variables and constrains 
 
virtual bool intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
 
void cacheInitialPosition()
cache the initial positions of the variables and the constrains