/home/coin/SVN-release/OS-2.1.0/Couenne/src/problem/reformulate.cpp

Go to the documentation of this file.
00001 /* $Id: reformulate.cpp 230 2009-07-18 11:42:59Z pbelotti $
00002  *
00003  * Name:    reformulate.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: apply reformulation
00006  *
00007  * This file is licensed under the Common Public License (CPL)
00008  */
00009 
00010 #include <vector>
00011 
00012 #include "CoinHelperFunctions.hpp"
00013 #include "CoinTime.hpp"
00014 
00015 #include "CouenneTypes.hpp"
00016 
00017 #include "exprVar.hpp"
00018 
00019 #include "CouenneProblem.hpp"
00020 #include "depGraph.hpp"
00021 #include "lqelems.hpp"
00022 
00023 
00025 void CouenneProblem::reformulate (CouenneCutGenerator *cg) {
00026 
00027   double now = CoinCpuTime ();
00028 
00029   if (domain_.current () == NULL) {
00030 
00031     // create room for problem's variables and bounds, if no domain exists
00032     CouNumber 
00033       *x  = (CouNumber *) malloc ((nVars()) * sizeof (CouNumber)),
00034       *lb = (CouNumber *) malloc ((nVars()) * sizeof (CouNumber)),
00035       *ub = (CouNumber *) malloc ((nVars()) * sizeof (CouNumber));
00036 
00037     for (int i = nVars(); i--;) {
00038       x  [i] =  0.;
00039       lb [i] = -COUENNE_INFINITY;
00040       ub [i] =  COUENNE_INFINITY;
00041     }
00042 
00043     domain_.push (nVars (), x, lb, ub);
00044   }
00045 
00046   // link initial variables to problem's domain
00047   for (std::vector <exprVar *>::iterator i = variables_.begin ();
00048        i != variables_.end (); ++i)
00049     (*i) -> linkDomain (&domain_);
00050 
00051   if (jnlst_ -> ProduceOutput(Ipopt::J_SUMMARY, J_PROBLEM))
00052     print (std::cout);
00053 
00054   // save -- for statistic purposes -- number of original
00055   // constraints. Some of them will be deleted as definition of
00056   // auxiliary variables.
00057   nOrigCons_    = constraints_. size ();
00058   nOrigIntVars_ = nIntVars ();
00059 
00060   jnlst_->Printf (Ipopt::J_ERROR, J_PROBLEM,
00061                   "Problem size before reformulation: %d variables (%d integer), %d constraints.\n",
00062                   nOrigVars_, nOrigIntVars_, nOrigCons_);
00063 
00064   // reformulation
00065   if (!standardize ()) { // problem is infeasible if standardize returns false
00066 
00067     jnlst_->Printf(Ipopt::J_ERROR, J_PROBLEM,
00068                    "Couenne: problem infeasible after reformulation\n");
00069     // fake infeasible bounds for Couenne to bail out
00070     for (int i = nVars (); i--;)
00071       Ub (i) = - (Lb (i) = 1.);
00072   }
00073 
00074   // clear all spurious variables pointers not referring to the variables_ vector
00075   realign ();
00076 
00077   // give a value to all auxiliary variables. Do it now to be able to
00078   // recognize complementarity constraints in fillDependence()
00079   initAuxs ();
00080 
00081   // fill dependence_ structure
00082   fillDependence (bonBase_, cg);
00083 
00084   // quadratic handling
00085   fillQuadIndices ();
00086 
00087   if ((now = (CoinCpuTime () - now)) > 10.)
00088     jnlst_->Printf(Ipopt::J_ERROR, J_PROBLEM,
00089     "Couenne: reformulation time %.3fs\n", now);
00090 
00091   jnlst_->Printf (Ipopt::J_WARNING, J_PROBLEM, "Initializing auxiliaries\n");
00092 
00093   // give a value to all auxiliary variables
00094   initAuxs ();
00095 
00096   int nActualVars = nIntVars_ = 0;
00097 
00098   // check how many integer variables we have now (including aux)
00099   for (int i=0; i<nVars(); i++)
00100     if (variables_ [i] -> Multiplicity () > 0) {
00101 
00102       nActualVars++;
00103       if (variables_ [i] -> isDefinedInteger ())
00104         nIntVars_++;
00105     }
00106 
00107   jnlst_->Printf(Ipopt::J_ERROR, J_PROBLEM,
00108                   "Problem size after  reformulation: %d variables (%d integer), %d constraints.\n",
00109                   nActualVars, nIntVars_, nCons());
00110 
00111   // check if optimal solution is available (for debug purposes)
00112   readOptimum ();
00113 
00114   if (bonBase_) {
00115 
00116     CouNumber 
00117       art_cutoff =  COIN_DBL_MAX,
00118       art_lower  = -COIN_DBL_MAX;
00119 
00120     bonBase_ -> options() -> GetNumericValue ("art_cutoff", art_cutoff, "couenne.");
00121     bonBase_ -> options() -> GetNumericValue ("art_lower",  art_lower,  "couenne.");
00122 
00123     if (art_cutoff <  1.e50) setCutOff (art_cutoff);
00124     if (art_lower  > -1.e50) {
00125       int indobj = objectives_ [0] -> Body () -> Index ();
00126       if (indobj >= 0)
00127         domain_.lb (indobj) = art_lower;
00128     }
00129   }
00130 
00131   if (jnlst_->ProduceOutput(Ipopt::J_DETAILED, J_PROBLEM)) {
00132     // We should route that also through the journalist
00133     print (std::cout);
00134   }
00135 
00136   createUnusedOriginals ();
00137 
00138   //writeAMPL ("extended-aw.mod", true);
00139   //writeAMPL ("original.mod", false);
00140 }

Generated on Tue Mar 30 03:04:38 2010 by  doxygen 1.4.7