PaGMO  1.1.5
types.h
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 // 30/01/10 Created by Francesco Biscani.
26 
27 #ifndef PAGMO_TYPES_H
28 #define PAGMO_TYPES_H
29 
30 #include <boost/lexical_cast.hpp>
31 #include <boost/numeric/conversion/converter.hpp>
32 #include <iostream>
33 #include <vector>
34 
35 #include "config.h"
36 
37 namespace pagmo
38 {
40  typedef std::vector<double> decision_vector;
42  typedef std::vector<double> fitness_vector;
44  typedef std::vector<double> constraint_vector;
45 
47 
53  typedef boost::numeric::converter<int,double,boost::numeric::conversion_traits<int,double>,
54  boost::numeric::def_overflow_handler,boost::numeric::RoundEven<double> > double_to_int;
55 }
56 
57 // Give the possibility to disable stream overloads with appropriate #define.
58 #ifndef PAGMO_NO_STD_VECTOR_STREAM_OVERLOADS
59 
60 #define PAGMO_MAX_OUTPUT_LENGTH 5
61 namespace std
62 {
65  template < class T >
66  inline ostream &operator<<(ostream &os, const vector<T> &v)
67  {
68  typename vector<T>::size_type len = v.size();
69  if (len < PAGMO_MAX_OUTPUT_LENGTH)
70  {
71  os << '[';
72  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
73  os << boost::lexical_cast<std::string>(v[i]);
74  if (i != v.size() - 1) {
75  os << ", ";
76  }
77  }
78  os << ']';
79  } else {
80  os << '[';
81  for (typename std::vector<T>::size_type i = 0; i < PAGMO_MAX_OUTPUT_LENGTH; ++i) {
82  os << boost::lexical_cast<std::string>(v[i]) << ", ";
83  }
84  os << " ... ]";
85  }
86  return os;
87  }
88 
89 
90 }
91 #undef PAGMO_MAX_OUTPUT_LENGTH
92 #endif
93 #endif
94 
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
STL namespace.
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
boost::numeric::converter< int, double, boost::numeric::conversion_traits< int, double >, boost::numeric::def_overflow_handler, boost::numeric::RoundEven< double > > double_to_int
Double to int converter.
Definition: types.h:54