Esempio n. 1
0
    void add_node(std::size_t node)
    {
        std::size_t new_count = nodes_count() + 1;
        auto index  = [=](std::size_t i, std::size_t j){return i*nodes_count() + j;};
        auto index_new = [=](std::size_t i, std::size_t j){return i*new_count + j;};

        if(new_count* new_count < _matrix.size())
            _matrix.resize(new_count*new_count);

        std::size_t end = node >= nodes_count() ? node + 1 : nodes_count();

        for(std::size_t i = node; i < end; ++i)
        {
            for(std::size_t j = node; j < end; ++j)
            {
                std::size_t x = (i <= node) ? i : i - 1;
                std::size_t y = (j <= node) ? j : j - 1;

                if(i == node || j == node)
                    _matrix[index_new(i,j)] = false;
                else if(i > node || j > node)
                    _matrix[index_new(i,j)] = _matrix[index(x,y)];
            }
        }

        _nodes_count = new_count;
    }
Esempio n. 2
0
void Individual::repairSuccessorsOfNode(size_t layer_idx, size_t node_idx) {

    auto original_node = nodes[layer_idx][node_idx];

    // Loop on higher layers looking for successors.
    for(auto i = layer_idx + 1; i < MAX_NB_LAYER; i++) {

        auto j = 0;
        auto current_node_count = 0;
        auto local_node_count = nodes_count(i);

        while (current_node_count < local_node_count &&
                j < MAX_NB_NODE_PER_LAYER) {

            auto current_node = nodes[i][j];

            if (current_node.activated) {
                ++current_node_count;

                for (auto k = 0; k < MAX_NB_PREDECESSORS; ++k) {
                    if (current_node.pred[k].x == layer_idx &&
                        current_node.pred[k].y == node_idx) {

                        current_node.pred[k] = original_node.pred[rand() % 2];
                    }
                }
            }
            j++;
        }
    }
}
Esempio n. 3
0
    auto edges() const
    {
        auto begin = [this](std::size_t i) -> std::size_t
        {
            return directed() ? 0u : i;
        };

        return ranges::view::for_each(ranges::view::iota(0u, nodes_count() - 1), [=](std::size_t i)
        {
            std::size_t b = begin(i);

            return ranges::view::for_each(ranges::view::iota(b, nodes_count() - 1), [=](std::size_t j)
            {
                return ranges::yield_if((*this)(i,j), std::make_pair(i, j));
            });
        });
    }
Esempio n. 4
0
 auto nodes()
 {
     return ranges::view::iota(0, nodes_count()-1) |
     ranges::view::transform([this](std::size_t i) -> node_t&
     {
        return (*this)(i);
     });
 }
Esempio n. 5
0
bool Individual::addNode(Node node, size_t layer_index) {

    size_t nb_nodes_in_layer = nodes_count(layer_index);

    // If the layer is not full
    if (nb_nodes_in_layer < MAX_NB_NODE_PER_LAYER) { 

        size_t node_index = firstFreeSlotOfLayer(layer_index);

        nodes[layer_index][node_index] = Node(node); //Node(node);

        nodes_count_[layer_index] += 1;

        if (layer_index > current_layer || current_layer == -1) {
            current_layer = layer_index;
        }
        return true;
    }
    else {
        return false;
    }
}
Esempio n. 6
0
 bool at(std::size_t i, std::size_t j) const {
     if (i < nodes_count() && j < nodes_count())
         return (*this)(i, j);
     else
         throw std::out_of_range{"adjacency_matrix::at(i,j): Index out of range"};
 }
Esempio n. 7
0
 node_proxy operator()(std::size_t i, std::size_t j) noexcept {
     assert(i < nodes_count() && j < nodes_count());
     return {this, i, j};
 }
Esempio n. 8
0
 bool operator()(std::size_t i, std::size_t j) const noexcept {
     assert(i < nodes_count() && j < nodes_count());
     return _at(i,j);
 }
Esempio n. 9
0
 void add_node(Args&&... args)
 {
     _nodes.emplace_back(nodes_count(), std::forward<Args>(args)...);
     _matrix.add_node();
 }
Esempio n. 10
0
 std::size_t _index_from_coords(std::size_t i, std::size_t j) const
 {
     return i * nodes_count() + j;
 }
Esempio n. 11
0
 auto _column_indices(std::size_t column) const
 {
     return ranges::view::iota(0u, nodes_count() - 1) |
            ranges::view::transform([=](std::size_t i){ return nodes_count() * i + column; });
 }
Esempio n. 12
0
 auto _row_indices(std::size_t row) const
 {
     return ranges::view::iota(0u, nodes_count() - 1) |
            ranges::view::transform([=](std::size_t i){ return nodes_count() * row + i; });
 }
Esempio n. 13
0
 void add_node()
 {
     add_node(nodes_count());
 }
Esempio n. 14
0
 auto neighbors(std::size_t node)
 {
     return ranges::view::iota(0u, nodes_count() - 1) |
            ranges::view::remove_if([=](int i){ return !_at(node, i); });
 }