Changeset 585


Ignore:
Timestamp:
Jun 11, 2007 2:17:15 PM (12 years ago)
Author:
pbonami
Message:

Fix extractLinear relaxation for GAMS matrices, remove a few std::cout

Location:
trunk/Bonmin/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonEcpCuts.cpp

    r583 r585  
    4444  double violation = nlp_->getNonLinearitiesViolation(
    4545                     si.getColSolution(), si.getObjValue());
    46   //  std::cout<<"Constraint violation: "<<violation<<std::endl;
    47 
     46#ifdef ECP_DEBUG
     47  std::cout<<"Constraint violation: "<<violation<<std::endl;
     48#endif
    4849  //Get a random number
    4950  if(violation <= 1e-12)
    5051    return;
     52#ifdef ECP_DEBUG
    5153  std::cout<<"Generating ECP cuts"<<std::endl;
     54#endif
    5255  solverManip * lpManip = NULL;
    5356  bool infeasible = false;
     
    7477        {
    7578          infeasible = true;
    76           //      std::cout<<"Stopping Ecp generation because problem became infeasible"<<std::endl;
     79#ifdef ECP_DEBUG
     80                std::cout<<"Stopping Ecp generation because problem became infeasible"<<std::endl;
     81#endif
    7782          break;
    7883        }
     
    8085                     lpManip->si()->getColSolution(),
    8186                     lpManip->si()->getObjValue());
    82         //        std::cout<<"Constraint violation: "<<violation<<std::endl;
     87#ifdef ECP_DEBUG
     88        std::cout<<"Constraint violation: "<<violation<<std::endl;
     89#endif
    8390         }
    8491      else break;
     
    105112      delete lpManip;
    106113    }
    107   //  std::cout<<"End ecp cut generation"<<std::endl;
     114#ifdef ECP_DEBUG
     115  std::cout<<"End ecp cut generation"<<std::endl;
     116#endif
    108117  return;
    109118}
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOaFeasChecker.cpp

    r481 r585  
    137137      }
    138138#ifdef OA_DEBUG
    139     debug_.printEndOfProcedureDebugMessage(cs, foundSolution, milpBound, isInteger, feasible, std::cout);
     139   debug_.printEndOfProcedureDebugMessage(cs, foundSolution, milpBound, isInteger, feasible, std::cout);
     140   std::cout<<"milpBound found: "<<milpBound<<std::endl;
    140141#endif
    141    std::cout<<"milpBound found: "<<milpBound<<std::endl;
    142142   if(usingCouenne)
    143143     delete [] nlpSol;
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOaNlpOptim.cpp

    r488 r585  
    104104          char type='<';
    105105          if (rowLower[i]>-1e20) type='>';
     106#ifdef OA_DEBUG
    106107          std::cout<<"Non zero with sign: "<<sign<<", type: "<<type<<std::endl;
     108#endif
    107109        }
    108110      }
     
    111113        continue;
    112114      }
     115#ifdef OA_DEBUG
    113116      else
    114117        std::cout<<"No nonzero element"<<std::endl;
     118#endif
    115119      int * indsCopy = CoinCopyOfArray(&indices[starts[i]], lengths[i]);
    116120      double * elemsCopy = CoinCopyOfArray(&elements[starts[i]], lengths[i]);
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.cpp

    r561 r585  
    251251      (3012,1,"resolve called before any call to initialSolve"
    252252       " can not use warm starts."));
     253  addMessage(ERROR_NO_TNLPSOLVER, CoinOneMessage
     254             (3013,1,"Can not parse options when no IpApplication has been created"));
     255                                               
    253256
    254257}
     
    589592{
    590593  if(!IsValid(app_)) {
    591     std::cout<<"Can not parse options when no IpApplication has been created"<<std::endl;
     594    messageHandler()->message(ERROR_NO_TNLPSOLVER, messages_)<<CoinMessageEol;
    592595    return NULL;
    593596  }
     
    14721475  jValues_ = new Number[nnz_jac];
    14731476  tminlp_->eval_jac_g(n, NULL, 0, m, nnz_jac, jRow_, jCol_, NULL);
    1474 
     1477  if(index_style == Ipopt::TNLP::FORTRAN_STYLE)//put C-style
     1478  {
     1479    for(int i = 0 ; i < nnz_jac ; i++){
     1480      jRow_[i]--;
     1481      jCol_[i]--;
     1482    }
     1483  }
    14751484
    14761485  if(constTypes_ != NULL) delete [] constTypes_;
     
    19411950    initialSolve();
    19421951
    1943   CoinPackedMatrix mat;
    19441952  double * rowLow = NULL;
    19451953  double * rowUp = NULL;
     
    19521960  //Get problem information
    19531961  tminlp_->get_nlp_info( n, m, nnz_jac_g, nnz_h_lag, index_style);
    1954   int offset = index_style == TNLP::FORTRAN_STYLE;
    19551962  //if not allocated allocate spaced for stroring jacobian
    19561963  if(jRow_ == NULL || jCol_ == NULL || jValues_ == NULL)
     
    19661973  rowLow = new double[m];
    19671974  rowUp = new double[m];
    1968   int * binding = new int[m];//store binding constraints at current opt (which are added to OA) -1 if constraint is not binding, otherwise index in subset of binding constraints
    1969   int numBindings = 0;
     1975  int * nonBindings = new int[m];//store non binding constraints (which are to be removed from OA)
     1976  int numNonBindings = 0;
    19701977  const double * rowLower = getRowLower();
    19711978  const double * rowUpper = getRowUpper();
     
    19761983  double infty = getInfinity();
    19771984  double nlp_infty = infty_;
     1985 
    19781986  for(int i = 0 ; i < m ; i++) {
    1979     {
    1980       if(constTypes_[i] == TNLP::NON_LINEAR) {
    1981         //If constraint is equality not binding do not add
    1982         if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty && fabs(duals[i]) == 0.)
    1983         {
    1984             binding[i] = -1;
    1985             continue;
    1986         }
    1987         else
    1988           binding[i] = numBindings;
     1987  {
     1988    if(constTypes_[i] == TNLP::NON_LINEAR) {
     1989      //If constraint is range not binding prepare to remove it
     1990      if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty && fabs(duals[i]) == 0.)
     1991      {
     1992        nonBindings[numNonBindings++] = i;
     1993        continue;
     1994      }
     1995      else
    19891996        if(rowLower[i] > - nlp_infty)
    1990           rowLow[numBindings] = (rowLower[i] - g[i]) - 1e-07;
    1991         else
    1992           rowLow[numBindings] = - infty;
    1993         if(rowUpper[i] < nlp_infty)
    1994           rowUp[numBindings] =  (rowUpper[i] - g[i]) + 1e-07;
    1995         else
    1996           rowUp[numBindings] = infty;
    1997        
    1998         //If equality or ranged constraint only add one side by looking at sign of dual multiplier
    1999         if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty)
    2000         {
    2001           if(duals[i] >= 0)// <= inequality
    2002             rowLow[numBindings] = - infty;
    2003           if(duals[i] <= 0)// >= inequality
    2004             rowUp[numBindings] = infty;
    2005         }
    2006         numBindings++;
     1997          rowLow[i] = (rowLower[i] - g[i]) - 1e-07;
     1998      else
     1999        rowLow[i] = - infty;
     2000      if(rowUpper[i] < nlp_infty)
     2001        rowUp[i] =  (rowUpper[i] - g[i]) + 1e-07;
     2002      else
     2003        rowUp[i] = infty;
     2004     
     2005      //If equality or ranged constraint only add one side by looking at sign of dual multiplier
     2006      if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty)
     2007      {
     2008        if(duals[i] >= 0)// <= inequality
     2009          rowLow[i] = - infty;
     2010        if(duals[i] <= 0)// >= inequality
     2011          rowUp[i] = infty;
    20072012      }
    2008       else {
    2009         binding[i] = numBindings;//All are considered as bindings
    2010         rowLow[numBindings] = (rowLower[i] - g[i]);
    2011         rowUp[numBindings] =  (rowUpper[i] - g[i]);
    2012         numBindings++;
    2013       }
    2014     }
    2015   }
    2016 
    2017   //Then convert everything to a CoinPackedMatrix (col ordered)
    2018   CoinBigIndex * inds = new CoinBigIndex[nnz_jac_g + 1];
    2019   double * vals = new double [nnz_jac_g + 1];
    2020   int * start = new int[n+1];
    2021   int * length = new int[n];
    2022   bool needOrder = false;
    2023   int nnz = 0;
    2024   if(nnz_jac_g > 0)
    2025   {
    2026   for(int k = 0; k < jCol_[0]; k++) {
    2027     start[k] = nnz;
    2028     length[k] = 0;
    2029   }
    2030   for(int i = 0 ; i < nnz_jac_g - 1 ; i++) {
    2031     {
    2032       if(jCol_[i + 1] < jCol_ [i] || ( jCol_ [i+1] == jCol_[i] && jRow_[i + 1] <= jRow_[i]) ) {
    2033         needOrder = 1;
    2034         break;
    2035       }
    2036       if(TNLP::LINEAR //Always accept coefficients from linear constraints
    2037           || //For other clean tinys
    2038           cleanNnz(jValues_[i],colLower[jCol_[i] - offset], colUpper[jCol_[i]-offset],
    2039               rowLower[jRow_[i] - offset], rowUpper[jRow_[i] - offset],
    2040               getColSolution()[jCol_[i] - offset],
    2041               rowLow[binding[jRow_[i] - offset]],
    2042               rowUp[binding[jRow_[i] -offset]], tiny_, veryTiny_)) {
    2043         if(binding[jRow_[i] - offset] == -1) continue;
    2044         vals[nnz] = jValues_[i];
    2045         if(rowLow[binding[jRow_[i] - offset]] > - infty_)
    2046           rowLow[binding[jRow_[i] - offset]] += jValues_[i] * getColSolution()[jCol_ [i] - offset];
    2047         if(rowUp[binding[jRow_[i] - offset]] < infty_)
    2048           rowUp[binding[jRow_[i] -offset]] += jValues_[i] *getColSolution()[jCol_[i] -offset];
    2049         inds[nnz] = binding[jRow_[i] - offset];//jRow_[i ] - 1;
    2050         length[jCol_[i] - offset]++;
    2051         nnz++;
    2052       }
    2053     }
    2054     if(jCol_[i + 1] > jCol_[i]) {
    2055       for(int k = jCol_[i]; k < jCol_[i + 1]; k++) {
    2056         start[k] = nnz;
    2057         length[k] = 0;
    2058       }
    2059     }
    2060   }
    2061   if(!needOrder) {
    2062     {
    2063       length[jCol_[nnz_jac_g -1] - offset]++;
    2064       vals[nnz] = jValues_[nnz_jac_g - 1];
    2065       rowLow[binding[jRow_[nnz_jac_g - 1] - 1]] += jValues_[nnz_jac_g - 1] * getColSolution()[jCol_ [nnz_jac_g - 1] - offset];
    2066       rowUp[binding[jRow_[nnz_jac_g - 1] -offset]] += jValues_[nnz_jac_g - 1] *getColSolution()[jCol_[nnz_jac_g - 1] -offset];
    2067       inds[nnz++] = binding[jRow_[nnz_jac_g - 1] - offset];
    2068     }
    2069     for(int i = jCol_[nnz_jac_g -1] ; i < n ; i++) {
    2070       start[i] = nnz;
    2071       length[i] = 0;
    2072     }
    2073     start[n]=nnz;
    2074   }
    2075   else {
    2076     std::cerr<<"jacobian matrix is not ordered properly"<<std::endl;
    2077     throw -1;
    2078   }
    2079   delete [] g;
    2080   }
    2081   else {
    2082    for (int i = 0 ; i < n ; i++)
    2083    {
    2084      length[i] = 0;
    2085      start[i] = 0;
    2086    }
    2087    start[n]=0;
    2088  }
    2089  mat.assignMatrix(false, m, n, nnz, vals, inds, start, length);
     2013    }
     2014    else {
     2015      rowLow[i] = (rowLower[i] - g[i]);
     2016      rowUp[i] =  (rowUpper[i] - g[i]);
     2017    }
     2018  }
     2019  }
     2020 
     2021 
     2022  //Then convert everything to a CoinPackedMatrix
     2023  //Go through values, clean coefficients and fix bounds
     2024  for(int i = 0 ; i < nnz_jac_g ; i++) {
     2025    if(constTypes_[jRow_[i]] == TNLP::LINEAR //Always accept coefficients from linear constraints
     2026       || //For other clean tinys
     2027       cleanNnz(jValues_[i],colLower[jCol_[i]], colUpper[jCol_[i]],
     2028                rowLower[jRow_[i]], rowUpper[jRow_[i]],
     2029                getColSolution()[jCol_[i]],
     2030                rowLow[jRow_[i]],
     2031                rowUp[jRow_[i]], tiny_, veryTiny_)) {     
     2032      rowLow[jRow_[i]] += jValues_[i] * getColSolution()[jCol_ [i]];
     2033      rowUp[jRow_[i]] += jValues_[i] *getColSolution()[jCol_[i]];
     2034    }
     2035  }
     2036  CoinPackedMatrix mat(true, jRow_, jCol_, jValues_, nnz_jac_g);
     2037 
     2038 
     2039
     2040  //remove non-bindings equality constraints
     2041  mat.deleteRows(numNonBindings, nonBindings);
     2042 
    20902043  int numcols=getNumCols();
    20912044  double *obj = new double[numcols];
    20922045  for(int i = 0 ; i < numcols ; i++)
    20932046    obj[i] = 0;
    2094   mat.transpose();
    2095  
    2096 #if 0
    2097   std::cout<<"Mat is ordered by "<<
    2098   <<mat.isColOrdered?"columns.":"rows."
    2099   <<std::endl;
    2100 #endif
     2047 
    21012048 
    21022049  si.loadProblem(mat, getColLower(), getColUpper(), obj, rowLow, rowUp);
    21032050  delete [] rowLow;
    21042051  delete [] rowUp;
    2105   delete [] binding;
     2052  delete [] nonBindings;
    21062053  for(int i = 0 ; i < getNumCols() ; i++) {
    21072054    if(isInteger(i))
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.hpp

    r541 r585  
    102102                                              was no previous call to initialSolve().
    103103                                         */,
     104    ERROR_NO_TNLPSOLVER /** Trying to access non-existent TNLPSolver*/,
    104105    OSITMINLPINTERFACE_DUMMY_END
    105106  };
Note: See TracChangeset for help on using the changeset viewer.