indigoX
assignment.hpp
Go to the documentation of this file.
1 
2 #ifndef INDIGOX_GRAPH_ASSIGNMENT_HPP
3 #define INDIGOX_GRAPH_ASSIGNMENT_HPP
4 #include "../utils/common.hpp"
5 #include "../utils/fwd_declares.hpp"
6 #include "base_graph.hpp"
7 
8 #include <EASTL/vector_map.h>
9 #include <cstdint>
10 #include <limits>
11 #include <map>
12 #include <memory>
13 #include <vector>
14 
15 // Local declarations
16 namespace indigox::graph {
17 
19  class IXAGVertex : public std::enable_shared_from_this<IXAGVertex> {
20  public:
21  IXAGVertex() = delete; // no default constructor
23  friend class IXAssignmentGraph;
25 
26  private:
29  IXAGVertex(const MGVertex v)
30  : _source_vert(v), _source_edge(), _pre(0), _count(0) {}
31 
36  IXAGVertex(const MGEdge e)
37  : _source_vert(), _source_edge(e), _pre(2), _count(0) {}
38 
39  public:
42  inline bool IsVertexMapped() const { return !_source_vert.expired(); }
43 
46  inline bool IsEdgeMapped() const { return !_source_edge.expired(); }
47 
52  inline MGVertex GetSourceVertex() const {
53  return IsVertexMapped() ? _source_vert.lock() : MGVertex();
54  }
55 
60  inline MGEdge GetSourceEdge() const {
61  return IsEdgeMapped() ? _source_edge.lock() : MGEdge();
62  }
63 
66  inline uint32_t GetPreAssignedCount() const { return _pre; }
67 
71  inline void SetPreAssignedCount(const uint32_t count) { _pre = count; }
72 
76  inline uint32_t GetAssignedCount() const { return _count; }
77 
82  inline uint32_t GetTotalAssigned() const { return _pre + _count; }
83 
86  inline void SetAssignedCount(const uint32_t count) { _count = count; }
87 
88  private:
90  _MGVertex _source_vert;
92  _MGEdge _source_edge;
97  uint32_t _pre, _count;
98  };
99 
108 
110  using graph_type = IXGraphBase<IXAGVertex, std::nullptr_t>;
112  using VertContain = std::vector<AGVertex>;
113 
114  public:
116  using VertIter = VertContain::const_iterator;
118  using NbrsIter = VertContain::const_iterator;
119 
120  public:
121  IXAssignmentGraph() = delete; // no default constructor
122 
123  public:
127 
131  inline bool HasVertex(const AGVertex &v) const {
132  return _g.HasVertex(v.get());
133  }
134 
138  inline bool HasVertex(const MGVertex &v) const {
139  return _v2v.find(v) != _v2v.end();
140  }
141 
145  inline bool HasVertex(const MGEdge &e) const {
146  return _e2v.find(e) != _e2v.end();
147  }
148 
154  inline AGVertex GetVertex(const MGVertex &v) const {
155  return HasVertex(v) ? _v2v.at(v) : AGVertex();
156  }
157 
163  inline AGVertex GetVertex(const MGEdge &e) const {
164  return HasVertex(e) ? _e2v.at(e) : AGVertex();
165  }
166 
169  inline size_t NumVertices() const { return _g.NumVertices(); }
170 
175  inline size_t Degree(const AGVertex &v) const {
176  return HasVertex(v) ? _g.Degree(v.get())
177  : std::numeric_limits<size_t>::max();
178  }
179 
185  inline std::pair<NbrsIter, NbrsIter>
186  GetNeighbours(const AGVertex &v) const {
187  return HasVertex(v) ? std::make_pair(_n.at(v).begin(), _n.at(v).end())
188  : std::make_pair(_v.end(), _v.end());
189  }
190 
193  inline std::pair<VertIter, VertIter> GetVertices() const {
194  return {_v.begin(), _v.end()};
195  }
196 
199  // inline bool IsConnected() { return _g.NumConnectedComponents() == 1; }
200 
210  void PreassignElectrons();
211 
212  private:
216  AGVertex AddVertex(MGVertex v);
217 
224  void AddEdges(MGVertex s, MGVertex t, MGEdge e);
225 
227  void DetermineAllNeighbours();
228 
229  private:
231  _MolecularGraph _source;
233  graph_type _g;
235  eastl::vector_map<MGVertex, AGVertex> _v2v;
237  eastl::vector_map<MGEdge, AGVertex> _e2v;
239  VertContain _v;
241  std::map<AGVertex, VertContain> _n;
242  };
243 
244 } // namespace indigox::graph
245 
246 #endif /* INDIGOX_GRAPH_ASSIGNMENT_HPP */
void SetPreAssignedCount(const uint32_t count)
Set the number of pre-assigned eletrons.
Definition: assignment.hpp:71
void PreassignElectrons()
Check if the graph is connected.
MGEdge GetSourceEdge() const
Obtain the referenced IXMolecularGraph edge.
Definition: assignment.hpp:60
Definition: assignment.hpp:16
friend struct indigox::test::TestAssignmentGraph
Friendship allows IXAssignmentGraph to be properly tested.
Definition: assignment.hpp:107
Class used to assign electrons to a molecule.
Definition: assignment.hpp:105
void SetAssignedCount(const uint32_t count)
Set the number of assigned eletrons.
Definition: assignment.hpp:86
Class for the edges of a IXMolecularGraph.
Definition: molecular.hpp:55
Class containing a graph representation of a molecule.
Definition: molecular.hpp:95
std::pair< NbrsIter, NbrsIter > GetNeighbours(const AGVertex &v) const
Get the neighbours of a vertex.
Definition: assignment.hpp:186
VertContain::const_iterator NbrsIter
Type of the iterator returned by the GetNeihbours() method.
Definition: assignment.hpp:118
size_t NumVertices() const
Get the number of vertices in the graph.
Definition: assignment.hpp:169
bool IsVertexMapped() const
Is the associated IXMolecularGraph member a vertex.
Definition: assignment.hpp:42
Class for the vertices of a IXMolecularGraph.
Definition: molecular.hpp:20
MGVertex GetSourceVertex() const
Obtain the referenced IXMolecularGraph vertex.
Definition: assignment.hpp:52
uint32_t GetPreAssignedCount() const
Get the number of pre-assigned electrons.
Definition: assignment.hpp:66
uint32_t GetAssignedCount() const
Get the number of assigned electrons.
Definition: assignment.hpp:76
std::shared_ptr< IXAGVertex > AGVertex
Definition: fwd_declares.hpp:104
VertContain::const_iterator VertIter
Type of the iterator returned by the GetVertices() method.
Definition: assignment.hpp:116
bool HasVertex(const MGEdge &e) const
Check if an IXMGEdge has an associated vertex in this graph.
Definition: assignment.hpp:145
size_t Degree(const AGVertex &v) const
Get the degree of a vertex.
Definition: assignment.hpp:175
AGVertex GetVertex(const MGVertex &v) const
Get the AGVertex associated with an MGVertex.
Definition: assignment.hpp:154
uint32_t GetTotalAssigned() const
Get the total number of assigned electrons.
Definition: assignment.hpp:82
Class for the vertices of an IXAssignmentGraph.
Definition: assignment.hpp:19
bool HasVertex(const AGVertex &v) const
Check if an IXAGVertex belongs to this graph.
Definition: assignment.hpp:131
bool IsEdgeMapped() const
Is the associated IXMoleculerGraph member an edge.
Definition: assignment.hpp:46
AGVertex GetVertex(const MGEdge &e) const
Get the AGVertex associated with an MGEdge.
Definition: assignment.hpp:163
std::pair< VertIter, VertIter > GetVertices() const
Get the vertices of the graph.
Definition: assignment.hpp:193
bool HasVertex(const MGVertex &v) const
Check if an IXMGVertex has an associated vertex in this graph.
Definition: assignment.hpp:138