source: trunk/Couenne/src/bound_tightening/impliedBounds.cpp @ 112

Last change on this file since 112 was 112, checked in by pbelotti, 11 years ago

isolate restoreUnused to when there is at least one unused -- takes care of reformulated stockcycle problem (thanks to C. D'Ambrosio for the bug report). Check linear terms before adding a full exprGroup -- need a constructor pilot. Quicker solution feasibility check (with initial integrality check).

File size: 4.6 KB
Line 
1/*
2 * Name:    impliedBounds.cpp
3 * Author:  Pietro Belotti
4 * Purpose: backward implied bound search
5 *
6 * (C) Carnegie-Mellon University, 2006.
7 * This file is licensed under the Common Public License (CPL)
8 */
9
10#include "CouenneProblem.hpp"
11
12/// Bound tightening for auxiliary variables
13
14int CouenneProblem::impliedBounds (t_chg_bounds *chg_bds) const {
15
16  int nchg = 0; //< number of bounds changed for propagation
17
18  if (Jnlst()->ProduceOutput(Ipopt::J_DETAILED, J_BOUNDTIGHTENING)) { 
19    Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,"  backward =====================\n  ");
20    int j=0;
21    for (int i=0; i < nVars (); i++) 
22      if (variables_ [i] -> Multiplicity () >= 0) {
23        Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,
24                        "x_%03d [%+15.8g %+15.8g] ", i, 
25                        domain_.lb (i),
26                        domain_.ub (i));
27        if (!(++j % 6)) Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,"\n  ");
28      }
29    if (j % 6) Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,"\n");
30    }
31
32  for (int ii = nVars (); ii--;) {
33
34    int i = numbering_ [ii];
35
36    if ((variables_ [i] -> Type () == AUX) &&
37        (variables_ [i] -> Multiplicity () > 0)) {
38
39      if (Lb (i) > Ub (i) + COUENNE_EPS) {
40        Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
41                        "  implied bounds: w_%d has infeasible bounds [%g,%g]\n", 
42                        i, Lb (i), Ub (i));
43        return -1;
44      }
45
46      //    if ((auxiliaries_ [i] -> Image () -> code () == COU_EXPRSUM) ||
47      //        (auxiliaries_ [i] -> Image () -> code () == COU_EXPRGROUP))
48
49      /*if (auxiliaries_ [i] -> Image () -> Argument () ||
50          auxiliaries_ [i] -> Image () -> ArgList  ()) {
51
52        expression *arg = auxiliaries_ [i] -> Image () -> Argument ();
53        if (!arg)   arg = auxiliaries_ [i] -> Image () -> ArgList  () [0];
54
55        printf (":::: ");
56          arg -> print (std::cout);
57          if (arg -> Index () >= 0) {
58          int ind = arg -> Index ();
59          printf (" in [%g,%g]",
60          expression::Lbound (ind),
61          expression::Ubound (ind));
62          }
63          printf ("\n");
64      }*/
65
66      // TODO: also test if this expression, or any of its indep
67      // variables, have changed. If not, skip
68
69      CouNumber
70        l0 = Lb (i), 
71        u0 = Ub (i);
72
73      if (variables_ [i] -> Image () -> impliedBound
74          (variables_ [i] -> Index (), Lb (), Ub (), chg_bds)) {
75
76        // conservative check for integer variables.
77        /*if (Var (i) -> isInteger ()) {
78          Lb (i) = ceil  (Lb (i) - COUENNE_EPS);
79          Ub (i) = floor (Ub (i) + COUENNE_EPS);
80          }*/
81
82        if (Jnlst()->ProduceOutput(Ipopt::J_VECTOR, J_BOUNDTIGHTENING)) {
83          // todo: send all output through journalist
84          Jnlst()->Printf(Ipopt::J_VECTOR, J_BOUNDTIGHTENING,
85                          "  impli %2d [%15.8g, %15.8g] -> [%15.8g, %15.8g]: ",
86                          i, l0, u0, Lb (i), Ub (i));
87
88          variables_ [i]             -> print (std::cout);
89
90          if (Jnlst()->ProduceOutput(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING)) {
91            Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING," := ");
92            variables_ [i] -> Image () -> print (std::cout);
93          }
94
95          Jnlst()->Printf(Ipopt::J_VECTOR, J_BOUNDTIGHTENING,"\n");
96        }
97
98        /*if (optimum_ &&
99            ((optimum_ [i] < Lb (i) - COUENNE_EPS) ||
100             (optimum_ [i] > Ub (i) + COUENNE_EPS)))
101          Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
102                          "#### implied b_%d [%g,%g] cuts optimum %g: [%g --> %g, %g <-- %g]\n",
103                          i+nvar, expression::Lbound (i+nvar), expression::Ubound (i+nvar),
104                          optimum_ [i+nvar], l0, lb_ [i+nvar], ub_ [i+nvar], u0);*/
105
106        //printf ("impli %2d ", nvar+i);
107
108        /*if (variables_ [i] -> Image () -> Argument () ||
109            variables_ [i] -> Image () -> ArgList ()) {
110
111          expression *arg = variables_ [i] -> Image () -> Argument ();
112
113          if (!arg) {
114            for (int k=0; k < variables_ [i] -> Image () -> nArgs (); k++) {
115              arg =  variables_ [i] -> Image () -> ArgList () [k];
116              Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," ");
117              arg -> print (std::cout);
118              if (arg -> Index () >= 0) {
119                int ind = arg -> Index ();
120                Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
121                                " in [%g,%g]",
122                                expression::Lbound (ind),
123                                expression::Ubound (ind));
124              }     
125            }
126          } else {
127            Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," ");
128            arg -> print (std::cout);
129            if (arg -> Index () >= 0) {
130              int ind = arg -> Index ();
131              Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," in [%g,%g]",
132                      expression::Lbound (ind),
133                      expression::Ubound (ind));
134            }
135          }
136        } else Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," [no args]");
137        Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,"\n");*/
138
139        nchg++;
140      }
141    }
142  }
143
144  if (nchg)
145    Jnlst () -> Printf (J_DETAILED, J_BOUNDTIGHTENING,
146                        "  implied bounds: %d changes\n", nchg);
147
148  return nchg;
149}
Note: See TracBrowser for help on using the repository browser.