/home/coin/SVN-release/OS-2.1.1/Couenne/src/problem/CouenneRestoreUnused.cpp

Go to the documentation of this file.
00001 /* $Id: CouenneRestoreUnused.cpp 215 2009-07-08 15:43:38Z pbelotti $
00002  *
00003  * Name:    CouenneRestoreUnused.cpp
00004  * Authors: Pietro Belotti, Lehigh University
00005  * Purpose: Restore a consistent value of duplicate variables 
00006  *
00007  * This file is licensed under the Common Public License (CPL)
00008  */
00009 
00010 #include "CouenneProblem.hpp"
00011 
00012 
00017 void CouenneProblem::createUnusedOriginals () {
00018 
00019   if (nUnusedOriginals_ < 0) { // no structure yet, identify and store
00020 
00021     nUnusedOriginals_ = 0;
00022 
00023     int 
00024       nOrig = nOrigVars (),
00025       nvars = nVars     ();
00026 
00027     unusedOriginalsIndices_ = (int *) malloc (nvars * sizeof (int)); // will trim it later
00028 
00029     for (int i=0; i<nvars; i++) {
00030 
00031       int indVar = numbering_ [i];
00032 
00033       if ((indVar < nOrig) && 
00034           (variables_ [indVar] -> Multiplicity () <= 0)) // found neglected variable!
00035         unusedOriginalsIndices_ [nUnusedOriginals_++] = indVar;
00036     }
00037 
00038     if (nUnusedOriginals_)
00039       unusedOriginalsIndices_ = (int *) realloc (unusedOriginalsIndices_, 
00040                                                  nUnusedOriginals_ * sizeof (int));
00041     else {
00042       free (unusedOriginalsIndices_);
00043       unusedOriginalsIndices_ = NULL;
00044     }
00045   }
00046 }
00047 
00048 
00052 void CouenneProblem::restoreUnusedOriginals (CouNumber *x) const {
00053 
00054   if (nUnusedOriginals_ <= 0) return;
00055 
00056   if (x)
00057     domain_.push (nVars(), x, NULL, NULL, false); // no need for another copy
00058 
00059   for (int i=0; i<nUnusedOriginals_; i++) {
00060 
00061     int indVar = unusedOriginalsIndices_ [i];
00062     expression *img = variables_ [indVar] -> Image ();
00063 
00064     if (img) {
00065 
00066       CouNumber value = (*img) ();
00067 
00068       X  (indVar) = value;
00069 
00070       if (x)
00071         x  [indVar] = value;
00072     }
00073   }
00074 
00075   if (x)
00076     domain_. pop ();
00077 }

Generated on Mon May 3 03:05:21 2010 by  doxygen 1.4.7