Skip to content

Commit

Permalink
start on oneToMany
Browse files Browse the repository at this point in the history
comments
  • Loading branch information
ghoshkaj committed Apr 30, 2018
1 parent b3aa758 commit 0470d55
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 14 deletions.
12 changes: 6 additions & 6 deletions features/testbot/distance_matrix.feature
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ Feature: Basic Distance Matrix
| | a | b | c | d |
| a | 0 | 100 | 200 | 299.9 |
| b | 100 | 0 | 100 | 200 |
| c | 200 | 100 | 0 | 100 |
| d | 299.9 | 200 | 100 | 0 |
# | c | 200 | 100 | 0 | 100 |
# | d | 299.9 | 200 | 100 | 0 |

# When I request a travel distance matrix I should get
# | | a | b | c | d |
# | a | 0 | 100 | 200 | 299.9 |
When I request a travel distance matrix I should get
| | a | b | c | d |
| a | 0 | 100 | 200 | 299.9 |

# When I request a travel distance matrix I should get
# | | a |
Expand Down Expand Up @@ -481,4 +481,4 @@ Feature: Basic Distance Matrix
# | a | 0 |
# | b | 299.9 |
# | c | 200 |
# | d | 499.9 |
# | d | 499.9 |
6 changes: 6 additions & 0 deletions include/engine/routing_algorithms/routing_base_mld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ template <bool DIRECTION, typename OutIter>
inline void retrievePackedPathFromSingleManyToManyHeap(
const SearchEngineData<Algorithm>::ManyToManyQueryHeap &heap, const NodeID middle, OutIter out)
{
std::cout << "and do I ever get here? middle: " << middle << std::endl;

NodeID current = middle;
NodeID parent = heap.GetData(current).parent;

while (current != parent)
{
std::cout << "inside while loop: current: " << current << " parent: " << parent
<< std::endl;
const auto &data = heap.GetData(current);

if (DIRECTION == FORWARD_DIRECTION)
Expand All @@ -105,9 +109,11 @@ template <bool DIRECTION>
inline PackedPath retrievePackedPathFromSingleManyToManyHeap(
const SearchEngineData<Algorithm>::ManyToManyQueryHeap &heap, const NodeID middle)
{
std::cout << "do I ever get here?" << std::endl;
PackedPath packed_path;
retrievePackedPathFromSingleManyToManyHeap<DIRECTION>(
heap, middle, std::back_inserter(packed_path));
std::cout << "do I reach the bottom of the non-recursive heap search?" << std::endl;
return packed_path;
}

Expand Down
2 changes: 2 additions & 0 deletions include/util/query_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ class QueryHeap
Data &GetData(NodeID node)
{
const auto index = node_index.peek_index(node);
BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size());
return inserted_nodes[index].data;
}

Data const &GetData(NodeID node) const
{
const auto index = node_index.peek_index(node);
BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size());
return inserted_nodes[index].data;
}

Expand Down
86 changes: 78 additions & 8 deletions src/engine/routing_algorithms/many_to_many_mld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,10 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const std::vector<std::size_t> &phantom_indices,
const bool calculate_distance)
{
(void)calculate_distance; // flag stub to use for calculating distances in matrix in mld in the
// future

std::vector<EdgeWeight> weights(phantom_indices.size(), INVALID_EDGE_WEIGHT);
std::vector<EdgeDuration> durations(phantom_indices.size(), MAXIMAL_EDGE_DURATION);
std::vector<EdgeDistance> distances(phantom_indices.size(), INVALID_EDGE_DISTANCE);
std::vector<EdgeDistance> distances;
std::vector<NodeID> middle_nodes_table(phantom_indices.size(), SPECIAL_NODEID);

// Collect destination (source) nodes into a map
std::unordered_multimap<NodeID, std::tuple<std::size_t, EdgeWeight, EdgeDuration>>
Expand Down Expand Up @@ -291,6 +289,7 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
{
weights[index] = path_weight;
durations[index] = path_duration;
middle_nodes_table[index] = node;
}

// Remove node from destinations list
Expand Down Expand Up @@ -322,33 +321,54 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
}
};

NodeID SourceOrDestination = 0;

{ // Place source (destination) adjacent nodes into the heap
const auto &phantom_node = phantom_nodes[phantom_index];

if (DIRECTION == FORWARD_DIRECTION)
{

if (phantom_node.IsValidForwardSource())
{
std::cout << " phantom_node.forward_segment_id.id: "
<< phantom_node.forward_segment_id.id << std::endl;
SourceOrDestination = phantom_node.forward_segment_id.id;
insert_node(phantom_node.forward_segment_id.id,
-phantom_node.GetForwardWeightPlusOffset(),
-phantom_node.GetForwardDuration());
}

if (phantom_node.IsValidReverseSource())
{
std::cout << " phantom_node.reverse_segment_id.id: "
<< phantom_node.reverse_segment_id.id << std::endl;
SourceOrDestination = phantom_node.reverse_segment_id.id;
insert_node(phantom_node.reverse_segment_id.id,
-phantom_node.GetReverseWeightPlusOffset(),
-phantom_node.GetReverseDuration());
}
}
else if (DIRECTION == REVERSE_DIRECTION)
{
if (phantom_node.IsValidForwardTarget())
{
std::cout << " phantom_node.forward_segment_id.id: "
<< phantom_node.forward_segment_id.id << std::endl;
SourceOrDestination = phantom_node.forward_segment_id.id;
insert_node(phantom_node.forward_segment_id.id,
phantom_node.GetForwardWeightPlusOffset(),
phantom_node.GetForwardDuration());
}

if (phantom_node.IsValidReverseTarget())
{
std::cout << " phantom_node.reverse_segment_id.id: "
<< phantom_node.reverse_segment_id.id << std::endl;
SourceOrDestination = phantom_node.reverse_segment_id.id;
insert_node(phantom_node.reverse_segment_id.id,
phantom_node.GetReverseWeightPlusOffset(),
phantom_node.GetReverseDuration());
}
}
}

Expand All @@ -373,6 +393,59 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
phantom_indices);
}

if (calculate_distance)
{

distances.resize(phantom_indices.size(), INVALID_EDGE_DISTANCE);

// std::cout << "query_heap.Size()" << query_heap.Size() << std::endl;
// std::cout << "query_heap.Min()" << query_heap.Min() << std::endl;

std::cout << "Source or Destination Node: " << SourceOrDestination << std::endl;
// PackedPath packed_path = mld::retrievePackedPathFromSingleManyToManyHeap<DIRECTION>(
// query_heap,
// SourceOrDestination); // packed_path_from_source_to_middle

std::cout << "Target Nodes: ";
auto index = 0;
for (auto middle_node_id : middle_nodes_table)
{
std::cout << middle_node_id << ", ";
}

for (auto middle_node_id : middle_nodes_table)
{

std::cout << "middle_node_id: " << middle_node_id << std::endl;

if (SourceOrDestination == middle_node_id)
{
distances[index] = 0.0;
index++;
continue;
}

// BOOST_ASSERT_MSG(!query_heap.Empty(), "Query Heap is Empty");
// if (!query_heap.Empty()){
PackedPath packed_path = mld::retrievePackedPathFromSingleManyToManyHeap<DIRECTION>(
query_heap,
middle_node_id); // packed_path_from_source_to_middle
// std::cout << "Fine then do I get here?" << std::endl;
// std::reverse(packed_path.begin(), packed_path.end());
// if (!packed_path.empty()) {
// std::cout << "packed_path: ";
// for (auto edge : packed_path)
// {
// std::cout << std::get<0>(edge) << ",";
// }
// std::cout << std::get<1>(packed_path.back());
// std::cout << std::endl;
// }
// }
index++;
}
}

return std::make_pair(durations, distances);
}

Expand Down Expand Up @@ -539,7 +612,6 @@ void calculateDistances(typename SearchEngineData<mld::Algorithm>::ManyToManyQue
continue;
}

std::cout << "middle_node_id: " << middle_node_id << std::endl;
std::cout << "source_phantom.forward_segment_id.id: "
<< source_phantom.forward_segment_id.id
<< " source_phantom.reverse_segment_id.id: "
Expand Down Expand Up @@ -865,8 +937,6 @@ manyToManySearch(SearchEngineData<mld::Algorithm> &engine_working_data,
const bool calculate_distance,
const bool calculate_duration)
{
(void)calculate_distance; // flag stub to use for calculating distances in matrix in mld in the
// future
(void)calculate_duration; // flag stub to use for calculating distances in matrix in mld in the
// future

Expand Down

0 comments on commit 0470d55

Please sign in to comment.