-
-
Save amirmasoudabdol/c4a1a711d330634c8488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _eoRealEnhancedVectorBounds_h | |
#define _eoRealEnhancedVectorBounds_h | |
#include <stdexcept> // std::exceptions! | |
#include <utils/eoRNG.h> | |
#include <utils/eoRealBounds.h> | |
//////////////////////////////////////////////////////////////////// | |
/** Now a derived class, for parser reading | |
* It holds some of the bounds (and destroy them when dying) | |
@ingroup Bounds | |
*/ | |
class eoRealEnhancedVectorBounds : public eoRealBaseVectorBounds, public eoPersistent | |
{ | |
public: | |
/** Dtor: destroy all ownedBounds - BUG ???*/ | |
virtual ~eoRealEnhancedVectorBounds() | |
{ | |
// std::cout << "Dtor, avec size = " << ownedBounds.size() << std::endl; | |
// for (unsigned i = 0; i < ownedBounds.size(); ++i) | |
// { | |
// delete ownedBounds[i]; | |
// } | |
} | |
/** Default Ctor will call base class default ctor | |
*/ | |
eoRealEnhancedVectorBounds():eoRealBaseVectorBounds() {} | |
/** Ctor: same bounds for everybody, given as an eoRealBounds | |
*/ | |
eoRealEnhancedVectorBounds(unsigned _dim, eoRealBounds & _bounds) : | |
eoRealBaseVectorBounds(_dim, _bounds), factor(1,_dim), ownedBounds(0) | |
{} | |
/** Ctor, particular case of dim-2 | |
*/ | |
eoRealEnhancedVectorBounds(eoRealBounds & _xbounds, eoRealBounds & _ybounds) : | |
eoRealBaseVectorBounds(_xbounds, _ybounds), factor(2,1), ownedBounds(0) | |
{} | |
// Simple bounds = minimum and maximum (allowed) | |
eoRealEnhancedVectorBounds(unsigned _dim, double _min, double _max) : | |
eoRealBaseVectorBounds(), factor(1, _dim), ownedBounds(0) | |
{ | |
if (_max-_min<=0) | |
throw std::logic_error("Void range in eoRealEnhancedVectorBounds"); | |
eoRealBounds *ptBounds = new eoRealInterval(_min, _max); | |
// handle memory once | |
ownedBounds.push_back(ptBounds); | |
// same bound for everyone | |
for (unsigned int i=0; i<_dim; i++) | |
push_back(ptBounds); | |
} | |
/** Ctor: different bounds for different variables, std::vectors of double | |
*/ | |
eoRealEnhancedVectorBounds(std::vector<double> _min, std::vector<double> _max) : | |
factor(_min.size(), 1), ownedBounds(0) | |
{ | |
if (_max.size() != _min.size()) | |
throw std::logic_error("Dimensions don't match in eoRealEnhancedVectorBounds"); | |
// the bounds | |
eoRealBounds *ptBounds; | |
for (unsigned i=0; i<_min.size(); i++) | |
{ | |
ptBounds = new eoRealInterval(_min[i], _max[i]); | |
ownedBounds.push_back(ptBounds); | |
push_back(ptBounds); | |
} | |
} | |
// FIX ME: I'm not working! | |
eoRealEnhancedVectorBounds(std::vector<double> _min, | |
std::vector<double> _max, | |
std::vector<bool> _is_bounded, | |
std::vector<short int> _network_topology): | |
factor(_min.size(), 1), ownedBounds(0) | |
{ | |
if (_max.size() != _min.size()) | |
throw std::logic_error("Dimensions don't match in eoRealEnhancedVectorBounds"); | |
// the bounds | |
for(unsigned i = 0; i < _min.size(); ++i) { | |
if (_is_bounded[i]){ | |
eoRealBounds *ptBounds; | |
ptBounds = new eoRealInterval(_min[i], _max[i]); | |
ownedBounds.push_back(ptBounds); | |
push_back(ptBounds); | |
}else{ | |
eoRealNoBounds *ptBounds; | |
ownedBounds.push_back(ptBounds); | |
push_back(ptBounds); | |
} | |
} | |
} | |
/** Ctor from a std::string | |
* and don't worry, the readFrom(std::string) starts by setting everything to 0! | |
*/ | |
eoRealEnhancedVectorBounds(std::string _s) : eoRealBaseVectorBounds() | |
{ | |
readFrom(_s); | |
} | |
// methods from eoPersistent | |
/** | |
* Read object from a stream | |
* only calls the readFrom(std::string) - for param reading | |
* @param _is A std::istream. | |
*/ | |
virtual void readFrom(std::istream& _is) ; | |
/** | |
* Read object from a std::string | |
* @param _s A std::istream. | |
*/ | |
virtual void readFrom(std::string _s) ; | |
/** overload printOn method to save space */ | |
virtual void printOn(std::ostream& _os) const | |
{ | |
if (factor[0]>1) | |
_os << factor[0] ; | |
operator[](0)->printOn(_os); | |
// other bounds | |
unsigned int index=factor[0]; | |
if (factor.size()>1) | |
for (unsigned i=1; i<factor.size(); i++) | |
{ | |
_os << ";"; | |
if (factor[i] > 1) | |
_os << factor[i]; | |
operator[](index)->printOn(_os); | |
index += factor[i]; | |
} | |
} | |
/** Eventually increases the size by duplicating last bound */ | |
void adjust_size(unsigned _dim); | |
/** need to rewrite copy ctor and assignement operator | |
* because of ownedBounds */ | |
eoRealEnhancedVectorBounds(const eoRealEnhancedVectorBounds &); | |
private:// WARNING: there is no reason for both std::vector below | |
//to be synchronized in any manner | |
std::vector<unsigned int> factor; // std::list of nb of "grouped" bounds | |
std::vector<eoRealBounds *> ownedBounds; | |
// keep this one private | |
eoRealEnhancedVectorBounds& operator=(const eoRealEnhancedVectorBounds&); | |
}; | |
#endif /* _eoRealEnhancedVectorBounds_h */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment