Changeset 295


Ignore:
Timestamp:
Feb 13, 2010 9:07:28 AM (11 years ago)
Author:
pbelotti
Message:

fixed bug in checkNLP -- not checking all aux. Adding information on common expressions

Location:
trunk/Couenne/src/problem
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/problem/checkNLP.cpp

    r154 r295  
    1 /* $Id$ */
    2 /*
     1/* $Id$
     2 *
    33 * Name:    checkNLP.cpp
    44 * Author:  Pietro Belotti
    55 * Purpose: check NLP feasibility of incumbent integer solution
    66 *
    7  * (C) Carnegie-Mellon University, 2006-09.
     7 * (C) Carnegie-Mellon University, 2006-10.
    88 * This file is licensed under the Common Public License (CPL)
    99 */
     
    1515bool CouenneProblem::checkNLP (const double *solution, double &obj, bool recompute) const {
    1616
    17   const int infeasible = 1;
    18   const int wrong_obj  = 2;
    19 
    20   /*printf ("checking solution: [%.12e] ", obj);
    21   for (int i=0; i<nOrigVars_; i++)
    22     printf ("%.12e ", solution [i]);
    23     printf ("\n");*/
    24 
    25   // pre-check on original variables
    26   for (int i=0; i < nOrigVars_; i++) {
     17  if (Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM)) {
     18
     19    printf ("checking solution: [%.12e] ", obj);
     20
     21    for (int i=0; i<nOrigVars_; i++)
     22      printf ("%.12e ", solution [i]);
     23    printf ("\n");
     24  }
     25
     26  // pre-check on original variables --- this is done after every LP,
     27  // and should be efficient
     28  for (register int i=0; i < nOrigVars_; i++) {
    2729
    2830    CouNumber val = solution [i];
     
    3032    // check (original and auxiliary) variables' integrality
    3133
    32     if ((variables_ [i] -> isInteger ()) &&
    33         (variables_ [i] -> Type () == VAR) &&
    34         (variables_ [i] -> Multiplicity () > 0) &&
     34    exprVar *v = variables_ [i];
     35
     36    if ((v -> Type ()      == VAR) &&
     37        (v -> Multiplicity () > 0) &&
     38        (v -> isInteger ())        &&
    3539        (fabs (val - COUENNE_round (val)) > feas_tolerance_)) {
    3640
     
    4246    }
    4347  }
     48
     49  const int infeasible = 1;
     50  const int wrong_obj  = 2;
    4451
    4552  CouNumber *sol = new CouNumber [nVars ()];
     
    5461  domain_.push (nVars (), sol, domain_.lb (), domain_.ub (), false);
    5562
    56   /*printf ("checknlp: %d vars -------------------\n", domain_.current () -> Dimension ());
    57   for (int i=0; i<domain_.current () -> Dimension (); i++)
    58     printf ("%4d %.12e [%.12e %.12e]\n",
    59     i, domain_.x (i), domain_.lb (i), domain_.ub (i));*/
     63
     64  if (Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM)) {
     65    printf ("checknlp: %d vars -------------------\n", domain_.current () -> Dimension ());
     66    for (int i=0; i<domain_.current () -> Dimension (); i++)
     67      printf ("%4d %.12e [%.12e %.12e]\n",
     68              i, domain_.x (i), domain_.lb (i), domain_.ub (i));
     69  }
    6070
    6171  expression *objBody = Obj (0) -> Body ();
     
    7484      (*(objBody -> Image () ? objBody -> Image () : objBody)) ();
    7585
    76   /*printf ("%.12e %.12e %.12e ------------------------------\n",
    77           realobj, sol [objBody -> Index ()],
    78           (*(objBody -> Image () ? objBody -> Image () : objBody)) ());*/
     86  if (Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM)) {
     87    printf ("%.12e %.12e %.12e ------------------------------\n",
     88            realobj, sol [objBody -> Index ()],
     89            (*(objBody -> Image () ? objBody -> Image () : objBody)) ());
     90  }
    7991
    8092  bool retval = true;
     
    8395
    8496    // check if objective corresponds
    85 
     97   
    8698    if (fabs (realobj - obj) / (1. + fabs (realobj)) > feas_tolerance_) {
    8799
     
    97109      obj = realobj;
    98110
    99     //printf ("recomputed: %.12e\n", obj);
     111    if (Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM))
     112      printf ("recomputed: %.12e\n", obj);
    100113
    101114    for (int i=0; i < nOrigVars_; i++) {
     
    130143        throw infeasible;
    131144      }
    132 
    133       /*if (variables_ [i] -> Type () == AUX) {
    134         printf ("checking aux ");
    135         variables_ [i] -> print (); printf (" := ");
    136         variables_ [i] -> Image () -> print ();
    137         printf (" --- %.12e = %.12e [%.12e]; {",
    138                 (*(variables_ [i])) (),
    139                 (*(variables_ [i] -> Image ())) (),
    140                 (*(variables_ [i])) () -
    141                 (*(variables_ [i] -> Image ())) ());
    142         for (int j=0; j<nVars (); j++)
    143           printf ("%.12e ", (*(variables_ [j])) ());
    144         printf ("}\n");
    145         }*/
     145    }
     146
     147    // check ALL auxs
     148
     149    for (int i=0; i < nVars (); i++) {
     150
     151      if (Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_PROBLEM)) {
     152        if (variables_ [i] -> Type () == AUX) {
     153          printf ("checking aux ");
     154          variables_ [i] -> print (); printf (" := ");
     155          variables_ [i] -> Image () -> print ();
     156          printf (" --- %.12e = %.12e [%.12e]; {",
     157                  (*(variables_ [i])) (),
     158                  (*(variables_ [i] -> Image ())) (),
     159                  (*(variables_ [i])) () -
     160                  (*(variables_ [i] -> Image ())) ());
     161          //for (int j=0; j<nVars (); j++)
     162          //printf ("%.12e ", (*(variables_ [j])) ());
     163          printf ("}\n");
     164        }
     165      }
    146166
    147167      CouNumber delta;
     
    171191        rhs  = (*(c -> Ub   ())) ();
    172192
    173       if ((rhs < COUENNE_INFINITY) &&
    174            (body > rhs + feas_tolerance_ * (1 + CoinMax (fabs (body), fabs (rhs)))) ||
    175           (lhs > -COUENNE_INFINITY) &&
    176           (body < lhs - feas_tolerance_ * (1 + CoinMax (fabs (body), fabs (lhs))))) {
     193      if (((rhs < COUENNE_INFINITY) &&
     194           (body > rhs + feas_tolerance_ * (1 + CoinMax (fabs (body), fabs (rhs))))) ||
     195          ((lhs > -COUENNE_INFINITY) &&
     196           (body < lhs - feas_tolerance_ * (1 + CoinMax (fabs (body), fabs (lhs)))))) {
    177197
    178198        if (Jnlst()->ProduceOutput(Ipopt::J_MOREVECTOR, J_PROBLEM)) {
    179199
    180           Jnlst()->Printf
    181             (Ipopt::J_MOREVECTOR, J_PROBLEM,
    182              "checkNLP: constraint %d violated (lhs=%+e body=%+e rhs=%+e, violation %g): ",
    183              i, lhs, body, rhs, CoinMax (lhs-body, body-rhs));
     200          printf ("checkNLP: constraint %d violated (lhs=%+e body=%+e rhs=%+e, violation %g): ",
     201                  i, lhs, body, rhs, CoinMax (lhs-body, body-rhs));
    184202
    185203          c -> print ();
  • trunk/Couenne/src/problem/problemIO.cpp

    r223 r295  
    1 /* $Id$ */
    2 /*
     1/* $Id$
     2 *
    33 * Name:    problemIO.cpp
    44 * Author:  Pietro Belotti
    55 * Purpose: methods of the class CouenneProblem
    66 *
    7  * (C) Carnegie-Mellon University, 2006.
     7 * (C) Carnegie-Mellon University, 2006-10.
    88 * This file is licensed under the Common Public License (CPL)
    99 */
     
    7171    for (std::vector <expression *>::iterator i = commonexprs_.begin ();
    7272         i != commonexprs_.end (); ++i) {
     73      out << "v["    << i - commonexprs_.begin () << "] := ";
    7374      (*i) -> print (out);
    7475      out << std::endl;
Note: See TracChangeset for help on using the changeset viewer.