Changeset 341 for stable/0.2/Couenne


Ignore:
Timestamp:
May 16, 2010 1:50:36 PM (10 years ago)
Author:
pbelotti
Message:

merged reformulation bugfix from trunk/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • stable/0.2/Couenne/src/standardize/constrStandardize.cpp

    r332 r341  
    1212#include "CouenneProblem.hpp"
    1313
     14#include "exprIVar.hpp"
    1415#include "exprAux.hpp"
     16#include "exprClone.hpp"
    1517#include "depGraph.hpp"
     18
     19// replace a variable
     20void replace (CouenneProblem *p, int wind, int xind);
    1621
    1722//#define DEBUG
     
    9398      int xind = rest -> Index ();
    9499
    95       if (false && (xind >= 0)) {
     100      if (xind >= 0) {
     101        // create new variable, it has to be integer if original variable was integer
     102        exprAux *w = new exprAux (new exprClone (p -> Var (xind)), wind, 1 + p -> Var (xind) -> rank (),
     103                                  p -> Var (wind) -> isInteger () ?
     104                                  exprAux::Integer : exprAux::Continuous,
     105                                  p -> domain ());
     106        p -> auxiliarize (w);
     107        w -> zeroMult ();
     108       
     109        replace (p, wind, xind);
     110
    96111        p -> auxiliarize (p -> Var (wind), p -> Var (xind));
    97         p -> Var (wind) -> zeroMult ();
     112        //p -> Var (wind) -> zeroMult (); // redundant variable is neutralized
     113
     114        // p -> auxiliarize (p -> Var (wind), p -> Var (xind));
     115        // p -> Var (wind) -> zeroMult ();
    98116      } else {
    99117
     
    144162  return body_ -> standardize (p);
    145163}
     164
     165
     166// Replace a variable ////////////////////////////////
     167void replace (CouenneProblem *p, int wind, int xind) {
     168
     169  exprVar
     170    *varLeaves = p -> Variables () [wind],
     171    *varStays  = p -> Variables () [xind];
     172
     173  // intersect features of the two variables (integrality, bounds)
     174
     175  varStays -> lb () = varLeaves -> lb () = CoinMax (varStays -> lb (), varLeaves -> lb ());
     176  varStays -> ub () = varLeaves -> ub () = CoinMin (varStays -> ub (), varLeaves -> ub ());
     177
     178  if (varStays  -> isInteger () ||
     179      varLeaves -> isInteger ()) {
     180
     181    varStays -> lb () = ceil  (varStays -> lb ());
     182    varStays -> ub () = floor (varStays -> ub ());
     183
     184    if (varStays -> Type () == AUX)
     185      varStays -> setInteger (true);
     186    else {
     187      //expression *old = varStays; // !!! leak
     188      p -> Variables () [xind] = varStays = new exprIVar (xind, p -> domain ());
     189      p -> auxiliarize (varStays); // replace it everywhere in the problem
     190      //delete old;
     191    }
     192  }
     193}
Note: See TracChangeset for help on using the changeset viewer.