PaGMO  1.1.5
rim.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 <string>
26 
27 #include "../exceptions.h"
28 #include "base.h"
29 #include "rim.h"
30 
31 namespace pagmo { namespace topology {
32 
34 rim::rim():base() {}
35 
37 {
38  return base_ptr(new rim(*this));
39 }
40 
42 {
43  // Store frequently-used variables.
45  pagmo_assert(t_size != 0);
46  switch (t_size) {
47  case 1: {
48  // If the topology was empty, do not do anything.
49  break;
50  }
51  case 2: {
52  add_edge(0,1);
53  add_edge(1,0);
54  break;
55  }
56  case 3: {
57  // Add edge to the center.
58  add_edge(0,2);
59  add_edge(2,0);
60  // Add 1-2 connection.
61  add_edge(1,2);
62  add_edge(2,1);
63  break;
64  }
65  case 4: {
66  // Add edge to the center.
67  add_edge(0,3);
68  add_edge(3,0);
69  // Add 1-3 and 3-2 connections.
70  add_edge(1,3);
71  add_edge(3,1);
72  add_edge(2,3);
73  add_edge(3,2);
74  break;
75  }
76  default: {
77  // Add edge to the center.
78  add_edge(0,t_size - 1);
79  add_edge(t_size - 1,0);
80  // Remove connection (previous last)-first.
81  remove_edge(t_size - 2,1);
82  remove_edge(1,t_size - 2);
83  // Add connection (previous last)-(new last).
84  add_edge(t_size - 2,t_size - 1);
85  add_edge(t_size - 1,t_size - 2);
86  // Add connection (new last)-(first).
87  add_edge(t_size - 1,1);
88  add_edge(1,t_size - 1);
89  }
90  }
91 }
92 
93 std::string rim::get_name() const
94 {
95  return "Rim";
96 }
97 
98 }} //namespaces
99 
100 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::topology::rim)
Root PaGMO namespace.
void connect(const vertices_size_type &)
Establish connections between islands during a push_back() operation.
Definition: rim.cpp:41
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base topology.
Definition: topology/base.h:47
Base topology class.
Definition: topology/base.h:75
void remove_edge(const vertices_size_type &, const vertices_size_type &)
Remove an edge.
vertices_size_type get_number_of_vertices() const
Get number of vertices.
graph_type::vertices_size_type vertices_size_type
Vertices size type.
std::string get_name() const
Get name of the topology.
Definition: rim.cpp:93
void add_edge(const vertices_size_type &, const vertices_size_type &)
Add an edge.
Wheel rim topology.
Definition: rim.h:46
base_ptr clone() const
Clone method.
Definition: rim.cpp:36
rim()
Default constructor.
Definition: rim.cpp:34