Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test randomized ordering 0515 #440

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ if(BENCHMARK)
CPMAddPackage(
NAME zlib
GITHUB_REPOSITORY madler/zlib
VERSION 1.2.13
#VERSION 1.2.13
VERSION 1.2.12
OPTIONS "CMAKE_POSITION_INDEPENDENT_CODE True"
)

Expand All @@ -40,4 +41,4 @@ if(BENCHMARK)
PUBLIC benchmark::benchmark
PUBLIC zlibstatic
)
endif(BENCHMARK)
endif(BENCHMARK)
11 changes: 11 additions & 0 deletions cmake_and_make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

#if [ -d "build" ]; then
# echo "empty directory build"
# rm -rf build
# mkdir -p build
#fi

cd build
cmake ../ -DTEST=ON -Dgtest_disable_pthreads=OFF
make
11 changes: 7 additions & 4 deletions include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const BellmanFordResult Graph<T>::bellmanford(const Node<T> &source,
result.success = false;
result.errorMessage = "";
result.result = INF_DOUBLE;
auto nodeSet = Graph<T>::getNodeSet();
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();
auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
Expand Down Expand Up @@ -66,7 +67,8 @@ const BellmanFordResult Graph<T>::bellmanford(const Node<T> &source,
auto earlyStopping = false;
// outer loop for vertex relaxation
for (int i = 0; i < n - 1; ++i) {
auto edgeSet = Graph<T>::getEdgeSet();
//auto edgeSet = Graph<T>::getEdgeSet();
auto edgeSet = Graph<T>::getEdgeVector();
// inner loop for distance updates of
// each relaxation
for (const auto &edge : edgeSet) {
Expand Down Expand Up @@ -100,7 +102,8 @@ const BellmanFordResult Graph<T>::bellmanford(const Node<T> &source,

// check if there exists a negative cycle
if (!earlyStopping) {
auto edgeSet = Graph<T>::getEdgeSet();
//auto edgeSet = Graph<T>::getEdgeSet();
auto edgeSet = Graph<T>::getEdgeVector();
for (const auto &edge : edgeSet) {
auto elem = edge->getNodePair();
auto edge_weight =
Expand All @@ -126,4 +129,4 @@ const BellmanFordResult Graph<T>::bellmanford(const Node<T> &source,
return result;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_BELLMANFORD_IMPL_H__
#endif // __CXXGRAPH_BELLMANFORD_IMPL_H__
8 changes: 5 additions & 3 deletions include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ template <typename T>
BestFirstSearchResult<T> Graph<T>::best_first_search(
const Node<T> &source, const Node<T> &target) const {
BestFirstSearchResult<T> result;
auto &nodeSet = Graph<T>::getNodeSet();
//auto &nodeSet = Graph<T>::getNodeSet();
auto &nodeSet = Graph<T>::getNodeVector();
using pq_type = std::pair<double, shared<const Node<T>>>;

auto source_node_it = std::find_if(
Expand Down Expand Up @@ -108,7 +109,8 @@ const std::vector<Node<T>> Graph<T>::concurrency_breadth_first_search(
const Node<T> &start, size_t num_threads) const {
std::vector<Node<T>> bfs_result;
// check is exist node in the graph
auto &nodeSet = Graph<T>::getNodeSet();
//auto &nodeSet = Graph<T>::getNodeSet();
auto &nodeSet = Graph<T>::getNodeVector();
auto start_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&start](auto node) { return node->getUserId() == start.getUserId(); });
Expand Down Expand Up @@ -259,4 +261,4 @@ const std::vector<Node<T>> Graph<T>::concurrency_breadth_first_search(
return bfs_result;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_BESTFIRSTSEARCH_IMPL_H__
#endif // __CXXGRAPH_BESTFIRSTSEARCH_IMPL_H__
11 changes: 7 additions & 4 deletions include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const MstResult Graph<T>::boruvka() const {
result.errorMessage = ERR_DIR_GRAPH;
return result;
}
const auto nodeSet = Graph<T>::getNodeSet();
//const auto nodeSet = Graph<T>::getNodeSet();
const auto nodeSet = Graph<T>::getNodeVector();
const auto n = nodeSet.size();

// Use std map for storing n subsets.
Expand Down Expand Up @@ -133,7 +134,8 @@ const MstResult Graph<T>::boruvka_deterministic() const {
result.errorMessage = ERR_DIR_GRAPH;
return result;
}
const auto nodeSet = Graph<T>::getNodeSet();
//const auto nodeSet = Graph<T>::getNodeSet();
const auto nodeSet = Graph<T>::getNodeVector();
const auto n = nodeSet.size();

// Use std map for storing n subsets.
Expand All @@ -145,7 +147,8 @@ const MstResult Graph<T>::boruvka_deterministic() const {

// check if all edges are weighted and store the weights
// in a map whose keys are the edge ids and values are the edge weights
const auto edgeSet = Graph<T>::getEdgeSet();
//const auto edgeSet = Graph<T>::getEdgeSet();
const auto edgeSet = Graph<T>::getEdgeVector();
std::unordered_map<CXXGraph::id_t, double> edgeWeight;
for (const auto &edge : edgeSet) {
if (edge->isWeighted().has_value() && edge->isWeighted().value())
Expand Down Expand Up @@ -223,4 +226,4 @@ const MstResult Graph<T>::boruvka_deterministic() const {
}

} // namespace CXXGraph
#endif // __CXXGRAPH_BORUVKA_IMPL_H__
#endif // __CXXGRAPH_BORUVKA_IMPL_H__
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/BreadthFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const std::vector<Node<T>> Graph<T>::breadth_first_search(
const Node<T> &start) const {
// vector to keep track of visited nodes
std::vector<Node<T>> visited;
auto &nodeSet = Graph<T>::getNodeSet();
//auto &nodeSet = Graph<T>::getNodeSet();
auto &nodeSet = Graph<T>::getNodeVector();
// check is exist node in the graph
auto start_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -65,4 +66,4 @@ const std::vector<Node<T>> Graph<T>::breadth_first_search(
}

} // namespace CXXGraph
#endif // __CXXGRAPH_BREADTHFIRSTSEARCH_IMPL_H__
#endif // __CXXGRAPH_BREADTHFIRSTSEARCH_IMPL_H__
8 changes: 5 additions & 3 deletions include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ bool Graph<T>::isConnectedGraph() const {
if (!isUndirectedGraph()) {
return false;
} else {
auto nodeSet = getNodeSet();
//auto nodeSet = getNodeSet();
auto nodeSet = getNodeVector();
// created visited map
std::unordered_map<CXXGraph::id_t, bool> visited;
for (const auto &node : nodeSet) {
Expand Down Expand Up @@ -70,7 +71,8 @@ bool Graph<T>::isStronglyConnectedGraph() const {
if (!isDirectedGraph()) {
return false;
} else {
auto nodeSet = getNodeSet();
//auto nodeSet = getNodeSet();
auto nodeSet = getNodeVector();
for (const auto &start_node : nodeSet) {
// created visited map
std::unordered_map<CXXGraph::id_t, bool> visited;
Expand Down Expand Up @@ -106,4 +108,4 @@ bool Graph<T>::isStronglyConnectedGraph() const {
}
}
} // namespace CXXGraph
#endif // __CXXGRAPH_CONNECTIVITY_IMPL_H__
#endif // __CXXGRAPH_CONNECTIVITY_IMPL_H__
8 changes: 5 additions & 3 deletions include/CXXGraph/Graph/Algorithm/CycleDetection_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ bool Graph<T>::isCyclicDirectedGraphDFS() const {
return false;
}
enum nodeStates : uint8_t { not_visited, in_stack, visited };
auto nodeSet = Graph<T>::getNodeSet();
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();

/* State of the node.
*
Expand Down Expand Up @@ -176,7 +177,8 @@ bool Graph<T>::isCyclicDirectedGraphBFS() const {
if (!isDirectedGraph()) {
return false;
}
auto nodeSet = Graph<T>::getNodeSet();
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();

std::unordered_map<CXXGraph::id_t, unsigned int> indegree;
for (const auto &node : nodeSet) {
Expand Down Expand Up @@ -228,4 +230,4 @@ bool Graph<T>::isCyclicDirectedGraphBFS() const {
return !(remain == 0);
}
} // namespace CXXGraph
#endif // __CXXGRAPH_CYCLEDETECTION_IMPL_H__
#endif // __CXXGRAPH_CYCLEDETECTION_IMPL_H__
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const std::vector<Node<T>> Graph<T>::depth_first_search(
const Node<T> &start) const {
// vector to keep track of visited nodes
std::vector<Node<T>> visited;
auto nodeSet = Graph<T>::getNodeSet();
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();
// check is exist node in the graph
auto start_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -61,4 +62,4 @@ const std::vector<Node<T>> Graph<T>::depth_first_search(
}

} // namespace CXXGraph
#endif // __CXXGRAPH_DEPTHFIRSTSEARCH_IMPL_H__
#endif // __CXXGRAPH_DEPTHFIRSTSEARCH_IMPL_H__
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/Dial_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const DialResult Graph<T>::dial(const Node<T> &source, int maxWeight) const {
DialResult result;
result.success = false;

auto nodeSet = getNodeSet();
//auto nodeSet = getNodeSet();
auto nodeSet = getNodeVector();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -155,4 +156,4 @@ const DialResult Graph<T>::dial(const Node<T> &source, int maxWeight) const {
return result;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_DIAL_IMPL_H__
#endif // __CXXGRAPH_DIAL_IMPL_H__
59 changes: 31 additions & 28 deletions include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ template <typename T>
const DijkstraResult Graph<T>::dijkstra(const Node<T>& source,
const Node<T>& target) const {
DijkstraResult result;
auto nodeSet = Graph<T>::getNodeSet();
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -150,19 +151,20 @@ const DijkstraResult Graph<T>::dijkstra(const Node<T>& source,
}

template <typename T>
const DijkstraResult Graph<T>::dijkstra_deterministic(
const Node<T>& source, const Node<T>& target) const {
DijkstraResult result;
auto nodeSet = Graph<T>::getNodeSet();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
if (source_node_it == nodeSet.end()) {
// check if source node exist in the graph
result.errorMessage = ERR_SOURCE_NODE_NOT_IN_GRAPH;
return result;
}
const DijkstraResult Graph<T>::dijkstra_deterministic(const Node<T>& source,
const Node<T>& target) const {
DijkstraResult result;
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
if (source_node_it == nodeSet.end()) {
// check if source node exist in the graph
result.errorMessage = ERR_SOURCE_NODE_NOT_IN_GRAPH;
return result;
}

auto target_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -297,19 +299,20 @@ const DijkstraResult Graph<T>::dijkstra_deterministic(
}

template <typename T>
const DijkstraResult Graph<T>::dijkstra_deterministic2(
const Node<T>& source, const Node<T>& target) const {
DijkstraResult result;
auto nodeSet = Graph<T>::getNodeSet();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
if (source_node_it == nodeSet.end()) {
// check if source node exist in the graph
result.errorMessage = ERR_SOURCE_NODE_NOT_IN_GRAPH;
return result;
}
const DijkstraResult Graph<T>::dijkstra_deterministic2(const Node<T>& source,
const Node<T>& target) const {
DijkstraResult result;
//auto nodeSet = Graph<T>::getNodeSet();
auto nodeSet = Graph<T>::getNodeVector();

auto source_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
if (source_node_it == nodeSet.end()) {
// check if source node exist in the graph
result.errorMessage = ERR_SOURCE_NODE_NOT_IN_GRAPH;
return result;
}

auto target_node_it = std::find_if(
nodeSet.begin(), nodeSet.end(),
Expand Down Expand Up @@ -452,4 +455,4 @@ const DijkstraResult Graph<T>::dijkstra_deterministic2(
}

} // namespace CXXGraph
#endif // __CXXGRAPH_DIJKSTRA_IMPL_H__
#endif // __CXXGRAPH_DIJKSTRA_IMPL_H__
4 changes: 3 additions & 1 deletion include/CXXGraph/Graph/Algorithm/FloydWarshall_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const FWResult Graph<T>::floydWarshall() const {
CXXGraph::pair_hash>
pairwise_dist;
const auto &nodeSet = Graph<T>::getNodeSet();
//const auto &nodeSet = Graph<T>::getNodeVector();
// create a pairwise distance matrix with distance node distances
// set to inf. Distance of node to itself is set as 0.
for (const auto &elem1 : nodeSet) {
Expand All @@ -47,6 +48,7 @@ const FWResult Graph<T>::floydWarshall() const {
}

const auto &edgeSet = Graph<T>::getEdgeSet();
//const auto &edgeSet = Graph<T>::getEdgeVector();
// update the weights of nodesfloydWarshall
// connected by edges
for (const auto &edge : edgeSet) {
Expand Down Expand Up @@ -105,4 +107,4 @@ const FWResult Graph<T>::floydWarshall() const {
return result;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_FLOYDWARSHALL_IMPL_H__
#endif // __CXXGRAPH_FLOYDWARSHALL_IMPL_H__
8 changes: 5 additions & 3 deletions include/CXXGraph/Graph/Algorithm/FordFulkerson_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ double Graph<T>::fordFulkersonMaxFlow(const Node<T> &source,
nodeHash<T>>
weightMap;
// build weight map
auto edgeSet = this->getEdgeSet();
//auto edgeSet = this->getEdgeSet();
auto edgeSet = this->getEdgeVector();
for (const auto &edge : edgeSet) {
// The Edge are all Directed at this point because is checked at the
// start
Expand All @@ -57,7 +58,8 @@ double Graph<T>::fordFulkersonMaxFlow(const Node<T> &source,
}

// Constuct iterators for source and target nodes in nodeSet
auto nodeSet = getNodeSet();
//auto nodeSet = getNodeSet();
auto nodeSet = getNodeVector();
auto source_node_ptr = *std::find_if(
nodeSet.begin(), nodeSet.end(),
[&source](auto node) { return node->getUserId() == source.getUserId(); });
Expand Down Expand Up @@ -105,4 +107,4 @@ double Graph<T>::fordFulkersonMaxFlow(const Node<T> &source,
return maxFlow;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_FORDFULKERSON_IMPL_H__
#endif // __CXXGRAPH_FORDFULKERSON_IMPL_H__
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/Kahn_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ TopoSortResult<T> Graph<T>::kahn() const {
result.errorMessage = ERR_UNDIR_GRAPH;
return result;
} else {
const auto nodeSet = Graph<T>::getNodeSet();
//const auto nodeSet = Graph<T>::getNodeSet();
const auto nodeSet = Graph<T>::getNodeVector();
result.nodesInTopoOrder.reserve(cachedAdjMatrix->size());

std::unordered_map<CXXGraph::id_t, unsigned int> indegree;
Expand Down Expand Up @@ -83,4 +84,4 @@ TopoSortResult<T> Graph<T>::kahn() const {
}
}
} // namespace CXXGraph
#endif // __CXXGRAPH_KAHN_IMPL_H__
#endif // __CXXGRAPH_KAHN_IMPL_H__
Loading
Loading