Skip to content

Commit

Permalink
problem fixed (cannot use virtual functions in constructors)
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonZChen committed Jan 18, 2025
1 parent b9db524 commit a0ea3f6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 16 deletions.
1 change: 0 additions & 1 deletion include/feature_generation/feature_generators/kwl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace feature_generation {
Embedding embed(const std::shared_ptr<graph::Graph> &graph) override;

protected:
void init_neighbour_container() override;
inline int get_initial_colour(int index,
int u,
int v,
Expand Down
1 change: 0 additions & 1 deletion include/feature_generation/feature_generators/wl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace feature_generation {
Embedding embed(const std::shared_ptr<graph::Graph> &graph) override;

protected:
void init_neighbour_container() override;
void collect_impl(const std::vector<graph::Graph> &graphs) override;
void refine(const std::shared_ptr<graph::Graph> &graph,
std::vector<int> &colours,
Expand Down
3 changes: 0 additions & 3 deletions include/feature_generation/features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ namespace feature_generation {
// common init for initialisation and loading from file
void initialise_variables();

// neighbour container initialisation depends on feature generator
virtual void init_neighbour_container() = 0;

// main collection body
virtual void collect_impl(const std::vector<graph::Graph> &graphs) = 0;

Expand Down
4 changes: 0 additions & 4 deletions src/feature_generation/feature_generators/kwl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ namespace feature_generation {

KWL2Features::KWL2Features(const std::string &filename) : Features(filename) {}

void KWL2Features::init_neighbour_container() {
std::cout << "error: KWL2Features neighbour container not implemented yet" << std::endl;
}

int kwl2_pair_to_index_map(int n, int i, int j) {
// map pair where 0 <= i, j < n to vec index
return i * n + j;
Expand Down
5 changes: 0 additions & 5 deletions src/feature_generation/feature_generators/wl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../../../include/feature_generation/feature_generators/wl.hpp"

#include "../../../include/feature_generation/neighbour_containers/wl_neighbour_container.hpp"
#include "../../../include/graph/graph_generator_factory.hpp"
#include "../../../include/utils/nlohmann/json.hpp"

Expand Down Expand Up @@ -28,10 +27,6 @@ namespace feature_generation {

WLFeatures::WLFeatures(const std::string &filename) : Features(filename) {}

void WLFeatures::init_neighbour_container() {
neighbour_container = std::make_shared<WLNeighbourContainer>(multiset_hash);
}

void WLFeatures::refine(const std::shared_ptr<graph::Graph> &graph,
std::vector<int> &colours,
std::vector<int> &colours_tmp,
Expand Down
12 changes: 10 additions & 2 deletions src/feature_generation/features.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../../include/feature_generation/features.hpp"

#include "../../include/feature_generation/maxsat.hpp"
#include "../../include/feature_generation/neighbour_containers/wl_neighbour_container.hpp"
#include "../../include/graph/graph_generator_factory.hpp"
#include "../../include/utils/nlohmann/json.hpp"

Expand Down Expand Up @@ -43,11 +44,18 @@ namespace feature_generation {
graph_generator = graph::create_graph_generator(graph_representation, *domain);
seen_colour_statistics =
std::vector<std::vector<long>>(2, std::vector<long>(iterations + 1, 0));
init_neighbour_container();

// We use a factory style method here instead of a virtual function as this is called
// from a constructor, from which virtual functions are not allowed to be called.
if (std::set<std::string>({"wl", "ccwl", "iwl", "niwl"}).count(feature_name)) {
neighbour_container = std::make_shared<WLNeighbourContainer>(multiset_hash);
} else {
std::cout << "error: neighbour container not yet implemented for feature_name="
<< feature_name << std::endl;
}
}

std::vector<std::set<int>> Features::new_layer_to_colours() const {
// plus 1 because zeroth iteration is also included
return std::vector<std::set<int>>(iterations + 1, std::set<int>());
}

Expand Down

0 comments on commit a0ea3f6

Please sign in to comment.