| 1 | /** \file |
| 2 | * \brief Tests for several layered layout algorithms. |
| 3 | * |
| 4 | * \author Tilo Wiedera |
| 5 | * |
| 6 | * \par License: |
| 7 | * This file is part of the Open Graph Drawing Framework (OGDF). |
| 8 | * |
| 9 | * \par |
| 10 | * Copyright (C)<br> |
| 11 | * See README.md in the OGDF root directory for details. |
| 12 | * |
| 13 | * \par |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * Version 2 or 3 as published by the Free Software Foundation; |
| 17 | * see the file LICENSE.txt included in the packaging of this file |
| 18 | * for details. |
| 19 | * |
| 20 | * \par |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * \par |
| 27 | * You should have received a copy of the GNU General Public |
| 28 | * License along with this program; if not, see |
| 29 | * http://www.gnu.org/copyleft/gpl.html |
| 30 | */ |
| 31 | |
| 32 | #include <ogdf/layered/BlockOrder.h> |
| 33 | #include <ogdf/layered/FastHierarchyLayout.h> |
| 34 | #include <ogdf/layered/FastSimpleHierarchyLayout.h> |
| 35 | #include <ogdf/layered/HierarchyLevels.h> |
| 36 | #include <ogdf/layered/OptimalHierarchyLayout.h> |
| 37 | |
| 38 | #include "layout_helpers.h" |
| 39 | |
| 40 | #define TEST_HIERARCHY_LAYOUT(TYPE, SKIP, ...) describeHierarchyLayout<TYPE>(#TYPE, SKIP, {__VA_ARGS__}) |
| 41 | |
| 42 | template<class Layout, class Levels> |
| 43 | class HierarchyMock : public LayoutModule { |
| 44 | Layout layout; |
| 45 | |
| 46 | public: |
| 47 | virtual void call(GraphAttributes &attr) override { |
| 48 | const Graph& G = attr.constGraph(); |
| 49 | NodeArray<int> nodeRank(G); |
| 50 | |
| 51 | int numberOfRanks = sqrt(G.numberOfNodes()); |
| 52 | |
| 53 | int i = 0; |
| 54 | for(node v : G.nodes) { |
| 55 | // each rank must contain at least one node |
| 56 | nodeRank[v] = i < numberOfRanks ? i++ : randomNumber(0, numberOfRanks); |
| 57 | } |
| 58 | |
| 59 | Hierarchy hierarchy(G, nodeRank); |
| 60 | Levels levels(hierarchy); |
| 61 | layout.call(levels, attr); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | template<class Layout> |
| 66 | void describeHierarchyLayout(const string& name, bool skipMe, std::initializer_list<GraphProperty> requirements) { |
| 67 | std::set<GraphProperty> reqs(requirements); |
| 68 | reqs.insert(GraphProperty::sparse); |
| 69 | // TODO BlockOrder is infested by bugs. It is skipped for now. |
| 70 | describeLayout<HierarchyMock<Layout, BlockOrder>>(name + " with BlockOrder" , 0, reqs, false, GraphSizes(), true); |
| 71 | describeLayout<HierarchyMock<Layout, HierarchyLevels>>(name + " with HierarchyLevels" , 0, reqs, false, GraphSizes(), skipMe); |
| 72 | } |
| 73 | |
| 74 | go_bandit([] { describe("Layered layouts" , [] { |
| 75 | TEST_HIERARCHY_LAYOUT(FastHierarchyLayout, false); |
| 76 | TEST_HIERARCHY_LAYOUT(FastSimpleHierarchyLayout, false); |
| 77 | TEST_HIERARCHY_LAYOUT(OptimalHierarchyLayout, false, GraphProperty::simple); |
| 78 | }); }); |
| 79 | |