Skip to content

Adding elements to the generator component

Dominik Drexler edited this page Jun 14, 2021 · 6 revisions

Introduction

The generator component is capable of automatically generating features by exhaustively stacking the elements of the core components. The generator accepts a set of states such that newly generated features are pruned if its state evaluations are identical to those of a feature that was generated before. Adding new features to the generator is a simple two-step procedure.

Step 1: Adding a generator function

// src/generator/feature_generator.h
private:
    void generate_equal_boolean(const States& states, int iteration, FeatureCollection& feature_collection);
// src/generator/feature_generator.cpp
void FeatureGenerator::generate_equal_boolean(const States& states, int iteration, FeatureCollection& feature_collection) {
    for (int i = 1; i < iteration; ++i) {
        int j = iteration - i;
        assert(i + j == iteration);
        assert(i >= 1 && j >= 1);
        int indices[2] = {i, j};
        std::sort(indices, indices+2);
        do {
            for (const auto& boolean_left : m_boolean_elements_by_complexity[indices[0]]) {
                for (const auto& boolean_right : m_boolean_elements_by_complexity[indices[1]]) {
                    if (!m_timer.is_expired()) 
                        add_boolean(states, m_factory->make_equal_boolean(boolean_left, boolean_right), feature_collection);
                }
            }
        } while (std::next_permutation(indices, indices+2));
        // Add construction of role pairs here
        // ...
    }
}

Step 2: Adding the generator function to the loop

// src/generator/feature_generator.cpp
void FeatureGenerator::generate_inductively(const States& states, FeatureCollection& feature_collection) {
    for (int i = 1; i < iteration; ++i) {
        // ...
        generate_equal_boolean(states, iteration, feature_collection);
        // ...
    }
}

Clone this wiki locally