NDEVR
API Documentation
hyper_graph.h
1#pragma once
2#include <NDEVR/Buffer.h>
3#include <NDEVR/Dictionary.h>
4#include <NDEVR/Set.h>
5#include "eigen_types.h"
6#include "DLLInfo.h"
7/* graph optimization */
8namespace NDEVR
9{
20 {
21 public:
22
23 class HGVertex;
24 class HGEdge;
25
28 {
29 public:
31 explicit HGVertex(int id = -1)
32 : _id(id)
33 {
34 }
35 virtual ~HGVertex() {}
37 int id() const { return _id; }
39 void setId(int newId) { _id = newId; }
41 const Buffer<HGEdge*>& edges() const { return _edges; }
44 protected:
46 int _id;
47 };
48
53 class HGEdge
54 {
55 public:
57 explicit HGEdge(int id = -1)
58 : _id(id)
59 {
60 }
61
62 virtual ~HGEdge() {}
64 virtual uint04 vertexCount() const = 0;
67 virtual const HGVertex* vertex(uint04 i) const = 0;
70 virtual HGVertex* vertex(uint04 i) = 0;
74 virtual void setVertex(uint04 i, HGVertex* v) = 0;
75
77 int id() const { return _id; }
79 void setId(int id) { _id = id; }
80 protected:
81 int _id;
82 };
83
84 public:
88 virtual ~HyperGraph()
89 {}
90
93 {
94 auto it = _vertices.find(id);
95 if (it == _vertices.end())
96 return nullptr;
97 return it->second;
98 }
99
100 const HGVertex* vertex(int id) const
101 {
102 auto it = _vertices.find(id);
103 if (it == _vertices.end())
104 return nullptr;
105 return it->second;
106 }
107
109 /*virtual bool removeVertex(HGVertex* v)
110 {
111 auto vert_it = _vertices.find(v->id());
112 if (vert_it == _vertices.end())
113 return false;
114 assert(vert_it->second == v);
115 //remove all edges which are entering or leaving v;
116 Set<HGEdge*> tmp(v->edges());
117 for (auto it = tmp.begin(); it != tmp.end(); ++it)
118 {
119 //TYLER PARKE: OPTIMIZE THIS
120 if (!removeEdge(*it)) {
121 assert(0);
122 }
123 }
124 _vertices.erase(vert_it);
125 return true;
126 }*/
128 /*virtual bool removeEdge(HGEdge* e)
129 {
130 auto it = _edges.find(e);
131 if (it == _edges.end())
132 return false;
133 _edges.erase(it);
134
135 for (uint04 i = 0; i < e->vertexCount(); i++)
136 e->vertex(i)->edges().removeElement(e);
137 return true;
138 }*/
140 virtual void clear()
141 {
142 _vertices.clear();
143 _edges.clear();
144 }
145
150
152 const Buffer<HGEdge*>& edges() const { return _edges; }
155
162 virtual bool addVertex(HGVertex& v)
163 {
164 lib_assert(!_vertices.contains(v.id()), "duplicate vertex entry");
165 _vertices.insert(std::make_pair(v.id(), &v));
166 return true;
167 }
168
173 virtual bool addEdge(HGEdge* e)
174 {
175 lib_assert(!_edges.contains(e), "duplicate vertex entry");
176 _edges.add(e);
177 for (uint04 i = 0; i < e->vertexCount(); i++)
178 {
179 auto v = e->vertex(i);
180 if (v != nullptr)
181 {
182 lib_assert(!v->edges().contains(e), "Already added vertex");
183 v->edges().add(e);
184 }
185 }
186 return true;
187 }
188
189
190 protected:
193
194 private:
195 // Disable the copy constructor and assignment operator
196 HyperGraph(const HyperGraph&) = delete;
197 HyperGraph& operator= (const HyperGraph&) = delete;
198 public:
199 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
200 };
201
202}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Abstract Edge class.
Definition hyper_graph.h:54
virtual const HGVertex * vertex(uint04 i) const =0
Returns a const pointer to the i-th vertex.
int id() const
returns the id of this edge
Definition hyper_graph.h:77
virtual void setVertex(uint04 i, HGVertex *v)=0
Sets the i-th vertex of this edge.
int _id
unique id
Definition hyper_graph.h:81
virtual uint04 vertexCount() const =0
Returns the number of vertices connected by this edge.
void setId(int id)
sets the id of this edge
Definition hyper_graph.h:79
virtual HGVertex * vertex(uint04 i)=0
Returns a mutable pointer to the i-th vertex.
HGEdge(int id=-1)
creates and empty edge with no vertices
Definition hyper_graph.h:57
abstract Vertex, your types must derive from that one
Definition hyper_graph.h:28
Buffer< HGEdge * > & edges()
returns the set of hyper-edges that are leaving/entering in this vertex
Definition hyper_graph.h:43
int _id
Unique identifier for this vertex.
Definition hyper_graph.h:46
int id() const
returns the id
Definition hyper_graph.h:37
Buffer< HGEdge * > _edges
Set of edges connected to this vertex.
Definition hyper_graph.h:45
void setId(int newId)
sets the id of this vertex
Definition hyper_graph.h:39
HGVertex(int id=-1)
creates a vertex having an ID specified by the argument
Definition hyper_graph.h:31
const Buffer< HGEdge * > & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
Definition hyper_graph.h:41
HyperGraph()
constructs an empty hyper graph
Definition hyper_graph.h:86
virtual void clear()
removes a vertex from the graph. Returns true on success (vertex was present)
virtual ~HyperGraph()
destroys the hyper-graph and all the vertices of the graph
Definition hyper_graph.h:88
virtual bool addEdge(HGEdge *e)
Adds an edge to the graph.
const HGVertex * vertex(int id) const
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
Dictionary< int, HGVertex * > & vertices()
const Dictionary< int, HGVertex * > & vertices() const
const Buffer< HGEdge * > & edges() const
Dictionary< int, HGVertex * > _vertices
Map from vertex id to vertex pointer.
Buffer< HGEdge * > & edges()
virtual bool addVertex(HGVertex &v)
adds a vertex to the graph.
Buffer< HGEdge * > _edges
Collection of all edges in the graph.
HGVertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
Definition hyper_graph.h:92
Convenience typedefs for commonly used Eigen vector, matrix, and transform types.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...