htd::ConstCollection<htd::id_t> htd::Graph::associatedEdgeIds(const htd::ConstCollection<htd::vertex_t> & elements) const { htd::VectorAdapter<htd::id_t> ret; if (elements.size() == 2) { auto & result = ret.container(); for (const htd::Hyperedge & edge : hyperedges()) { if (std::equal(edge.begin(), edge.end(), elements.begin())) { result.push_back(edge.id()); } } } return htd::ConstCollection<htd::id_t>::getInstance(ret); }
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; }
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())) { }
inline bool operator==(const htd::ConstCollection<T> & rhs) const { return size() == rhs.size() && std::equal(begin(), end(), rhs.begin()); }