1 /* $Id$
2  *
3  * Name:    CouenneBTPerfIndicatorConstr.cpp
4  * Author:  Pietro Belotti
5  * Purpose: Measures performance of BT in terms of shrunken bounds -- constructors
6  *
7  * (C) Pietro Belotti, 2011.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include "CouenneBTPerfIndicator.hpp"
12 #include "CouenneProblem.hpp"
13 #include "IpSmartPtr.hpp"
14 
15 
16 using namespace Couenne;
17 
18 ///
CouenneBTPerfIndicator(CouenneProblem * p,const std::string & name)19 CouenneBTPerfIndicator::CouenneBTPerfIndicator (CouenneProblem *p, const std::string &name):
20 
21   name_            (name),
22   nFixed_          (0.),
23   boundRatio_      (0.),
24   shrunkInf_       (0.),
25   shrunkDoubleInf_ (0.),
26   nProvedInfeas_   (0.),
27   weightSum_       (0.),
28   oldLB_           (NULL),
29   oldUB_           (NULL),
30   totalTime_       (0.),
31   nRuns_           (0),
32   problem_         (p),
33   stats_           ((p != NULL) &&
34 		    (GetRawPtr (p -> Jnlst ()) != NULL) &&
35 		    (p -> Jnlst () -> ProduceOutput (Ipopt::J_ERROR, J_COUENNE))) {}
36 
37 
38 ///
~CouenneBTPerfIndicator()39 CouenneBTPerfIndicator::~CouenneBTPerfIndicator () {
40 
41   if (totalTime_ > 0. &&
42       nRuns_ &&
43       problem_)
44 
45     if (stats_)
46       problem_->Jnlst()->Printf(Ipopt::J_ERROR, J_COUENNE, "Performance of %30s:\t %10gs, %8d runs. fix: %10g shrnk: %10g ubd: %10g 2ubd: %10g infeas: %10g\n",
47 	      name_.c_str (),
48 	      totalTime_,
49 	      nRuns_,
50 	      nFixed_, boundRatio_, shrunkInf_, shrunkDoubleInf_, nProvedInfeas_);
51 
52   //weightSum_ * nFixed_, weightSum_ * boundRatio_, weightSum_ * shrunkInf_, weightSum_ * shrunkDoubleInf_, weightSum_ * nProvedInfeas_);
53 
54   if (oldLB_) delete [] oldLB_;
55   if (oldUB_) delete [] oldUB_;
56 }
57 
58 
59 ///
CouenneBTPerfIndicator(const CouenneBTPerfIndicator & rhs)60 CouenneBTPerfIndicator::CouenneBTPerfIndicator (const CouenneBTPerfIndicator &rhs):
61 
62   name_            (rhs.name_),
63   nFixed_          (rhs.nFixed_),
64   boundRatio_      (rhs.boundRatio_),
65   shrunkInf_       (rhs.shrunkInf_),
66   shrunkDoubleInf_ (rhs.shrunkDoubleInf_),
67   nProvedInfeas_   (rhs.nProvedInfeas_),
68   weightSum_       (rhs.weightSum_),
69   oldLB_           (!rhs.problem_ || rhs.oldLB_ ? NULL : CoinCopyOfArray (rhs.oldLB_, rhs.problem_ -> nVars ())),
70   oldUB_           (!rhs.problem_ || rhs.oldUB_ ? NULL : CoinCopyOfArray (rhs.oldUB_, rhs.problem_ -> nVars ())),
71   totalTime_       (rhs.totalTime_),
72   nRuns_           (rhs.nRuns_),
73   problem_         (rhs.problem_),
74   stats_           (rhs.stats_) {}
75 
76 
77 ///
operator =(const CouenneBTPerfIndicator & rhs)78 CouenneBTPerfIndicator &CouenneBTPerfIndicator::operator= (const CouenneBTPerfIndicator &rhs) {
79 
80   name_            = rhs.name_;
81   nFixed_          = rhs.nFixed_;
82   boundRatio_      = rhs.boundRatio_;
83   shrunkInf_       = rhs.shrunkInf_;
84   shrunkDoubleInf_ = rhs.shrunkDoubleInf_;
85   nProvedInfeas_   = rhs.nProvedInfeas_;
86   weightSum_       = rhs.weightSum_;
87   oldLB_           = !rhs.problem_ || !rhs.oldLB_ ? NULL : CoinCopyOfArray (rhs.oldLB_, rhs.problem_ -> nVars ());
88   oldUB_           = !rhs.problem_ || !rhs.oldUB_ ? NULL : CoinCopyOfArray (rhs.oldUB_, rhs.problem_ -> nVars ());
89   totalTime_       = rhs.totalTime_;
90   nRuns_           = rhs.nRuns_;
91   problem_         = rhs.problem_;
92   stats_           = rhs.stats_;
93 
94   return *this;
95 }
96 
97 
98 ///
setOldBounds(const CouNumber * lb,const CouNumber * ub) const99 void CouenneBTPerfIndicator::setOldBounds (const CouNumber *lb, const CouNumber *ub) const {
100 
101   if (problem_) {
102 
103     oldLB_ = CoinCopyOfArray (lb, problem_ -> nVars ());
104     oldUB_ = CoinCopyOfArray (ub, problem_ -> nVars ());
105 
106   } else {
107 
108     printf ("CouenneBTPerfIndicator::setOldBounds(): no problem information, exiting\n");
109     exit (-1);
110   }
111 }
112 
113 
114 /// add to timer
addToTimer(double time) const115 void CouenneBTPerfIndicator::addToTimer (double time) const
116 {totalTime_ += time;}
117