Changeset 616


Ignore:
Timestamp:
Jun 9, 2011 1:58:42 AM (9 years ago)
Author:
pbelotti
Message:

making Lagrangian Hessian changeable between iterations

Location:
trunk/Couenne/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/heuristics/CouenneFPSolveNLP.cpp

    r613 r616  
    7373
    7474  problem_ -> setObjective (0, newObj);
     75  nlp_     -> setObjective (newObj);
    7576
    7677  printf ("FP: created obj\n");
     
    8485
    8586  printf ("FP: optimize\n");
     87
     88  problem_ -> print ();
    8689
    8790  ApplicationReturnStatus status = firstNLP ?
     
    106109
    107110  problem_ -> setObjective (0, oldObj);
     111  nlp_     -> setObjective (oldObj);
    108112
    109113  return nlp_ -> getSolValue ();
  • trunk/Couenne/src/heuristics/CouenneFeasPumpConstructors.cpp

    r615 r616  
    3333
    3434  ApplicationReturnStatus status = app_ -> Initialize ();
    35   app_ -> Options () -> SetIntegerValue ("max_iter", 50);
     35  app_ -> Options () -> SetIntegerValue ("max_iter", 500);
    3636  if (status != Solve_Succeeded)
    3737    printf ("FP: Error in initialization\n");
  • trunk/Couenne/src/interfaces/CouenneTNLP.cpp

    r615 r616  
    22 *
    33 * Name:    CouenneTNLP.cpp
    4  * Authors: Pietro Belotti, Lehigh University
     4 * Authors: Pietro Belotti
    55 * Purpose: Implementation of an NLP interface with gradient/Jacobian/etc
    66 *
     
    3636  if (sol_)  delete [] sol_;
    3737  if (sol0_) delete [] sol0_;
     38  if (HLa_)  delete HLa_;
    3839}
    3940
     
    4748  bestZ_   (COIN_DBL_MAX),
    4849  Jac_     (p),
    49   HLa_     (p) {
     50  HLa_     (new ExprHess (p)) {
    5051
    5152  std::set <int> objDep;
     
    130131
    131132  nnz_jac_g = Jac_.nnz ();
    132   nnz_h_lag = HLa_.nnz ();
     133  nnz_h_lag = HLa_ -> nnz ();
    133134
    134135  index_style = C_STYLE; // what else? ;-)
     
    477478      jCol   != NULL) {
    478479
     480    printf ("asking for dimensions\n");
     481
    479482    /// first call, must determine structure iRow/jCol
    480483
    481     CoinCopyN (HLa_.iRow (), nele_hess, iRow);
    482     CoinCopyN (HLa_.jCol (), nele_hess, jCol);
     484    CoinCopyN (HLa_ -> iRow (), nele_hess, iRow);
     485    CoinCopyN (HLa_ -> jCol (), nele_hess, jCol);
    483486
    484487  } else {
     
    492495
    493496      int
    494          numL = HLa_. numL () [i],
    495         *lamI = HLa_. lamI () [i];
    496 
    497       expression **expr = HLa_. expr () [i];
     497         numL = HLa_ -> numL () [i],
     498        *lamI = HLa_ -> lamI () [i];
     499
     500      expression **expr = HLa_ -> expr () [i];
    498501
    499502      for (int j=0; j<numL; j++)
     
    514517}
    515518
     519// Change objective function and modify gradient expressions
     520// accordingly
     521void CouenneTNLP::setObjective (expression *newObj) {
     522
     523  if (HLa_)
     524    delete HLa_;
     525
     526  // change the Hessian accordingly
     527
     528  HLa_ = new ExprHess (problem_);
     529
     530  std::set <int> objDep;
     531
     532  // objective of entering problem is reformulated, no need to go
     533  // further
     534  newObj -> DepList (objDep, STOP_AT_AUX);
     535
     536  printf ("new objective:");
     537  newObj -> print ();
     538  printf ("\n");
     539
     540  for (std::vector <std::pair <int, expression *> >::iterator i = gradient_. begin (); i != gradient_. end (); ++i)
     541    delete (*i). second;
     542
     543  gradient_ . erase (gradient_ . begin (), gradient_ . end ());
     544
     545  for (std::set <int>::iterator i = objDep.begin (); i != objDep. end (); ++i) {
     546
     547    expression *gradcomp = newObj -> differentiate (*i);
     548    gradcomp -> realign (problem_);
     549    gradient_ . push_back (std::pair <int, expression *> (*i, gradcomp));
     550
     551    printf ("objective depends on x_%d: derivative is ", *i);
     552    gradcomp -> print ();
     553    printf ("\n");
     554  }
     555}
    516556
    517557// This method is called when the algorithm is complete so the TNLP
  • trunk/Couenne/src/interfaces/CouenneTNLP.hpp

    r612 r616  
    166166                                                  Index* pos_nonlin_vars);
    167167
     168    // Change objective function and modify gradient expressions
     169    // accordingly
     170    virtual void setObjective (expression *newObj);
     171
    168172  private:
    169173
     
    191195    /// Hessian --- there are 1+m of them, but all are squeezed in a
    192196    /// single object
    193     ExprHess HLa_;
     197    ExprHess *HLa_;
    194198  };
    195199}
Note: See TracChangeset for help on using the changeset viewer.