Skip to content

Commit

Permalink
Loads the edge based graph edges and constructs a dynamic graph from it
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Feb 8, 2017
1 parent 032d1da commit 35c981a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 8 deletions.
91 changes: 91 additions & 0 deletions include/partition/edge_based_graph_reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#ifndef OSRM_EDGE_BASED_GRAPH_READER_HPP
#define OSRM_EDGE_BASED_GRAPH_READER_HPP

#include "storage/io.hpp"
#include "util/coordinate.hpp"
#include "util/dynamic_graph.hpp"

#include <cstdint>

#include <algorithm>
#include <iterator>
#include <memory>
#include <vector>

namespace osrm
{
namespace partition
{

struct EdgeBasedGraphEdgeData
{
};

struct EdgeBasedGraph : util::DynamicGraph<EdgeBasedGraphEdgeData>
{
using Base = util::DynamicGraph<EdgeBasedGraphEdgeData>;
using Base::Base;
};

struct EdgeBasedGraphEdge : EdgeBasedGraph::InputEdge
{
using Base = EdgeBasedGraph::InputEdge;
using Base::Base;
};

struct EdgeBasedGraphReader
{
EdgeBasedGraphReader(storage::io::FileReader &reader)
{
// Reads: | Fingerprint | #e | max_eid | edges |
// - uint64: number of edges
// - EdgeID: max edge id
// - extractor::EdgeBasedEdge edges
//
// Gets written in Extractor::WriteEdgeBasedGraph

const auto num_edges = reader.ReadElementCount64();
const auto max_edge_id = reader.ReadOne<EdgeID>();

// Sentinel
num_nodes = max_edge_id + 1;

edges.resize(num_edges);
reader.ReadInto(edges);
}

// FIXME: wrapped in unique_ptr since dynamic_graph is not move-able

std::unique_ptr<EdgeBasedGraph> BuildEdgeBasedGraph()
{
std::sort(begin(edges), end(edges));

// TODO: See GraphContractor ctor for the ugly dance one has to perform here
std::vector<EdgeBasedGraphEdge> graph_edges(edges.size());

std::transform(begin(edges), end(edges), begin(graph_edges), [](const auto &edge) {
return EdgeBasedGraphEdge{edge.source, edge.target};
});

return std::make_unique<EdgeBasedGraph>(num_nodes, graph_edges);
}

private:
std::vector<extractor::EdgeBasedEdge> edges;
std::size_t num_nodes;
};

inline std::unique_ptr<EdgeBasedGraph> LoadEdgeBasedGraph(const std::string &path)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader(path, fingerprint);

EdgeBasedGraphReader builder{reader};

return builder.BuildEdgeBasedGraph();
}

} // ns partition
} // ns osrm

#endif
2 changes: 0 additions & 2 deletions include/util/dynamic_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ template <typename EdgeDataT> class DynamicGraph
}
}

~DynamicGraph() {}

unsigned GetNumberOfNodes() const { return number_of_nodes; }

unsigned GetNumberOfEdges() const { return number_of_edges; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STATIC_GRAPH_TRAITS_HPP
#define STATIC_GRAPH_TRAITS_HPP
#ifndef OSRM_GRAPH_TRAITS_HPP
#define OSRM_GRAPH_TRAITS_HPP

#include <type_traits>

Expand Down Expand Up @@ -31,14 +31,14 @@ struct HasTargetMember<T, decltype((void)(sizeof(std::declval<T>().target) > 0))
{
};

// Static Graph requires edges to have a .target and .data member attribute
// Our graphs require edges to have a .target and .data member attribute
template <typename Edge>
struct HasDataAndTargetMember
: std::integral_constant<bool, HasDataMember<Edge>::value && HasTargetMember<Edge>::value>
{
};

// Static Graph requires nodes to have a .first_edge member attribute
// Our graphs require nodes to have a .first_edge member attribute
template <typename T, typename = void> struct HasFirstEdgeMember : std::false_type
{
};
Expand Down
2 changes: 1 addition & 1 deletion include/util/static_graph.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef STATIC_GRAPH_HPP
#define STATIC_GRAPH_HPP

#include "util/graph_traits.hpp"
#include "util/integer_range.hpp"
#include "util/percent.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/static_graph_traits.hpp"
#include "util/typedefs.hpp"

#include <boost/assert.hpp>
Expand Down
25 changes: 24 additions & 1 deletion src/partition/partitioner.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "partition/partitioner.hpp"
#include "partition/bisection_graph.hpp"
#include "partition/compressed_node_based_graph_reader.hpp"
#include "partition/edge_based_graph_reader.hpp"
#include "partition/node_based_graph_to_edge_based_graph_mapping_reader.hpp"
#include "partition/recursive_bisection.hpp"

#include "util/coordinate.hpp"
#include "util/geojson_debug_logger.hpp"
#include "util/geojson_debug_policies.hpp"
#include "util/integer_range.hpp"
#include "util/json_container.hpp"
#include "util/log.hpp"

Expand Down Expand Up @@ -115,9 +117,30 @@ int Partitioner::Run(const PartitionConfig &config)
recursive_bisection.BisectionIDs());

auto mapping = LoadNodeBasedGraphToEdgeBasedGraphMapping(config.nbg_ebg_mapping_path.string());

util::Log() << "Loaded node based graph to edge based graph mapping";

auto edge_based_graph = LoadEdgeBasedGraph(config.edge_based_graph_path.string());
util::Log() << "Loaded edge based graph for mapping partition ids: "
<< edge_based_graph->GetNumberOfEdges() << " edges, "
<< edge_based_graph->GetNumberOfNodes() << " nodes";

for (const auto node_id : util::irange(0u, edge_based_graph->GetNumberOfNodes()))
{
const auto node_based_nodes = mapping.Lookup(node_id);

const auto u = node_based_nodes.u;
const auto v = node_based_nodes.v;

auto partition_id = [](auto) {
return 0; /*dummy*/
};

if (partition_id(u) != partition_id(v))
{
// TODO: resolve border nodes u, v
}
}

return 0;
}

Expand Down

0 comments on commit 35c981a

Please sign in to comment.