Skip to content

Commit

Permalink
Format latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Apr 30, 2024
1 parent f6c47f5 commit 7b3579c
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 340 deletions.
7 changes: 4 additions & 3 deletions src/adiar/bdd/restrict.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <adiar/bdd.h>
#include <adiar/bdd/bdd_policy.h>

#include <adiar/types.h>

#include <adiar/internal/algorithms/select.h>
Expand All @@ -13,11 +12,13 @@ namespace adiar
{
//////////////////////////////////////////////////////////////////////////////
template <typename AssignmentPolicy>
class bdd_restrict_policy : public bdd_policy, public AssignmentPolicy
class bdd_restrict_policy
: public bdd_policy
, public AssignmentPolicy
{
public:
template <typename Arg>
bdd_restrict_policy(const Arg &a)
bdd_restrict_policy(const Arg& a)
: AssignmentPolicy(a)
{}

Expand Down
74 changes: 23 additions & 51 deletions src/adiar/internal/algorithms/quantify.h
Original file line number Diff line number Diff line change
Expand Up @@ -1232,29 +1232,19 @@ namespace adiar::internal
{
// -------------------------------------------------------------------------------------------
// CASE: Not to-be quantified node.
if (!_pred_result) {
return n;
}
if (!_pred_result) { return n; }

// -------------------------------------------------------------------------------------------
// CASE: Prune low()
//
// TODO (ZDD): Remove 'Policy::keep_terminal' depending on semantics in Policy
if (Policy::collapse_to_terminal(n.low())) {
return n.low();
}
if (n.low().is_terminal() && !Policy::keep_terminal(n.low())) {
return n.high();
}
if (Policy::collapse_to_terminal(n.low())) { return n.low(); }
if (n.low().is_terminal() && !Policy::keep_terminal(n.low())) { return n.high(); }

// -------------------------------------------------------------------------------------------
// CASE: Prune high()
if (Policy::collapse_to_terminal(n.high())) {
return n.high();
}
if (n.high().is_terminal() && !Policy::keep_terminal(n.high())) {
return n.low();
}
if (Policy::collapse_to_terminal(n.high())) { return n.high(); }
if (n.high().is_terminal() && !Policy::keep_terminal(n.high())) { return n.low(); }

// -------------------------------------------------------------------------------------------
// No pruning possible. Do nothing.
Expand Down Expand Up @@ -1363,7 +1353,6 @@ namespace adiar::internal
struct quantify__pred_profile
{
private:

public:
/// \brief Total number of nodes in the diagram.
size_t dd_size;
Expand Down Expand Up @@ -1399,36 +1388,24 @@ namespace adiar::internal
};

/// \brief The *deepest* to-be quantified level.
var_data deepest_var
{
0,
std::numeric_limits<size_t>::max(),
Policy::max_id+1
};
var_data deepest_var{ 0, std::numeric_limits<size_t>::max(), Policy::max_id + 1 };

/// \brief The *shallowest* to-be quantified level.
var_data shallowest_var
{
Policy::max_label+1,
std::numeric_limits<size_t>::max(),
Policy::max_id+1
};
var_data shallowest_var{ Policy::max_label + 1,
std::numeric_limits<size_t>::max(),
Policy::max_id + 1 };

/// \brief The *widest* to-be quantified level.
var_data widest_var
{
Policy::max_label+1,
var_data widest_var{
Policy::max_label + 1,
std::numeric_limits<size_t>::max(),
0,
};

/// \brief The *narrowest* to-be quantified level.
var_data narrowest_var
{
Policy::max_label+1,
std::numeric_limits<size_t>::max(),
Policy::max_id+1
};
var_data narrowest_var{ Policy::max_label + 1,
std::numeric_limits<size_t>::max(),
Policy::max_id + 1 };
};

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -1439,7 +1416,8 @@ namespace adiar::internal
__quantify__pred_profile(const typename Policy::dd_type& dd,
const predicate<typename Policy::label_type>& pred)
{
// TODO: tighten definition of 'shallow' and 'deep' variables based on widest level
// TODO: tighten 'shallow' to only be above shallowest widest level (inclusive)
// TODO: tighten 'deep' to not be 'shallow'

quantify__pred_profile<Policy> res;
res.dd_size = dd_nodecount(dd);
Expand All @@ -1449,14 +1427,14 @@ namespace adiar::internal
level_info_stream<true /* bottom-up */> lis(dd);

const size_t third_dd_size = res.dd_size / 3;
size_t nodes_below = 0u;
size_t nodes_below = 0u;

while (lis.can_pull()) {
const level_info li = lis.pull();
if (pred(li.label()) == Policy::quantify_onset) {
res.quant_all_vars += 1u;
res.quant_all_size += li.width();
res.quant_deep_vars += nodes_below + 1 <= third_dd_size;
res.quant_all_vars += 1u;
res.quant_all_size += li.width();
res.quant_deep_vars += nodes_below + 1 <= third_dd_size;
res.quant_shallow_vars += res.dd_size - third_dd_size <= nodes_below + li.width();

{ // Shallowest variable (always updated due to bottom-up direction).
Expand All @@ -1465,17 +1443,11 @@ namespace adiar::internal
res.shallowest_var.width = li.width();
}
// Deepest variable.
if (res.deepest_var.level < li.level()) {
res.deepest_var = res.shallowest_var;
}
if (res.deepest_var.level < li.level()) { res.deepest_var = res.shallowest_var; }
// Widest variable
if (res.widest_var.width < li.width()) {
res.widest_var = res.shallowest_var;
}
if (res.widest_var.width < li.width()) { res.widest_var = res.shallowest_var; }
// Narrowest variable
if (li.width() < res.narrowest_var.width) {
res.narrowest_var = res.shallowest_var;
}
if (li.width() < res.narrowest_var.width) { res.narrowest_var = res.shallowest_var; }
}

nodes_below += li.width();
Expand Down
17 changes: 5 additions & 12 deletions src/adiar/internal/algorithms/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ namespace adiar::internal
if (std::holds_alternative<typename Policy::node_type>(rec)) {
const node rec_node = std::get<typename Policy::node_type>(rec);

if constexpr (Policy::skip_reduce) {
output_changes |= rec_node != n;
}
if constexpr (Policy::skip_reduce) { output_changes |= rec_node != n; }

// Output/Forward outgoing arcs
__select_recurse_out(pq, aw, n.uid().as_ptr(false), rec_node.low());
Expand All @@ -155,9 +153,7 @@ namespace adiar::internal
const typename Policy::pointer_type rec_target =
std::get<typename Policy::pointer_type>(rec);

if constexpr (Policy::skip_reduce) {
output_changes = true;
}
if constexpr (Policy::skip_reduce) { output_changes = true; }

// Output/Forward extension of arc
while (pq.can_pull() && pq.top().target == n.uid()) {
Expand Down Expand Up @@ -222,22 +218,19 @@ namespace adiar::internal
#ifdef ADIAR_STATS
stats_select.lpq.unbucketed += 1u;
#endif
return __select<Policy,
select_priority_queue_t<0, memory_mode::Internal>>(
return __select<Policy, select_priority_queue_t<0, memory_mode::Internal>>(
ep, dd, policy, aux_available_memory, max_pq_size);
} else if (!external_only && max_pq_size <= pq_memory_fits) {
#ifdef ADIAR_STATS
stats_select.lpq.internal += 1u;
#endif
return __select<Policy,
select_priority_queue_t<ADIAR_LPQ_LOOKAHEAD, memory_mode::Internal>>(
return __select<Policy, select_priority_queue_t<ADIAR_LPQ_LOOKAHEAD, memory_mode::Internal>>(
ep, dd, policy, aux_available_memory, max_pq_size);
} else {
#ifdef ADIAR_STATS
stats_select.lpq.external += 1u;
#endif
return __select<Policy,
select_priority_queue_t<ADIAR_LPQ_LOOKAHEAD, memory_mode::External>>(
return __select<Policy, select_priority_queue_t<ADIAR_LPQ_LOOKAHEAD, memory_mode::External>>(
ep, dd, policy, aux_available_memory, max_pq_size);
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/adiar/zdd/subset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ namespace adiar

//////////////////////////////////////////////////////////////////////////////////////////////////
template <typename AssignmentPolicy>
class zdd_offset_policy : public zdd_policy, public AssignmentPolicy
class zdd_offset_policy
: public zdd_policy
, public AssignmentPolicy
{
public:
template <typename Arg>
zdd_offset_policy(const Arg &a)
zdd_offset_policy(const Arg& a)
: AssignmentPolicy(a)
{}

public:
internal::select_rec
process(const zdd::node_type& n)
{
if (AssignmentPolicy::current_matches()) {
return n.low();
}
if (AssignmentPolicy::current_matches()) { return n.low(); }
return n;
}

Expand Down Expand Up @@ -188,7 +188,9 @@ namespace adiar

//////////////////////////////////////////////////////////////////////////////////////////////////
template <typename AssignmentPolicy>
class zdd_onset_policy : public zdd_policy, public AssignmentPolicy
class zdd_onset_policy
: public zdd_policy
, public AssignmentPolicy
{
public:
template <typename Arg>
Expand All @@ -213,12 +215,15 @@ namespace adiar
if (AssignmentPolicy::has_level_incl()) {
// If recursion goes past the intended level, then it is replaced with
// the false terminal.
const zdd::pointer_type low = n.low().is_terminal() || n.low().label() > AssignmentPolicy::level_incl()
const zdd::pointer_type low =
n.low().is_terminal() || n.low().label() > AssignmentPolicy::level_incl()
? zdd::pointer_type(false)
: n.low();

// If this applies to high, then the node should be skipped entirely.
if (n.high().is_terminal() || n.high().label() > AssignmentPolicy::level_incl()) { return low; }
if (n.high().is_terminal() || n.high().label() > AssignmentPolicy::level_incl()) {
return low;
}
return zdd::node_type(n.uid(), low, n.high());
}
return n;
Expand Down
Loading

0 comments on commit 7b3579c

Please sign in to comment.