Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ tests/adiar/internal/data_structures/sorter:
tests/adiar/internal/data_structures/stack:
$(MAKE) $(MAKE_FLAGS) tests TEST_SUBFOLDER=adiar/internal/data_structures/ TEST_NAME=stack

tests/adiar/internal/data_structures/vector:
$(MAKE) $(MAKE_FLAGS) tests TEST_SUBFOLDER=adiar/internal/data_structures/ TEST_NAME=vector

tests/adiar/internal/data_types/arc:
$(MAKE) $(MAKE_FLAGS) tests TEST_SUBFOLDER=adiar/internal/data_types/ TEST_NAME=arc

Expand Down
1 change: 1 addition & 0 deletions src/adiar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(HEADERS
internal/data_structures/priority_queue.h
internal/data_structures/sorter.h
internal/data_structures/stack.h
internal/data_structures/vector.h

# adiar/internal/data_types
internal/data_types/arc.h
Expand Down
9 changes: 5 additions & 4 deletions src/adiar/bdd/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace adiar
{
//////////////////////////////////////////////////////////////////////////////////////////////////
class bdd_eval_func_visitor
{
const predicate<bdd::label_type>& af;
Expand Down Expand Up @@ -54,7 +55,7 @@ namespace adiar
return v.get_result();
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
class bdd_eval_generator_visitor
{
const generator<pair<bdd::label_type, bool>>& _generator;
Expand Down Expand Up @@ -118,7 +119,7 @@ namespace adiar
return v.get_result();
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: Merge code duplication with Curiously Recurring Template Pattern

template <typename Visitor>
Expand Down Expand Up @@ -266,7 +267,7 @@ namespace adiar
{
if (!bdd_iscube(d)) { throw domain_error("BDD 'd' is not a cube"); }

typename internal::level_ifstream_t<bdd>::template stream_t<> d_levels(d);
internal::level_info_ifstream d_levels(d);
const generator<bdd::label_type> d_gen = make_generator__levels(d_levels);

const size_t total_levels = std::min<size_t>(f->levels() + d->levels(), bdd::max_label + 1);
Expand Down Expand Up @@ -298,7 +299,7 @@ namespace adiar
{
if (!bdd_iscube(d)) { throw domain_error("BDD 'd' is not a cube"); }

typename internal::level_ifstream_t<bdd>::template stream_t<> d_levels(d);
internal::level_info_ifstream d_levels(d);
const generator<bdd::label_type> d_gen = make_generator__levels(d_levels);

const size_t total_levels = std::min<size_t>(f->levels() + d->levels(), bdd::max_label + 1);
Expand Down
15 changes: 6 additions & 9 deletions src/adiar/internal/algorithms/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <adiar/internal/algorithms/intercut.h>
#include <adiar/internal/assert.h>
#include <adiar/internal/data_structures/vector.h>
#include <adiar/internal/data_types/node.h>
#include <adiar/internal/data_types/tuple.h>
#include <adiar/internal/dd.h>
Expand Down Expand Up @@ -54,9 +55,9 @@ namespace adiar::internal
static typename to_policy::dd_type
on_terminal_input(const bool terminal_value,
const typename from_policy::dd_type& /*dd*/,
const shared_file<typename from_policy::label_type>& dom)
const internal_vector<typename from_policy::label_type>& dom)
{
adiar_assert(dom->size() > 0, "Emptiness check is before terminal check");
adiar_assert(dom.size() > 0, "Emptiness check is before terminal check");

node::uid_type prior_node = node::uid_type(terminal_value);

Expand All @@ -65,21 +66,17 @@ namespace adiar::internal
bool has_output = true;
node_ofstream nw(nf);

ifstream<typename from_policy::label_type, true> ls(dom);

while (ls.can_pull()) {
const typename to_policy::label_type next_label = ls.pull();

for (auto iter = dom.rbegin(); iter != dom.rend(); ++iter) {
const tuple children = from_policy::reduction_rule_inv(prior_node);
const node next_node = node(next_label, to_policy::max_id, children[0], children[1]);
const node next_node = node(*iter, to_policy::max_id, children[0], children[1]);
const typename to_policy::pointer_type reduction_result =
to_policy::reduction_rule(next_node);

if (reduction_result == next_node.uid()) { // Output
prior_node = next_node.uid();

nw.unsafe_push(next_node);
nw.unsafe_push(level_info(next_label, 1u));
nw.unsafe_push(level_info(*iter, 1u));
} else {
// If we kill the resulting node once, then we will also do it for all the other labels we
// still are missing.
Expand Down
39 changes: 17 additions & 22 deletions src/adiar/internal/algorithms/intercut.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <adiar/internal/cnl.h>
#include <adiar/internal/cut.h>
#include <adiar/internal/data_structures/levelized_priority_queue.h>
#include <adiar/internal/data_structures/vector.h>
#include <adiar/internal/data_types/arc.h>
#include <adiar/internal/data_types/node.h>
#include <adiar/internal/data_types/uid.h>
Expand Down Expand Up @@ -83,7 +84,7 @@ namespace adiar::internal

template <size_t look_ahead, memory_mode mem_mode>
using intercut_priority_queue_t =
levelized_label_priority_queue<intercut_req, intercut_req_lt, look_ahead, mem_mode, 2u, 0u>;
levelized_node_priority_queue<intercut_req, intercut_req_lt, look_ahead, mem_mode, 2u, 0u>;

//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -194,34 +195,27 @@ namespace adiar::internal
// In the general case, we have to use it both in the priority queue
// `intercut_pq` below, and for a lookahead of the algorithm. The main issue
// is how to design the priority queue such that it can retrieve, merge with
// `dd_levels`, and expose `xs`.
shared_file<typename intercut_policy::label_type> hit_levels;
{
ofstream<typename intercut_policy::label_type> lw(hit_levels);
for (auto x = xs(); x; x = xs()) { lw << x.value(); }

if (lw.size() == 0) { return intercut_policy::on_empty_labels(dd); }
}
// the levels of `dd` and expose `xs`.
internal_vector<typename intercut_policy::label_type> hit_levels(dd::max_label);
for (auto x = xs(); x; x = xs()) { hit_levels.push_back(x.value()); }
if (hit_levels.empty()) { return intercut_policy::on_empty_labels(dd); }

if (n.is_terminal()) { return intercut_policy::on_terminal_input(n.value(), dd, hit_levels); }

ifstream<typename intercut_policy::label_type> ls(hit_levels);
typename intercut_policy::label_type l = ls.pull();
typename internal_vector<typename intercut_policy::label_type>::iterator ls =
hit_levels.begin();

shared_levelized_file<arc> out_arcs;
arc_ofstream aw(out_arcs);

out_arcs->max_1level_cut = 0;

shared_file<typename intercut_policy::label_type> dd_levels;
{
ofstream<typename intercut_policy::label_type> lw(dd_levels);
dd_support(dd, [&lw](const typename intercut_policy::label_type x) { lw << x; });
}

// Add request for root in the queue
pq_t intercut_pq({ dd_levels, hit_levels }, pq_memory, max_pq_size, stats_intercut.lpq);
intercut_pq.push(intercut_req(ptr_uint64::nil(), n.uid(), std::min(l, n.label())));
pq_t intercut_pq({ dd, make_generator(hit_levels.begin(), hit_levels.end()) },
pq_memory,
max_pq_size,
stats_intercut.lpq);
intercut_pq.push(intercut_req(ptr_uint64::nil(), n.uid(), std::min(*ls, n.label())));

// Process nodes of the decision diagram in topological order
while (!intercut_pq.empty()) {
Expand All @@ -231,12 +225,13 @@ namespace adiar::internal
const typename intercut_policy::label_type out_label = intercut_pq.current_level();
typename intercut_policy::id_type out_id = 0;

const bool hit_level = out_label == l;
const bool hit_level = out_label == *ls;

// Forward to next label to cut on after this level
while (ls.can_pull() && l <= out_label) { l = ls.pull(); }
while (ls != hit_levels.end() && *ls <= out_label) { ++ls; }

if (!ls.can_pull() && l <= out_label) { l = intercut_policy::max_label + 1; }
typename intercut_policy::label_type l =
ls == hit_levels.end() ? intercut_policy::max_label + 1 : *ls;

// Update max 1-level cut
out_arcs->max_1level_cut = std::max(out_arcs->max_1level_cut, intercut_pq.size());
Expand Down
8 changes: 4 additions & 4 deletions src/adiar/internal/algorithms/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ namespace adiar::internal
size_t _terminals[2] = { 0u, 0u };

public:
reduce_priority_queue(const shared_levelized_file<arc> (&files)[1u],
reduce_priority_queue(std::array<typename inner_lpq::level_input_type, 1>&& files,
size_t memory_given,
size_t max_size,
statistics::levelized_priority_queue_t& stats)
: inner_lpq(files, memory_given, max_size, stats)
: inner_lpq(std::move(files), memory_given, max_size, stats)
{}

reduce_priority_queue(const shared_levelized_file<arc> (&files)[1u],
reduce_priority_queue(std::array<typename inner_lpq::level_input_type, 1>&& files,
size_t memory_given,
size_t max_size)
: reduce_priority_queue(files, memory_given, max_size, stats_reduce.lpq)
: reduce_priority_queue(std::move(files), memory_given, max_size, stats_reduce.lpq)
{}

////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading
Loading