Skip to content

Commit

Permalink
readded tuple indices for tuple graph of width 0
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Mar 2, 2024
1 parent cb26ede commit 32991e2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

__version__ = "0.3.17"
__version__ = "0.3.18"
HERE = Path(__file__).resolve().parent


Expand Down
8 changes: 3 additions & 5 deletions src/novelty/tuple_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ TupleGraph& TupleGraph::operator=(TupleGraph&& other) = default;
TupleGraph::~TupleGraph() = default;

std::string TupleGraph::compute_repr() const {
// Step 1: Sort nodes, compute index remapping
// Step 1: Sort tuple nodes by tuple index, compute index remapping
TupleNodes nodes = m_nodes;
std::sort(nodes.begin(), nodes.end(), [](const TupleNode& l, const TupleNode& r){
if (l.get_state_indices() == r.get_state_indices()) {
return l.get_tuple_index() < r.get_tuple_index();
}
return l.get_state_indices() < r.get_state_indices();
return l.get_tuple_index() < r.get_tuple_index();
});
// Remap node indices to get a canonical representation
std::vector<TupleNodeIndex> remapping(nodes.size());
for (size_t i = 0; i < nodes.size(); ++i) {
remapping[nodes[i].get_index()] = i; // old to new index
Expand Down
6 changes: 3 additions & 3 deletions src/novelty/tuple_graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ bool TupleGraphBuilder::test_prune(const std::vector<TupleNode>& tuple_node_laye

void TupleGraphBuilder::build_width_equal_0_tuple_graph() {
TupleNodeIndex initial_node_index = m_nodes.size();
TupleIndex tuple_index = m_novelty_base->atom_indices_to_tuple_index({});
m_node_indices_by_distance.push_back({initial_node_index});
m_nodes.push_back({TupleNode(initial_node_index, tuple_index, {m_root_state_index})});
m_nodes.push_back({TupleNode(initial_node_index, initial_node_index, {m_root_state_index})});
m_state_indices_by_distance.push_back({m_root_state_index});
const auto& it = m_state_space->get_forward_successor_state_indices().find(m_root_state_index);
if (it != m_state_space->get_forward_successor_state_indices().end()) {
Expand All @@ -130,7 +129,8 @@ void TupleGraphBuilder::build_width_equal_0_tuple_graph() {
for (const auto& target_index : it->second) {
TupleNodeIndex node_index = m_nodes.size();
curr_tuple_layer.push_back(node_index);
auto tuple_node = TupleNode(node_index, tuple_index, {target_index});
auto tuple_node = TupleNode(node_index, node_index, {target_index});
std::cout << node_index << std::endl;
m_nodes.push_back(tuple_node);
m_nodes[initial_node_index].add_successor(node_index);
m_nodes[node_index].add_predecessor(initial_node_index);
Expand Down
Loading

0 comments on commit 32991e2

Please sign in to comment.