implement size setter for Bit vector
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2223 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
bf8f7306e4
commit
6159b9503d
1 changed files with 26 additions and 1 deletions
|
|
@ -47,6 +47,7 @@ template<class Fitness>
|
||||||
class moGPUBitVector: public moGPUVector<bool, Fitness> {
|
class moGPUBitVector: public moGPUVector<bool, Fitness> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define bool vector corresponding to Solution
|
* Define bool vector corresponding to Solution
|
||||||
**/
|
**/
|
||||||
|
|
@ -94,11 +95,35 @@ public:
|
||||||
|
|
||||||
for (unsigned i = 0; i < N; i++) {
|
for (unsigned i = 0; i < N; i++) {
|
||||||
|
|
||||||
vect[i] = (bool) round((float) rng.rand() / RAND_MAX);
|
vect[i] = (int) (rng.rand() / RAND_MAX);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Function inline to set the size of vector, called from host.
|
||||||
|
*@param _size the vector size
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual inline __host__ void setSize(unsigned _size) {
|
||||||
|
|
||||||
|
if(_size<N) {
|
||||||
|
moGPUBitVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i < tmp_vect.N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this)=tmp_vect;
|
||||||
|
}
|
||||||
|
else if(_size>N) {
|
||||||
|
moGPUBitVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i <N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this)=tmp_vect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
* @param _os A std::ostream.
|
* @param _os A std::ostream.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue