Exemplo n.º 1
0
    std::vector<int> LevelInverseOrdering::computeVertexOrder(const InstancePtr& instance, const HTDDecompositionPtr& decomposition) const {
        const htd::ConstCollection<htd::vertex_t> vertices = instance->hypergraph->internalGraph().vertices();
        std::vector<htd::vertex_t> verticesSorted(vertices.begin(), vertices.end());

        std::sort(verticesSorted.begin(), verticesSorted.end(), [instance] (htd::vertex_t x1, htd::vertex_t x2) -> bool {
            int x1Level = htd::accessLabel<int>(instance->hypergraph->internalGraph().vertexLabel("level", x1));
            int x2Level = htd::accessLabel<int>(instance->hypergraph->internalGraph().vertexLabel("level", x2));
            if (x1Level > x2Level) {
                return true; // return true if x1 should be ordered before x2 (ie x1 level is greater than x2 level)
            } else if (x1Level == x2Level) {
                return (x1 < x2); // for same level, keep instance ordering
            }
            return false;
        });

        std::vector<int> orderingIndex(instance->hypergraph->vertexCount() + 1); // "0" vertex is skipped by HTD
        for (const auto& vertexId : instance->hypergraph->internalGraph().vertices()) {
            int index = std::find(verticesSorted.begin(), verticesSorted.end(), vertexId) - verticesSorted.begin();
            orderingIndex[vertexId] = index;
        }

        return orderingIndex;

    }
Exemplo n.º 2
0
htd::Hyperedge::Hyperedge(htd::id_t id, const htd::ConstCollection<htd::vertex_t> & elements) : written_(true), id_(id), elements_(std::make_shared<std::vector<htd::vertex_t>>(elements.begin(), elements.end()))
{

}