Skip to content

Commit 4c46755

Browse files
authored
General update: cleaning up the README and fixes #339, #367 (#529)
* Implemented type trait to permit compilation of non-extractable types such as pointers: Fixes #339. Added /bigobj for MSVC compiler. * Harmonised test naming scheme * Added commented out test in ConectivityTest * Improved getNodeSet and getAdjList : Fixes #367 * Moved some functionality out of Graph_impl to lighten the file. * Correctly formatted header gaurds * Added an example and links to more in the README file. * Improved README by reordering and decluttering to make it clearer. Removed implementation and description of algorithms, redirecting the reader to the website and Deoxygen docs. * Amended the capitalisation of WelshPowell * Forced renaming of WelshPowell, git was case-insensitive :( * Fixed shadow template parameter
1 parent 477f5d4 commit 4c46755

18 files changed

Lines changed: 455 additions & 599 deletions

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ if(DEBUG)
1919
)
2020
endif(DEBUG)
2121

22-
if (NOT MSVC)
22+
if (MSVC)
23+
add_compile_options(/bigobj)
24+
else ()
2325
option(SANITIZE "Enable Sanitize" OFF)
2426
if(SANITIZE)
2527
add_compile_options(

README.md

Lines changed: 108 additions & 318 deletions
Large diffs are not rendered by default.

include/CXXGraph/Graph/Algorithm/BronKerbosch_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ const BronKerboschResult<T> Graph<T>::bron_kerbosch() const {
7272
}
7373

7474
} // namespace CXXGraph
75-
#endif
75+
#endif // __CXXGRAPH_BRONKERBOSCH_IMPL_H__
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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_EULERIAN_PATH_IMPL_H__
21+
#define __CXXGRAPH_EULERIAN_PATH_IMPL_H__
22+
23+
#pragma once
24+
25+
#include "CXXGraph/Graph/Graph_decl.h"
26+
27+
namespace CXXGraph {
28+
29+
template <typename T>
30+
std::shared_ptr<std::vector<Node<T>>> Graph<T>::eulerianPath() const {
31+
const auto nodeSet = Graph<T>::getNodeSet();
32+
33+
std::shared_ptr<std::vector<Node<T>>> eulerPath =
34+
std::make_shared<std::vector<Node<T>>>();
35+
36+
// unused
37+
// bool undirected = this->isUndirectedGraph();
38+
39+
std::vector<shared<const Node<T>>> currentPath;
40+
// The starting node is the only node which has more outgoing than ingoing
41+
// links
42+
auto firstNodeIt = std::max_element(nodeSet.begin(), nodeSet.end(),
43+
[this](auto n1, auto n2) {
44+
return cachedAdjListOut->at(n1).size() <
45+
cachedAdjListOut->at(n2).size();
46+
});
47+
auto currentNode = *(firstNodeIt);
48+
currentPath.push_back(currentNode);
49+
50+
while (currentPath.size() > 0) {
51+
auto &edges = cachedAdjListOut->at(currentNode);
52+
// we keep removing the edges that
53+
// have been traversed from the adjacency list
54+
if (edges.size()) {
55+
auto firstEdge = edges.back().second;
56+
57+
shared<const Node<T>> nextNodeId;
58+
nextNodeId = firstEdge->getOtherNode(currentNode);
59+
60+
currentPath.push_back(nextNodeId);
61+
currentNode = nextNodeId;
62+
edges.pop_back();
63+
} else {
64+
eulerPath->push_back(*currentNode);
65+
currentNode = currentPath.back();
66+
currentPath.pop_back();
67+
}
68+
}
69+
return eulerPath;
70+
}
71+
} // namespace CXXGraph
72+
73+
#endif // __CXXGRAPH_EULERIAN_PATH_IMPL_H__

include/CXXGraph/Graph/Algorithm/welshPowellColoring_impl.hpp renamed to include/CXXGraph/Graph/Algorithm/WelshPowellColoring_impl.hpp

File renamed without changes.

include/CXXGraph/Graph/Graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp"
3636
#include "CXXGraph/Graph/Algorithm/Dial_impl.hpp"
3737
#include "CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp"
38+
#include "CXXGraph/Graph/Algorithm/EulerianPath_impl.hpp"
3839
#include "CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp"
3940
#include "CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp"
4041
#include "CXXGraph/Graph/Algorithm/HopcroftKarp_impl.hpp"
@@ -45,7 +46,7 @@
4546
#include "CXXGraph/Graph/Algorithm/Tarjan_impl.hpp"
4647
#include "CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp"
4748
#include "CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp"
48-
#include "CXXGraph/Graph/Algorithm/welshPowellColoring_impl.hpp"
49+
#include "CXXGraph/Graph/Algorithm/WelshPowellColoring_impl.hpp"
4950

5051
// IO Operation
5152
#include "CXXGraph/Graph/IO/IOUtility_impl.hpp"

include/CXXGraph/Graph/Graph_decl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ class Graph {
111111
std::unordered_map<std::string, T> &nodeFeatMap,
112112
std::unordered_map<CXXGraph::id_t, double> &edgeWeightMap);
113113

114+
// Type trait used to compile allow compilation when T is not extractable
115+
template <typename U, typename = void>
116+
struct is_istream_extractable : std::false_type {};
117+
118+
template <typename U>
119+
struct is_istream_extractable<
120+
U, std::void_t<decltype(std::declval<std::istream &>() >>
121+
std::declval<U &>())>> : std::true_type {};
122+
114123
#ifdef WITH_COMPRESSION
115124
int compressFile(const std::string &inputFile,
116125
const std::string &outputFile) const;

0 commit comments

Comments
 (0)