Skip to content

Commit

Permalink
Move more function from Run in subfunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarex committed May 28, 2015
1 parent 1164a65 commit d64e6e6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion contractor/contractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class Contractor
}
// clear input vector
input_edge_list.clear();
// FIXME not sure if we need this
edges.shrink_to_fit();

tbb::parallel_sort(edges.begin(), edges.end());
Expand Down Expand Up @@ -953,7 +954,6 @@ class Contractor
}

std::shared_ptr<ContractorGraph> contractor_graph;
std::vector<ContractorGraph::InputEdge> contracted_edge_list;
stxxl::vector<QueryEdge> external_edge_list;
std::vector<NodeID> orig_node_id_to_new_id_map;
XORFastHash fast_hash;
Expand Down
73 changes: 39 additions & 34 deletions contractor/processing_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,18 @@ int Prepare::Process(int argc, char *argv[])
rtree_nodes_output_path = osrm_input_path.string() + ".ramIndex";
rtree_leafs_output_path = osrm_input_path.string() + ".fileIndex";

/*** Setup Scripting Environment ***/
// Create a new lua state


SimpleLogger().Write() << "Generating edge-expanded graph representation";

TIMER_START(expansion);

std::vector<EdgeBasedNode> node_based_edge_list;
auto node_based_edge_list = osrm::make_unique<std::vector<EdgeBasedNode>>();;
DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
auto internal_to_external_node_map = osrm::make_unique<std::vector<QueryNode>>();
auto graph_size =
BuildEdgeExpandedGraph(*internal_to_external_node_map,
node_based_edge_list, edge_based_edge_list);
*node_based_edge_list, edge_based_edge_list);

auto number_of_node_based_nodes = graph_size.first;
auto number_of_edge_based_nodes = graph_size.second;
Expand All @@ -146,49 +144,26 @@ int Prepare::Process(int argc, char *argv[])
SimpleLogger().Write() << "building r-tree ...";
TIMER_START(rtree);

BuildRTree(node_based_edge_list, *internal_to_external_node_map);
BuildRTree(*node_based_edge_list, *internal_to_external_node_map);

TIMER_STOP(rtree);

RangebasedCRC32 crc32;
if (crc32.using_hardware())
{
SimpleLogger().Write() << "using hardware based CRC32 computation";
}
else
{
SimpleLogger().Write() << "using software based CRC32 computation";
}

const unsigned crc32_value = crc32(node_based_edge_list);
node_based_edge_list.clear();
node_based_edge_list.shrink_to_fit();
SimpleLogger().Write() << "CRC32: " << crc32_value;
const unsigned crc32_value = CalculateEdgeChecksum(std::move(node_based_edge_list));

SimpleLogger().Write() << "writing node map ...";
WriteNodeMapping(std::move(internal_to_external_node_map));

/***
* Contracting the edge-expanded graph
*/

SimpleLogger().Write() << "initializing contractor";
auto contractor =
osrm::make_unique<Contractor>(number_of_edge_based_nodes, edge_based_edge_list);
// Contracting the edge-expanded graph

TIMER_START(contraction);
contractor->Run();
DeallocatingVector<QueryEdge> contracted_edge_list;
ContractGraph(number_of_edge_based_nodes, edge_based_edge_list, contracted_edge_list);
TIMER_STOP(contraction);

SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec";

DeallocatingVector<QueryEdge> contracted_edge_list;
contractor->GetEdges(contracted_edge_list);
contractor.reset();

/***
* Sorting contracted edges in a way that the static query graph can read some in in-place.
*/
// Sorting contracted edges in a way that the static query graph can read some in in-place.

tbb::parallel_sort(contracted_edge_list.begin(), contracted_edge_list.end());
const unsigned contracted_edge_count = contracted_edge_list.size();
Expand Down Expand Up @@ -254,8 +229,8 @@ int Prepare::Process(int argc, char *argv[])
hsgr_output_stream.write((char *)&node_array[0],
sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
}
// serialize all edges

// serialize all edges
SimpleLogger().Write() << "Building edge array";
edge = 0;
int number_of_used_edges = 0;
Expand Down Expand Up @@ -309,6 +284,24 @@ int Prepare::Process(int argc, char *argv[])
return 0;
}

unsigned Prepare::CalculateEdgeChecksum(std::unique_ptr<std::vector<EdgeBasedNode>> node_based_edge_list)
{
RangebasedCRC32 crc32;
if (crc32.using_hardware())
{
SimpleLogger().Write() << "using hardware based CRC32 computation";
}
else
{
SimpleLogger().Write() << "using software based CRC32 computation";
}

const unsigned crc32_value = crc32(*node_based_edge_list);
SimpleLogger().Write() << "CRC32: " << crc32_value;

return crc32_value;
}

/**
\brief Parses command line arguments
\param argc count of arguments
Expand Down Expand Up @@ -542,6 +535,18 @@ Prepare::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_nod
return std::make_pair(number_of_node_based_nodes, number_of_edge_based_nodes);
}

/**
\brief Build contracted graph.
*/
void Prepare::ContractGraph(const std::size_t number_of_edge_based_nodes,
DeallocatingVector<EdgeBasedEdge>& edge_based_edge_list,
DeallocatingVector<QueryEdge>& contracted_edge_list)
{
Contractor contractor(number_of_edge_based_nodes, edge_based_edge_list);
contractor.Run();
contractor.GetEdges(contracted_edge_list);
}

/**
\brief Writing info on original (node-based) nodes
*/
Expand Down
13 changes: 8 additions & 5 deletions contractor/processing_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ class Prepare
EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile);
void LoadRestrictionMap(const std::unordered_map<NodeID, NodeID> &external_to_internal_node_map,
RestrictionMap &restriction_map);
std::shared_ptr<NodeBasedDynamicGraph>
LoadNodeBasedGraph(std::vector<NodeID> &barrier_node_list,
std::vector<NodeID> &traffic_light_list,
RestrictionMap &restriction_map,
std::vector<QueryNode>& internal_to_external_node_map);
unsigned CalculateEdgeChecksum(std::unique_ptr<std::vector<EdgeBasedNode>> node_based_edge_list);
void ContractGraph(const std::size_t number_of_edge_based_nodes,
DeallocatingVector<EdgeBasedEdge>& edge_based_edge_list,
DeallocatingVector<QueryEdge>& contracted_edge_list);
std::shared_ptr<NodeBasedDynamicGraph> LoadNodeBasedGraph(std::vector<NodeID> &barrier_node_list,
std::vector<NodeID> &traffic_light_list,
RestrictionMap &restriction_map,
std::vector<QueryNode>& internal_to_external_node_map);
std::pair<std::size_t, std::size_t>
BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_node_map,
std::vector<EdgeBasedNode> &node_based_edge_list,
Expand Down

0 comments on commit d64e6e6

Please sign in to comment.