Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Util.h File Reference

Set of utitily functions, independent of any GA class. More...

#include <sstream>
#include <string>
#include <list>
#include <math.h>
#include <cstdlib>

Include dependency graph for Util.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define RANDOM_MAX   2147483648.0

Functions

int random_int (int nmax)
 Produces a random natural number between 0 and nmax-1.
std::string itos (int i)
 Converts an int to a string.
std::string ftos (double d)
 Converts a double to a string.
int bitstodec (std::list< char >::iterator start, std::list< char >::iterator end)
 Returns the standard decimal value of a part of a bitstring.
int bitstodec (std::list< char > bits)
 Returns the standard decimal value of an entire bitstring.
void bitstodecparts (std::list< char > bits, int partsize, int *decparts)
 Computes the standard decimal value of all equally sized subparts of an entire bitstring.
std::string bitstos (std::list< char > bits)
 Returns a string representation of a bitstring.
std::string rbitstos (std::list< char > bits)
 Returns a string representation of a reversed bitstring.
template<typename __Tp>
std::_List_iterator< __Tp > & operator+= (std::_List_iterator< __Tp > &it, int __n)
 Dirty, but useful: increment list iterator by specified nr of positions.
template<class T>
T ** newMatrix (int nr, int nc)
 Allocates memory for a new matrix with specified number of rows and cols.
template<class T>
void deleteMatrix (T **mtx, int nr, int nc)
 Deletes the memory that was previously allocated for a matrix with specified number of rows and cols.


Detailed Description

Set of utitily functions, independent of any GA class.

Author:
Arthur van Dam, dam@math.uu.nl

Function Documentation

int bitstodec std::list< char >  bits  ) 
 

Returns the standard decimal value of an entire bitstring.

Watch out for integer overflows!

See also:
bitstodec(iterator, iterator)

int bitstodec std::list< char >::iterator  start,
std::list< char >::iterator  end
 

Returns the standard decimal value of a part of a bitstring.

Bitstrings often represent one or more numbers. As a help for Chromosome subclasses, this function performs the binary to decimal conversion for (a subpart of) a bitstring. start should point to the least significant bit, end should point 1 element beyond the most significant bit.

void bitstodecparts std::list< char >  bits,
int  partsize,
int *  decparts
 

Computes the standard decimal value of all equally sized subparts of an entire bitstring.

The results are put into an array that is allocated elsewhere at the call site. Watch out for integer overflows when using excessively long bitstrings! Assumes that subparts fit exactly within bitstring (otherwise out-of- bounds problems will occur)

See also:
bitstodec(iterator, iterator)

std::string bitstos std::list< char >  bits  ) 
 

Returns a string representation of a bitstring.

e.g. "10101110"

template<class T>
void deleteMatrix T **  mtx,
int  nr,
int  nc
 

Deletes the memory that was previously allocated for a matrix with specified number of rows and cols.

No explicit template instantiation is necessary, e.g.: double **mtx = newMatrix<double>(7, 4); deleteMatrix(mtx, 7, 4);

template<class T>
T** newMatrix int  nr,
int  nc
 

Allocates memory for a new matrix with specified number of rows and cols.

Use explicit template instantiation to call this function, e.g.: double** mtx; mtx = newMatrix<double>(7, 4);

template<typename __Tp>
std::_List_iterator<__Tp>& operator+= std::_List_iterator< __Tp > &  it,
int  __n
 

Dirty, but useful: increment list iterator by specified nr of positions.

Runs in linear time.

std::string rbitstos std::list< char >  bits  ) 
 

Returns a string representation of a reversed bitstring.

e.g. "01110101" This is used when the bitstring represents some decimal number. The least significant bit is then commonly placed at the rightmost position.


Generated on Tue Oct 20 12:59:23 2009 for LabSci GALib optimisation by genetic algorithms, student version by  doxygen 1.3.9.1