| CXXGraph 0.4.0 CXXGraph is a header only, that manages the Graphs and it's algorithm in C++

Typedef.hpp
1 /***********************************************************/
2 /*** ______ ____ ______ _ ***/
3 /*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
4 /*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
5 /*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
6 /*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
7 /*** |_| ***/
8 /***********************************************************/
9 /*** Header-Only C++ Library for Graph ***/
10 /*** Representation and Algorithms ***/
11 /***********************************************************/
12 /*** Author: ZigRazor ***/
13 /*** E-Mail: zigrazor@gmail.com ***/
14 /***********************************************************/
15 /*** Collaboration: ----------- ***/
16 /***********************************************************/
17 /*** License: MPL v2.0 ***/
18 /***********************************************************/
19
20 #ifndef __CXXGRAPH_TYPEDEF_H__
21 #define __CXXGRAPH_TYPEDEF_H__
22
23 #pragma once
24
25 #include <map>
26 #include <string>
27 #include <fstream>
28
29 namespace CXXGRAPH
30 {
31
32 template <typename T>
33 class Node;
34
35 template <typename T>
36 class Edge;
37
38 namespace PARTITIONING{
39 template<typename T>
40 class Partition;
41 }
42 // ENUMERATION //////////////////////////////////////
43
45 enum E_InputOutputFormat
46 {
47 STANDARD_CSV,
48 STANDARD_TSV,
49 OUT_1,
50 OUT_2
51 };
52
53 typedef E_InputOutputFormat InputOutputFormat;
54
55
56
58 // Structures ///////////////////////////////////////
59
61 struct Subset_struct
62 {
63 unsigned long long parent = 0; // parent of the current set
64 unsigned long long rank = 0; // rank of the current set, used for balancing the trees
65 };
66 typedef Subset_struct Subset;
67
69 struct DijkstraResult_struct
70 {
71 bool success = false; // TRUE if the function does not return error, FALSE otherwise
72 std::string errorMessage = ""; //message of error
73 double result = INF_DOUBLE; //result (valid only if success is TRUE)
74 };
75 typedef DijkstraResult_struct DijkstraResult;
76
78 struct BellmanFordResult_struct
79 {
80 bool success = false; // TRUE if the function does not return error, FALSE otherwise
81 bool negativeCycle = false; // TRUE if graph contains a negative cycle, FALSE otherwise
82 std::string errorMessage = ""; //message of error
83 double result = 0.0; //result (valid only if success is TRUE & negativeCycle is false )
84 };
85 typedef BellmanFordResult_struct BellmanFordResult;
86
87 // implmentation is similar to boost hash_combine
88 template<typename T>
89 inline T hash_combine(T& lhs, const T& rhs) {
90 T result = lhs ^ (rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2));
91 return result;
92 }
93
99 struct pair_hash {
100 template <class T1, class T2>
101 std::size_t operator () (const std::pair<T1,T2> &p) const {
102 std::size_t h1 = std::hash<T1>{}(p.first);
103 std::size_t h2 = std::hash<T2>{}(p.second);
104 return hash_combine(h1, h2);
105 }
106 };
107
109 struct FWResult_struct
110 {
111 bool success = false; // TRUE if the function does not return error, FALSE otherwise
112 bool negativeCycle = false; // TRUE if graph contains a negative cycle, FALSE otherwise
113 std::string errorMessage = ""; //message of error
114 std::unordered_map<std::pair<std::string, std::string>, double, pair_hash> result = {};
115 };
116 typedef FWResult_struct FWResult;
117
119 struct MstResult_struct
120 {
121 bool success = false; // TRUE if the function does not return error, FALSE otherwise
122 std::string errorMessage = ""; //message of error
123 std::vector<std::pair<std::string, std::string>> mst = {}; // Stores the nodes of MST (string node-names are set by user during init)
124 double mstCost = 0.0; // MST
125 };
126 typedef MstResult_struct MstResult;
127
129 struct DialResult_struct
130 {
131 bool success = false; // TRUE if the function does not return error, FALSE otherwise
132 std::string errorMessage = ""; //message of error
133 std::unordered_map<unsigned long long, long> minDistanceMap = {}; //result a map that contains the node id and the minumum distance from source (valid only if success is TRUE)
134 };
135 typedef DialResult_struct DialResult;
136
138
139
141 // Using Definition ///////////////////////////////////////////////////////////////
142
143 template <typename T>
144 using AdjacencyMatrix = std::unordered_map<const Node<T> *, std::vector<std::pair<const Node<T> *, const Edge<T> *>>>;
145
146 template <typename T>
147 using PartitionMap = std::unordered_map<unsigned int, std::shared_ptr<PARTITIONING::Partition<T>>>;
148
150 }
151
152 #endif // __CXXGRAPH_TYPEDEF_H__
CXXGRAPH::Edge
Definition: Edge.hpp:39
CXXGRAPH::BellmanFordResult_struct
Struct that contains the information about Dijsktra's Algorithm results.
Definition: Typedef.hpp:79
CXXGRAPH::DialResult_struct
Struct that contains the information about Dijsktra's Algorithm results.
Definition: Typedef.hpp:130
CXXGRAPH::DijkstraResult_struct
Struct that contains the information about Dijsktra's Algorithm results.
Definition: Typedef.hpp:70
CXXGRAPH::FWResult_struct
Struct that contains the information about Floyd-Warshall Algorithm results.
Definition: Typedef.hpp:110
CXXGRAPH::MstResult_struct
Struct that contains the information about Prim, Boruvka & Kruskal Algorithm results.
Definition: Typedef.hpp:120
CXXGRAPH::Subset_struct
Struct useful for union-find operations.
Definition: Typedef.hpp:62
CXXGRAPH::pair_hash
Definition: Typedef.hpp:99