Skip to content

Commit

Permalink
fixed inc_pfxt unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy1005 committed Sep 2, 2023
1 parent 5d7e33c commit d31a3b7
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.26.0)
cmake_minimum_required(VERSION 3.18.0)

# this is hardcoded, can I configure cmake to auto locate nvcc for me?
# set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
Expand Down
1 change: 0 additions & 1 deletion ink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ target_link_libraries(ink PUBLIC std::filesystem)



set_property(TARGET ink PROPERTY CXX_STANDARD 23)
target_compile_options(ink INTERFACE -Wall -Wextra -Wfatal-errors)


42 changes: 35 additions & 7 deletions ink/ink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,14 @@ Edge& Ink::insert_edge(

// record affected pfxt nodes
for (auto n : e.dep_nodes) {
_affected_pfxtnodes.push_back(std::move(n));
// reset node markings
_affected_pfxtnodes.push_back(n);
}
e.dep_nodes.clear();

// initialize pruned weights
for (size_t i = 0; i < NUM_WEIGHTS; i++) {
e.pruned_weights[i] = false;
}

return e;
}
Expand Down Expand Up @@ -261,6 +266,11 @@ Edge& Ink::insert_edge(
e.modified = true;
}

// initialize pruned weights
for (size_t i = 0; i < NUM_WEIGHTS; i++) {
e.pruned_weights[i] = false;
}

return e;
}
}
Expand Down Expand Up @@ -1021,6 +1031,15 @@ Pfxt Ink::_pfxt_cache(const Sfxt& sfxt) const {

void Ink::_update_pfxt(Pfxt& pfxt) {

// reset node markings
for (auto& n : pfxt.paths) {
n->reset();
}

for (auto& n : pfxt.nodes) {
n->reset();
}

// sort affected pfxt nodes by level (ascending)
auto& ap = _affected_pfxtnodes;
if (ap.empty()) {
Expand Down Expand Up @@ -1096,7 +1115,7 @@ void Ink::_update_pfxt(Pfxt& pfxt) {
// and spur each node with their
// corresponding pruned edge + weights
for (const auto& r : _respurs) {
_spur_pruned(pfxt, *r.node, r.pruned);
_spur_pruned(pfxt, *r.node, r.pruned);
}

// update _all_path_costs
Expand All @@ -1110,8 +1129,12 @@ void Ink::_update_pfxt(Pfxt& pfxt) {
}

// validate the priority queue
while (pfxt.top()->detour_cost < max_dc) {
for (auto t = pfxt.top(); t && t->detour_cost < max_dc; ) {
auto node = pfxt.pop();
if (node == nullptr) {
break;
}

if (node->removed) {
continue;
}
Expand Down Expand Up @@ -1545,9 +1568,6 @@ void Ink::_spur_pruned(
for (const auto& p : pruned) {
_eptrs[p.first]->pruned_weights[p.second] = false;
}

// TODO: finish the pfxt validation phase here

}


Expand Down Expand Up @@ -1714,6 +1734,14 @@ size_t PfxtNode::num_children() const {
return children.size();
}

void PfxtNode::reset() {
updated = false;
removed = false;
in_queue = false;
to_respur = false;
pruned.clear();
}

Pfxt::Pfxt(const Sfxt& sfxt) :
sfxt{sfxt}
{
Expand Down
13 changes: 3 additions & 10 deletions ink/ink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,9 @@ struct PfxtNode {
std::optional<std::pair<size_t, size_t>> link;

size_t num_children() const;

void print_stuff() const {
if (edge) {
std::cout << "edge=" << edge->name() << '\n';
}
std::cout << "updated=" << updated << '\n';
std::cout << "removed=" << removed << '\n';
std::cout << "detour_cost=" << detour_cost << '\n';
std::cout << "--------\n";
}

// reset node markings, pruned_weights
void reset();

// for traversing the prefix tree
std::vector<PfxtNode*> children;
Expand Down
5 changes: 0 additions & 5 deletions unittests/c17_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,6 @@ TEST_CASE("c17 Benchmark w/ Incremental Update" * doctest::timeout(300)) {
std::advance(it, 1);
REQUIRE(it->vert.name == "nx22");
REQUIRE(float_equal(it->dist, 17.0f));

for (const auto& p : paths) {
p.dump(std::cout);
}

}


Expand Down
Loading

0 comments on commit d31a3b7

Please sign in to comment.