Skip to content

Commit

Permalink
Add indices for tuple pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelS239 committed Dec 8, 2024
1 parent 628f965 commit 4b97ba6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
38 changes: 24 additions & 14 deletions src/core/algorithms/dd/split/split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ unsigned Split::ReduceDDs(auto const& start_time) {
std::vector<DF> search, dfs_y;
std::list<DD> reduced;

std::vector<std::size_t> tuple_pair_indices;
if (reduce_method_ == +Reduce::IEHybrid) {
tuple_pair_indices = std::vector<std::size_t>(tuple_pair_num_);
for (std::size_t i = 0; i < tuple_pair_num_; i++) {
tuple_pair_indices[i] = i;
}
}

for (model::ColumnIndex index = 0; index < num_columns_; index++) {
std::vector<model::ColumnIndex> indices;
for (model::ColumnIndex j = 0; j < num_columns_; j++) {
Expand Down Expand Up @@ -203,7 +211,7 @@ unsigned Split::ReduceDDs(auto const& start_time) {
reduced = HybridPruningReduce(df_y, search, cnt);
break;
case +Reduce::IEHybrid:
reduced = InstanceExclusionReduce(tuple_pairs_, search, df_y, cnt);
reduced = InstanceExclusionReduce(tuple_pair_indices, search, df_y, cnt);
break;
default:
break;
Expand Down Expand Up @@ -327,6 +335,7 @@ void Split::CalculateTuplePairs() {
}
}
}
tuple_pair_num_ = tuple_pairs_.size();
}

double Split::CalculateDistance(model::ColumnIndex column_index,
Expand Down Expand Up @@ -659,34 +668,35 @@ std::list<DD> Split::HybridPruningReduce(DF const& rhs, std::vector<DF> const& s
return dds;
}

std::list<DD> Split::InstanceExclusionReduce(
std::vector<std::pair<std::size_t, std::size_t>> const& tuple_pairs,
std::vector<DF> const& search, DF const& rhs, unsigned& cnt) {
std::list<DD> Split::InstanceExclusionReduce(std::vector<std::size_t> const& tuple_pair_indices,
std::vector<DF> const& search, DF const& rhs,
unsigned& cnt) {
if (!search.size()) return {};

std::list<DD> dds;
DF const first_df = search.front();
DF const last_df = search.back();
std::vector<std::pair<std::size_t, std::size_t>> remaining_tuple_pairs;
std::vector<std::size_t> remaining_tuple_pair_indices;

cnt++;
bool last_dd_holds = true;
bool no_pairs_left = true;
for (auto pair : tuple_pairs) {
if (!CheckDF(rhs, pair)) {
if (CheckDF(first_df, pair)) {
remaining_tuple_pairs.push_back(pair);
for (auto index : tuple_pair_indices) {
if (!CheckDF(rhs, tuple_pairs_[index])) {
if (CheckDF(first_df, tuple_pairs_[index])) {
remaining_tuple_pair_indices.push_back(index);
no_pairs_left = false;
}
if (last_dd_holds && CheckDF(last_df, pair)) last_dd_holds = false;
if (last_dd_holds && CheckDF(last_df, tuple_pairs_[index])) last_dd_holds = false;
if (!no_pairs_left && !last_dd_holds) break;
}
}

if (no_pairs_left) {
if (IsFeasible(first_df)) dds.emplace_back(first_df, rhs);
std::vector<DF> remainder = DoPositivePruning(search, first_df);
std::list<DD> remaining_dds = InstanceExclusionReduce(tuple_pairs, remainder, rhs, cnt);
std::list<DD> remaining_dds =
InstanceExclusionReduce(tuple_pair_indices, remainder, rhs, cnt);
dds.splice(dds.end(), remaining_dds);
return dds;
}
Expand All @@ -695,14 +705,14 @@ std::list<DD> Split::InstanceExclusionReduce(

if (!last_dd_holds) {
std::vector<DF> remainder = DoNegativePruning(search, last_df);
return InstanceExclusionReduce(tuple_pairs, remainder, rhs, cnt);
return InstanceExclusionReduce(tuple_pair_indices, remainder, rhs, cnt);
}

auto const [prune, remainder] = PositiveSplit(search, first_df);

dds = InstanceExclusionReduce(tuple_pairs, remainder, rhs, cnt);
dds = InstanceExclusionReduce(tuple_pair_indices, remainder, rhs, cnt);
std::list<DD> const pruning_dds =
InstanceExclusionReduce(remaining_tuple_pairs, prune, rhs, cnt);
InstanceExclusionReduce(remaining_tuple_pair_indices, prune, rhs, cnt);

std::list<DD> merged_dds = MergeReducedResults(dds, pruning_dds);
dds.splice(dds.end(), merged_dds);
Expand Down
7 changes: 4 additions & 3 deletions src/core/algorithms/dd/split/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Split : public Algorithm {
unsigned num_rows_;
model::ColumnIndex num_columns_;
std::vector<model::ColumnIndex> non_empty_cols_;
std::size_t tuple_pair_num_;

std::vector<model::TypeId> type_ids_;

Expand Down Expand Up @@ -87,9 +88,9 @@ class Split : public Algorithm {
std::list<DD> NegativePruningReduce(DF const& rhs, std::vector<DF> const& search,
unsigned& cnt);
std::list<DD> HybridPruningReduce(DF const& rhs, std::vector<DF> const& search, unsigned& cnt);
std::list<DD> InstanceExclusionReduce(
std::vector<std::pair<std::size_t, std::size_t>> const& tuple_pairs,
std::vector<DF> const& search, DF const& rhs, unsigned& cnt);
std::list<DD> InstanceExclusionReduce(std::vector<std::size_t> const& tuple_pair_indices,
std::vector<DF> const& search, DF const& rhs,
unsigned& cnt);
unsigned ReduceDDs(auto const& start_time);
unsigned RemoveRedundantDDs();
unsigned RemoveTransitiveDDs();
Expand Down

0 comments on commit 4b97ba6

Please sign in to comment.