PaGMO  1.1.5
algorithm/base.cpp
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #include <iostream>
26 #include <sstream>
27 #include <string>
28 #include <typeinfo>
29 
30 #include "../population.h"
31 #include "../rng.h"
32 #include "base.h"
33 
34 namespace pagmo
35 {
36 namespace algorithm {
37 
39 
42 base::base():m_screen_output(false), m_drng(rng_generator::get<rng_double>()), m_urng(rng_generator::get<rng_uint32>()), m_fevals(0) {}
43 
45 
49 
51 
56 std::string base::get_name() const
57 {
58  return typeid(*this).name();
59 }
60 
62 
67 void base::set_screen_output(const bool p) {m_screen_output = p;}
68 
70 
77 
79 
84 void base::reset_rngs(const unsigned int p) const {
85  m_urng = rng_uint32(p);
86  m_drng = rng_double(p);
87 }
88 
90 
96 std::string base::human_readable() const
97 {
98  std::ostringstream s;
99  s << "Algorithm name: " << get_name();
100  const std::string tmp(human_readable_extra());
101  if (tmp.size()) {
102  s << " - " << tmp;
103  }
104  return s.str();
105 }
106 
108 
113 std::string base::human_readable_extra() const
114 {
115  return std::string();
116 }
117 
119 
127 std::ostream &operator<<(std::ostream &s, const base &alg)
128 {
129  s << alg.human_readable();
130  return s;
131 }
132 
133 }
134 }
Root PaGMO namespace.
bool get_screen_output() const
Gets screen output.
Generic thread-safe generator of pseudo-random number generators.
Definition: rng.h:138
void set_screen_output(const bool p)
Setter-Getter for protected m_screen_output data.
This rng returns an unsigned integer in the [0,2**32-1] range.
Definition: rng.h:47
Base algorithm class.
base()
Default constructor.
virtual ~base()
Trivial destructor.
bool m_screen_output
Indicates to the derived class whether to print stuff on screen.
virtual std::string get_name() const
Get algorithm's name.
void reset_rngs(const unsigned int) const
Resets the seed of the internal rngs using a user-provided seed.
std::string human_readable() const
Return human readable representation of the algorithm.
virtual std::string human_readable_extra() const
Extra information in human readable format.
rng_uint32 m_urng
Random number generator for unsigned integer values.
std::ostream & operator<<(std::ostream &s, const base &alg)
Overload stream operator for algorithm::base.
rng_double m_drng
Random number generator for double-precision floating point values.
This rng returns a double in the [0,1[ range.
Definition: rng.h:89