Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ if(DEBUG)
)
endif(DEBUG)

if (NOT MSVC)
if (MSVC)
add_compile_options(/bigobj)
else ()
option(SANITIZE "Enable Sanitize" OFF)
if(SANITIZE)
add_compile_options(
Expand Down
426 changes: 108 additions & 318 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/CXXGraph/Graph/Algorithm/BronKerbosch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ const BronKerboschResult<T> Graph<T>::bron_kerbosch() const {
}

} // namespace CXXGraph
#endif
#endif // __CXXGRAPH_BRONKERBOSCH_IMPL_H__
73 changes: 73 additions & 0 deletions include/CXXGraph/Graph/Algorithm/EulerianPath_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/***********************************************************/
/*** ______ ____ ______ _ ***/
/*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
/*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
/*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
/*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
/*** |_| ***/
/***********************************************************/
/*** Header-Only C++ Library for Graph ***/
/*** Representation and Algorithms ***/
/***********************************************************/
/*** Author: ZigRazor ***/
/*** E-Mail: zigrazor@gmail.com ***/
/***********************************************************/
/*** Collaboration: ----------- ***/
/***********************************************************/
/*** License: MPL v2.0 ***/
/***********************************************************/

#ifndef __CXXGRAPH_EULERIAN_PATH_IMPL_H__
#define __CXXGRAPH_EULERIAN_PATH_IMPL_H__

#pragma once

#include "CXXGraph/Graph/Graph_decl.h"

namespace CXXGraph {

template <typename T>
std::shared_ptr<std::vector<Node<T>>> Graph<T>::eulerianPath() const {
const auto nodeSet = Graph<T>::getNodeSet();

std::shared_ptr<std::vector<Node<T>>> eulerPath =
std::make_shared<std::vector<Node<T>>>();

// unused
// bool undirected = this->isUndirectedGraph();

std::vector<shared<const Node<T>>> currentPath;
// The starting node is the only node which has more outgoing than ingoing
// links
auto firstNodeIt = std::max_element(nodeSet.begin(), nodeSet.end(),
[this](auto n1, auto n2) {
return cachedAdjListOut->at(n1).size() <
cachedAdjListOut->at(n2).size();
});
auto currentNode = *(firstNodeIt);
currentPath.push_back(currentNode);

while (currentPath.size() > 0) {
auto &edges = cachedAdjListOut->at(currentNode);
// we keep removing the edges that
// have been traversed from the adjacency list
if (edges.size()) {
auto firstEdge = edges.back().second;

shared<const Node<T>> nextNodeId;
nextNodeId = firstEdge->getOtherNode(currentNode);

currentPath.push_back(nextNodeId);
currentNode = nextNodeId;
edges.pop_back();
} else {
eulerPath->push_back(*currentNode);
currentNode = currentPath.back();
currentPath.pop_back();
}
}
return eulerPath;
}
} // namespace CXXGraph

#endif // __CXXGRAPH_EULERIAN_PATH_IMPL_H__
3 changes: 2 additions & 1 deletion include/CXXGraph/Graph/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp"
#include "CXXGraph/Graph/Algorithm/Dial_impl.hpp"
#include "CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp"
#include "CXXGraph/Graph/Algorithm/EulerianPath_impl.hpp"
#include "CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp"
#include "CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp"
#include "CXXGraph/Graph/Algorithm/HopcroftKarp_impl.hpp"
Expand All @@ -45,7 +46,7 @@
#include "CXXGraph/Graph/Algorithm/Tarjan_impl.hpp"
#include "CXXGraph/Graph/Algorithm/TopologicalSort_impl.hpp"
#include "CXXGraph/Graph/Algorithm/TransitiveReduction_impl.hpp"
#include "CXXGraph/Graph/Algorithm/welshPowellColoring_impl.hpp"
#include "CXXGraph/Graph/Algorithm/WelshPowellColoring_impl.hpp"

// IO Operation
#include "CXXGraph/Graph/IO/IOUtility_impl.hpp"
Expand Down
9 changes: 9 additions & 0 deletions include/CXXGraph/Graph/Graph_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ class Graph {
std::unordered_map<std::string, T> &nodeFeatMap,
std::unordered_map<CXXGraph::id_t, double> &edgeWeightMap);

// Type trait used to compile allow compilation when T is not extractable
template <typename U, typename = void>
struct is_istream_extractable : std::false_type {};

template <typename U>
struct is_istream_extractable<
U, std::void_t<decltype(std::declval<std::istream &>() >>
std::declval<U &>())>> : std::true_type {};

#ifdef WITH_COMPRESSION
int compressFile(const std::string &inputFile,
const std::string &outputFile) const;
Expand Down
Loading
Loading