Version: 9.15.0
YACS::ENGINE::ComplexWeight Class Reference

#include <ComplexWeight.hxx>

Collaboration diagram for YACS::ENGINE::ComplexWeight:

Public Member Functions

 ComplexWeight ()
 
 ComplexWeight (double elementaryWeight, double loopWeight, int nbCoresByIteration)
 
 ComplexWeight (const ComplexWeight &other)
 
 ~ComplexWeight ()
 
std::vector< std::pair< double, int > > getLoopWeight () const
 
double getSimpleLoopWeight () const
 
double getElementaryWeight () const
 
double calculateTotalLength (int nbOfCoresAllocated) const
 
void setDefaultElementary ()
 
void setDefaultLoop ()
 
bool isDefaultValue () const
 
bool isUnsetLoopWeight () const
 
bool isUnsetElementaryWeight () const
 
bool hasValidLoopWeight () const
 
bool hasValidElementaryWeight () const
 
void setLoopWeight (double loopWeight, int nbCoresByIteration)
 
void setElementaryWeight (double elementaryWeight)
 
void setToZero ()
 
int getNbCoresConsoLoopMax () const
 
void max (ComplexWeight &other)
 
void addWeight (const ComplexWeight *other)
 

Protected Attributes

bool _bootWeight
 
std::vector< std::pair< double, int > > _loopWeight
 
double _elementaryWeight
 

Private Member Functions

void unsetLoop ()
 
void unsetElementary ()
 
bool isDefaultValueLoop () const
 
bool isDefaultValueElementary () const
 

Detailed Description

Definition at line 38 of file ComplexWeight.hxx.

Constructor & Destructor Documentation

◆ ComplexWeight() [1/3]

ComplexWeight::ComplexWeight ( )

Definition at line 31 of file ComplexWeight.cxx.

32 {
33  setToZero();
34 }

References setToZero().

◆ ComplexWeight() [2/3]

ComplexWeight::ComplexWeight ( double  elementaryWeight,
double  loopWeight,
int  nbCoresByIteration 
)

Definition at line 36 of file ComplexWeight.cxx.

36  : _elementaryWeight(elementaryWeight), _bootWeight(false)
37 {
38  _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
39 }
std::vector< std::pair< double, int > > _loopWeight

References _loopWeight.

◆ ComplexWeight() [3/3]

YACS::ENGINE::ComplexWeight::ComplexWeight ( const ComplexWeight other)
inline

Definition at line 43 of file ComplexWeight.hxx.

43 {_bootWeight=other._bootWeight; _loopWeight=other._loopWeight; _elementaryWeight=other._elementaryWeight;}

References _bootWeight, _elementaryWeight, and _loopWeight.

◆ ~ComplexWeight()

YACS::ENGINE::ComplexWeight::~ComplexWeight ( )
inline

Definition at line 44 of file ComplexWeight.hxx.

44 {};

Member Function Documentation

◆ addWeight()

void ComplexWeight::addWeight ( const ComplexWeight other)

Definition at line 112 of file ComplexWeight.cxx.

113 {
114  bool found;
115  if ((!_bootWeight) && ((other->isUnsetLoopWeight() && this->isDefaultValueLoop()) || (this->isUnsetLoopWeight() && other->isDefaultValueLoop())))
116  this->unsetLoop();
117  else
118  {
119  for(std::vector< std::pair<double,int> >::const_iterator it=other->_loopWeight.begin();it!=other->_loopWeight.end();it++)
120  {
121  found=false;
122  for(std::vector< std::pair<double,int> >::iterator it2=_loopWeight.begin();it2!=_loopWeight.end();it2++)
123  {
124  if ((*it).second == (*it2).second)
125  {
126  if (((*it2).first>=0) && ((*it).first>=0))
127  this->setLoopWeight((*it2).first+(*it).first, (*it2).second);
128  else if ((*it).first>=0)
129  this->setLoopWeight((*it).first, (*it2).second);
130  found=true;
131  continue;
132  }
133  }
134  if ((!found) && ((*it).second!=-1))
135  this->setLoopWeight((*it).first, (*it).second);
136  }
137  if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
138  _loopWeight.erase(_loopWeight.begin());
139  }
140 
141  if ((!_bootWeight) && ((other->isUnsetElementaryWeight() && this->isDefaultValueElementary()) || (this->isUnsetElementaryWeight() && other->isDefaultValueElementary())))
142  this->unsetElementary();
143  else
144  {
145  if (other->hasValidElementaryWeight())
146  {
149  else
151  }
152  }
153  if (!other->_bootWeight)
154  _bootWeight=false;
155 }
bool isDefaultValueElementary() const
void setLoopWeight(double loopWeight, int nbCoresByIteration)
bool isUnsetElementaryWeight() const
bool hasValidElementaryWeight() const

References _bootWeight, _elementaryWeight, _loopWeight, hasValidElementaryWeight(), isDefaultValueElementary(), isDefaultValueLoop(), isUnsetElementaryWeight(), isUnsetLoopWeight(), setLoopWeight(), unsetElementary(), and unsetLoop().

Referenced by YACS::ENGINE::DynParaLoop::getWeightRegardingDPL(), YACS::ENGINE::ElementaryNode::getWeightRegardingDPL(), YACS::ENGINE::ForkBlocPoint::getWeightRegardingDPL(), YACS::ENGINE::LinkedBlocPoint::getWeightRegardingDPL(), and YACS::ENGINE::NotSimpleCasePoint::getWeightRegardingDPL().

◆ calculateTotalLength()

double ComplexWeight::calculateTotalLength ( int  nbOfCoresAllocated) const

Definition at line 48 of file ComplexWeight.cxx.

49 {
50  if (isDefaultValue())
51  throw Exception("ComplexWeight::calculateTotalLength : can not calculate total weight with default value!");
52  double totalWeight(0);
54  totalWeight+=_elementaryWeight;
55  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
56  {
57  if ((*it).second>0)
58  totalWeight+=(*it).first*((double)(*it).second)/((double)nbOfCoresAllocated);
59  }
60  return totalWeight;
61 }

References _elementaryWeight, _loopWeight, hasValidElementaryWeight(), and isDefaultValue().

◆ getElementaryWeight()

double YACS::ENGINE::ComplexWeight::getElementaryWeight ( ) const
inline

◆ getLoopWeight()

std::vector<std::pair<double,int> > YACS::ENGINE::ComplexWeight::getLoopWeight ( ) const
inline

Definition at line 45 of file ComplexWeight.hxx.

45 {return _loopWeight;}

◆ getNbCoresConsoLoopMax()

int ComplexWeight::getNbCoresConsoLoopMax ( ) const

Definition at line 84 of file ComplexWeight.cxx.

85 {
86  int nbCoresPerShotLoopMax(0);
87  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
88  if ((*it).second>nbCoresPerShotLoopMax)nbCoresPerShotLoopMax=(*it).second;
89  return nbCoresPerShotLoopMax;
90 }

References _loopWeight.

◆ getSimpleLoopWeight()

double ComplexWeight::getSimpleLoopWeight ( ) const

Definition at line 41 of file ComplexWeight.cxx.

42 {
43  if(_loopWeight.size()!=1)
44  throw Exception("ComplexWeight::getSimpleLoopWeight : can not get loop weight. Node contain multiple loop weights!");
45  return (*(_loopWeight.begin())).first;
46 }

References _loopWeight.

Referenced by YACS::ENGINE::VisitorSaveSchema::visitForEachLoop(), YACS::ENGINE::VisitorSaveSchema::visitForEachLoopDyn(), and YACS::ENGINE::VisitorSaveSchema::visitOptimizerLoop().

◆ hasValidElementaryWeight()

bool YACS::ENGINE::ComplexWeight::hasValidElementaryWeight ( ) const
inline

Definition at line 55 of file ComplexWeight.hxx.

55 { return (_elementaryWeight>=0);}

Referenced by addWeight(), and calculateTotalLength().

◆ hasValidLoopWeight()

bool YACS::ENGINE::ComplexWeight::hasValidLoopWeight ( ) const
inline

Definition at line 54 of file ComplexWeight.hxx.

54 { return (((*(_loopWeight.begin())).first>0) && ((*(_loopWeight.begin())).second!=-1));}

◆ isDefaultValue()

bool YACS::ENGINE::ComplexWeight::isDefaultValue ( ) const
inline

Definition at line 51 of file ComplexWeight.hxx.

51 { return ((isDefaultValueElementary()) && (isDefaultValueLoop()));}

Referenced by calculateTotalLength().

◆ isDefaultValueElementary()

bool YACS::ENGINE::ComplexWeight::isDefaultValueElementary ( ) const
inlineprivate

Definition at line 71 of file ComplexWeight.hxx.

71 {return (_elementaryWeight<0);}

Referenced by addWeight().

◆ isDefaultValueLoop()

bool YACS::ENGINE::ComplexWeight::isDefaultValueLoop ( ) const
inlineprivate

Definition at line 70 of file ComplexWeight.hxx.

70 {return ((*(_loopWeight.begin())).second==-1);}

Referenced by addWeight().

◆ isUnsetElementaryWeight()

bool YACS::ENGINE::ComplexWeight::isUnsetElementaryWeight ( ) const
inline

Definition at line 53 of file ComplexWeight.hxx.

53 {return (_elementaryWeight==0);}

Referenced by addWeight().

◆ isUnsetLoopWeight()

bool YACS::ENGINE::ComplexWeight::isUnsetLoopWeight ( ) const
inline

Definition at line 52 of file ComplexWeight.hxx.

52 {return ((*(_loopWeight.begin())).second==0);}

Referenced by addWeight().

◆ max()

void ComplexWeight::max ( ComplexWeight other)

Definition at line 92 of file ComplexWeight.cxx.

93 {
95 
96  double allLoopWeight1(0);
97  double allLoopWeight2(0);
98  for(std::vector< std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++)
99  {
100  if (((*it).first>0) && ((*it).second>0))
101  allLoopWeight1+=(*it).first * (*it).second;
102  }
103  for(std::vector< std::pair<double,int> >::const_iterator it=other._loopWeight.begin();it!=other._loopWeight.end();it++)
104  {
105  if (((*it).first>0) && ((*it).second>0))
106  allLoopWeight2+=(*it).first * (*it).second;
107  }
108  if (allLoopWeight2>allLoopWeight1)
109  _loopWeight=other._loopWeight;
110 }

References _elementaryWeight, and _loopWeight.

Referenced by YACS::ENGINE::Switch::getWeightRegardingDPL().

◆ setDefaultElementary()

void YACS::ENGINE::ComplexWeight::setDefaultElementary ( )
inline

Definition at line 49 of file ComplexWeight.hxx.

49 {setToZero(); setLoopWeight(0.,0);}

Referenced by YACS::ENGINE::ElementaryNode::ElementaryNode().

◆ setDefaultLoop()

void YACS::ENGINE::ComplexWeight::setDefaultLoop ( )
inline

Definition at line 50 of file ComplexWeight.hxx.

void setElementaryWeight(double elementaryWeight)

Referenced by YACS::ENGINE::DynParaLoop::DynParaLoop().

◆ setElementaryWeight()

void YACS::ENGINE::ComplexWeight::setElementaryWeight ( double  elementaryWeight)
inline

Definition at line 57 of file ComplexWeight.hxx.

57 {_bootWeight=false; _elementaryWeight=elementaryWeight;}

Referenced by YACS::ENGINE::ElementaryNode::setWeight().

◆ setLoopWeight()

void ComplexWeight::setLoopWeight ( double  loopWeight,
int  nbCoresByIteration 
)

Definition at line 63 of file ComplexWeight.cxx.

64 {
65  bool found(false);
66  int i(0), rankFound(0);
67  _bootWeight=false;
68  for(std::vector<std::pair<double,int> >::const_iterator it=_loopWeight.begin();it!=_loopWeight.end();it++,i++)
69  {
70  if ((*it).second==nbCoresByIteration)
71  {
72  found=true;
73  rankFound=i;
74  }
75 
76  }
77  if (found)
78  _loopWeight.erase(_loopWeight.begin()+rankFound);
79  _loopWeight.push_back(std::pair<double,int>(loopWeight,nbCoresByIteration));
80  if ((_loopWeight.size()>1) && ((*(_loopWeight.begin())).second==-1))
81  _loopWeight.erase(_loopWeight.begin());
82 }

References _bootWeight, _loopWeight, and yacsorb.CORBAEngineTest::i.

Referenced by addWeight(), and YACS::ENGINE::DynParaLoop::getWeight().

◆ setToZero()

◆ unsetElementary()

void YACS::ENGINE::ComplexWeight::unsetElementary ( )
inlineprivate

Definition at line 69 of file ComplexWeight.hxx.

69 {_elementaryWeight=-1.;}

Referenced by addWeight().

◆ unsetLoop()

void YACS::ENGINE::ComplexWeight::unsetLoop ( )
inlineprivate

Definition at line 68 of file ComplexWeight.hxx.

68 {_loopWeight.clear(); _loopWeight.push_back(std::pair<double,int>(-1.,-1));}

Referenced by addWeight().

Member Data Documentation

◆ _bootWeight

bool YACS::ENGINE::ComplexWeight::_bootWeight
protected

Definition at line 63 of file ComplexWeight.hxx.

Referenced by addWeight(), ComplexWeight(), and setLoopWeight().

◆ _elementaryWeight

double YACS::ENGINE::ComplexWeight::_elementaryWeight
protected

Definition at line 66 of file ComplexWeight.hxx.

Referenced by addWeight(), calculateTotalLength(), ComplexWeight(), and max().

◆ _loopWeight

std::vector<std::pair<double,int> > YACS::ENGINE::ComplexWeight::_loopWeight
protected

The documentation for this class was generated from the following files: