RepastHPC  2.3.1
UndirectedVertex.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * UndirectedVertex.h
36  *
37  * Created on: Oct 13, 2010
38  * Author: nick
39  */
40 
41 #ifndef UNDIRECTEDVERTEX_H_
42 #define UNDIRECTEDVERTEX_H_
43 
44 #include "Vertex.h"
45 
46 namespace repast {
47 
54 template<typename V, typename E>
55 class UndirectedVertex : public Vertex<V, E> {
56 
57 private:
58  typedef typename Vertex<V,E>::AdjListMap AdjListMap;
59  typedef typename Vertex<V,E>::AdjListMap::iterator AdjListMapIterator;
60  typedef typename Vertex<V,E>::EdgeType EdgeType;
61 
62  AdjListMap* adjMap;
63 
64 public:
65  UndirectedVertex(boost::shared_ptr<V> item);
66  virtual ~UndirectedVertex();
67 
68  // doc inherited from Vertex.h
69  virtual boost::shared_ptr<E> removeEdge(Vertex<V,E>* other, EdgeType type);
70 
71  // doc inherited from Vertex.h
72  virtual boost::shared_ptr<E> findEdge(Vertex<V,E>* other, EdgeType type);
73 
74  // doc inherited from Vertex.h
75  virtual void addEdge(Vertex<V,E>* other, boost::shared_ptr<E> edge, EdgeType type);
76 
77  // doc inherited from Vertex.h
78  virtual void successors(std::vector<V*>& out);
79 
80  // doc inherited from Vertex.h
81  virtual void predecessors(std::vector<V*>& out);
82 
83  // doc inherited from Vertex.h
84  virtual void adjacent(std::vector<V*>& out);
85 
86  // doc inherited from Vertex.h
87  virtual void edges(EdgeType type , std::vector<boost::shared_ptr<E> >& out);
88 
89  // doc inherited from Vertex.h
90  int inDegree();
91 
92  // doc inherited from Vertex.h
93  int outDegree();
94 };
95 
96 template<typename V, typename E>
97 UndirectedVertex<V,E>::UndirectedVertex(boost::shared_ptr<V> item) : Vertex<V,E>(item) {
98  adjMap = new AdjListMap();
99 }
100 
101 template<typename V, typename E>
102 UndirectedVertex<V,E>::~UndirectedVertex() {
103  delete adjMap;
104 }
105 
106 template<typename V, typename E>
107 boost::shared_ptr<E> UndirectedVertex<V,E>::removeEdge(Vertex<V,E>* other, EdgeType type) {
108  return Vertex<V,E>::removeEdge(other, adjMap);
109 }
110 
111 template<typename V, typename E>
112 boost::shared_ptr<E> UndirectedVertex<V,E>::findEdge(Vertex<V,E>* other, EdgeType type) {
113  boost::shared_ptr<E> ret;
114  AdjListMapIterator iter = adjMap->find(other);
115  return (iter != adjMap->end() ? iter->second : ret);
116 }
117 
118 template<typename V, typename E>
119 void UndirectedVertex<V,E>::addEdge(Vertex<V,E>* other, boost::shared_ptr<E> edge, EdgeType type) {
120  (*adjMap)[other] = edge;
121 }
122 
123 template<typename V, typename E>
124 void UndirectedVertex<V,E>::successors(std::vector<V*>& out) {
125  this->getItems(adjMap, out);
126 }
127 
128 template<typename V, typename E>
129 void UndirectedVertex<V,E>::predecessors(std::vector<V*>& out) {
130  this->getItems(adjMap, out);
131 }
132 
133 template<typename V, typename E>
134 void UndirectedVertex<V,E>::adjacent(std::vector<V*>& out) {
135  this->getItems(adjMap, out);
136 }
137 
138 template<typename V, typename E>
140  return adjMap->size();
141 }
142 
143 template<typename V, typename E>
145  return adjMap->size();
146 }
147 
148 template<typename V, typename E>
149 void UndirectedVertex<V,E>::edges(EdgeType type , std::vector<boost::shared_ptr<E> >& out) {
150  Vertex<V, E>::edges(adjMap, out);
151 }
152 
153 
154 
155 }
156 
157 
158 #endif /* UNDIRECTEDVERTEX_H_ */
repast::Vertex::removeEdge
virtual boost::shared_ptr< E > removeEdge(Vertex *other, EdgeType type)=0
Removes the edge of the specified type between this Vertex and the specified Vertex.
repast::Vertex::edges
virtual void edges(EdgeType type, std::vector< boost::shared_ptr< E > > &out)=0
Gets all the edges of the specified type in which this Vertex participates and return them in out.
repast::UndirectedVertex::findEdge
virtual boost::shared_ptr< E > findEdge(Vertex< V, E > *other, EdgeType type)
Finds the edge of the specified type between this Vertex and the specified vertex.
Definition: UndirectedVertex.h:112
repast::UndirectedVertex::addEdge
virtual void addEdge(Vertex< V, E > *other, boost::shared_ptr< E > edge, EdgeType type)
Adds an edge of the specified type between this Vertex and the specified vertex.
Definition: UndirectedVertex.h:119
repast::UndirectedVertex::adjacent
virtual void adjacent(std::vector< V * > &out)
Gets the Vertices adjacent to this Vertex.
Definition: UndirectedVertex.h:134
repast::UndirectedVertex::predecessors
virtual void predecessors(std::vector< V * > &out)
Gets the predecessors of this Vertex.
Definition: UndirectedVertex.h:129
repast::UndirectedVertex::successors
virtual void successors(std::vector< V * > &out)
Gets the successors of this Vertex.
Definition: UndirectedVertex.h:124
repast::Vertex
Used internally by repast graphs / networks to encapsulate Vertices.
Definition: Vertex.h:52
repast::UndirectedVertex
A vertex in an undirected network.
Definition: UndirectedVertex.h:55
repast::Vertex::AdjListMap
boost::unordered_map< Vertex< V, E > *, boost::shared_ptr< E >, HashVertex< V, E > > AdjListMap
Typedef for the adjacency list map that contains the other Vertices that this Vertex links to.
Definition: Vertex.h:92
repast::UndirectedVertex::edges
virtual void edges(EdgeType type, std::vector< boost::shared_ptr< E > > &out)
Gets all the edges of the specified type in which this Vertex participates and return them in out.
Definition: UndirectedVertex.h:149
repast::UndirectedVertex::inDegree
int inDegree()
Gets the in degree of this Vertex.
Definition: UndirectedVertex.h:139
repast::UndirectedVertex::outDegree
int outDegree()
Gets the out degree of this Vertex.
Definition: UndirectedVertex.h:144
repast::Vertex::item
boost::shared_ptr< V > item() const
Gets the item that this Vertex contains.
Definition: Vertex.h:192
repast::Vertex::EdgeType
EdgeType
Enum the identifies whether an edge is incoming or outgoing.
Definition: Vertex.h:98
repast::UndirectedVertex::removeEdge
virtual boost::shared_ptr< E > removeEdge(Vertex< V, E > *other, EdgeType type)
Removes the edge of the specified type between this Vertex and the specified Vertex.
Definition: UndirectedVertex.h:107