[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[57] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[57] | 4 | * |
---|
[107] | 5 | * Copyright (C) 2003-2008 |
---|
[57] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <lemon/concepts/digraph.h> |
---|
| 20 | #include <lemon/list_graph.h> |
---|
[171] | 21 | #include <lemon/smart_graph.h> |
---|
[57] | 22 | //#include <lemon/full_graph.h> |
---|
| 23 | //#include <lemon/hypercube_graph.h> |
---|
| 24 | |
---|
| 25 | #include "test_tools.h" |
---|
[171] | 26 | #include "graph_test.h" |
---|
[57] | 27 | |
---|
| 28 | using namespace lemon; |
---|
| 29 | using namespace lemon::concepts; |
---|
| 30 | |
---|
[228] | 31 | template <class Digraph> |
---|
| 32 | void checkDigraph() { |
---|
| 33 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 34 | Digraph G; |
---|
| 35 | |
---|
| 36 | checkGraphNodeList(G, 0); |
---|
| 37 | checkGraphArcList(G, 0); |
---|
| 38 | |
---|
| 39 | Node |
---|
| 40 | n1 = G.addNode(), |
---|
| 41 | n2 = G.addNode(), |
---|
| 42 | n3 = G.addNode(); |
---|
| 43 | checkGraphNodeList(G, 3); |
---|
| 44 | checkGraphArcList(G, 0); |
---|
| 45 | |
---|
| 46 | Arc a1 = G.addArc(n1, n2); |
---|
| 47 | check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc"); |
---|
| 48 | checkGraphNodeList(G, 3); |
---|
| 49 | checkGraphArcList(G, 1); |
---|
| 50 | |
---|
| 51 | checkGraphOutArcList(G, n1, 1); |
---|
| 52 | checkGraphOutArcList(G, n2, 0); |
---|
| 53 | checkGraphOutArcList(G, n3, 0); |
---|
| 54 | |
---|
| 55 | checkGraphInArcList(G, n1, 0); |
---|
| 56 | checkGraphInArcList(G, n2, 1); |
---|
| 57 | checkGraphInArcList(G, n3, 0); |
---|
| 58 | |
---|
| 59 | checkGraphConArcList(G, 1); |
---|
| 60 | |
---|
| 61 | Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); |
---|
| 62 | checkGraphNodeList(G, 3); |
---|
| 63 | checkGraphArcList(G, 4); |
---|
| 64 | |
---|
| 65 | checkGraphOutArcList(G, n1, 1); |
---|
| 66 | checkGraphOutArcList(G, n2, 3); |
---|
| 67 | checkGraphOutArcList(G, n3, 0); |
---|
| 68 | |
---|
| 69 | checkGraphInArcList(G, n1, 1); |
---|
| 70 | checkGraphInArcList(G, n2, 1); |
---|
| 71 | checkGraphInArcList(G, n3, 2); |
---|
| 72 | |
---|
| 73 | checkGraphConArcList(G, 4); |
---|
| 74 | |
---|
| 75 | checkNodeIds(G); |
---|
| 76 | checkArcIds(G); |
---|
| 77 | checkGraphNodeMap(G); |
---|
| 78 | checkGraphArcMap(G); |
---|
| 79 | |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | void checkConcepts() { |
---|
[171] | 84 | { // Checking digraph components |
---|
[57] | 85 | checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
---|
| 86 | |
---|
[209] | 87 | checkConcept<IDableDigraphComponent<>, |
---|
[57] | 88 | IDableDigraphComponent<> >(); |
---|
| 89 | |
---|
[209] | 90 | checkConcept<IterableDigraphComponent<>, |
---|
[57] | 91 | IterableDigraphComponent<> >(); |
---|
| 92 | |
---|
[209] | 93 | checkConcept<MappableDigraphComponent<>, |
---|
[57] | 94 | MappableDigraphComponent<> >(); |
---|
| 95 | } |
---|
[171] | 96 | { // Checking skeleton digraph |
---|
[57] | 97 | checkConcept<Digraph, Digraph>(); |
---|
| 98 | } |
---|
[171] | 99 | { // Checking ListDigraph |
---|
| 100 | checkConcept<Digraph, ListDigraph>(); |
---|
[57] | 101 | checkConcept<AlterableDigraphComponent<>, ListDigraph>(); |
---|
| 102 | checkConcept<ExtendableDigraphComponent<>, ListDigraph>(); |
---|
| 103 | checkConcept<ClearableDigraphComponent<>, ListDigraph>(); |
---|
| 104 | checkConcept<ErasableDigraphComponent<>, ListDigraph>(); |
---|
[171] | 105 | } |
---|
| 106 | { // Checking SmartDigraph |
---|
| 107 | checkConcept<Digraph, SmartDigraph>(); |
---|
| 108 | checkConcept<AlterableDigraphComponent<>, SmartDigraph>(); |
---|
| 109 | checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
---|
| 110 | checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
---|
| 111 | } |
---|
| 112 | // { // Checking FullDigraph |
---|
| 113 | // checkConcept<Digraph, FullDigraph>(); |
---|
| 114 | // } |
---|
| 115 | // { // Checking HyperCubeDigraph |
---|
| 116 | // checkConcept<Digraph, HyperCubeDigraph>(); |
---|
| 117 | // } |
---|
| 118 | } |
---|
[57] | 119 | |
---|
[171] | 120 | template <typename Digraph> |
---|
[228] | 121 | void checkDigraphValidity() { |
---|
[171] | 122 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 123 | Digraph g; |
---|
| 124 | |
---|
| 125 | Node |
---|
| 126 | n1 = g.addNode(), |
---|
| 127 | n2 = g.addNode(), |
---|
| 128 | n3 = g.addNode(); |
---|
| 129 | |
---|
| 130 | Arc |
---|
| 131 | e1 = g.addArc(n1, n2), |
---|
| 132 | e2 = g.addArc(n2, n3); |
---|
| 133 | |
---|
| 134 | check(g.valid(n1), "Wrong validity check"); |
---|
| 135 | check(g.valid(e1), "Wrong validity check"); |
---|
| 136 | |
---|
| 137 | check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
---|
| 138 | check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | template <typename Digraph> |
---|
[228] | 142 | void checkDigraphValidityErase() { |
---|
[171] | 143 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 144 | Digraph g; |
---|
| 145 | |
---|
| 146 | Node |
---|
| 147 | n1 = g.addNode(), |
---|
| 148 | n2 = g.addNode(), |
---|
| 149 | n3 = g.addNode(); |
---|
| 150 | |
---|
| 151 | Arc |
---|
| 152 | e1 = g.addArc(n1, n2), |
---|
| 153 | e2 = g.addArc(n2, n3); |
---|
| 154 | |
---|
| 155 | check(g.valid(n1), "Wrong validity check"); |
---|
| 156 | check(g.valid(e1), "Wrong validity check"); |
---|
| 157 | |
---|
| 158 | g.erase(n1); |
---|
| 159 | |
---|
| 160 | check(!g.valid(n1), "Wrong validity check"); |
---|
| 161 | check(g.valid(n2), "Wrong validity check"); |
---|
| 162 | check(g.valid(n3), "Wrong validity check"); |
---|
| 163 | check(!g.valid(e1), "Wrong validity check"); |
---|
| 164 | check(g.valid(e2), "Wrong validity check"); |
---|
| 165 | |
---|
| 166 | check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
---|
| 167 | check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
---|
| 168 | } |
---|
| 169 | |
---|
[228] | 170 | void checkDigraphs() { |
---|
[171] | 171 | { // Checking ListDigraph |
---|
[57] | 172 | checkDigraph<ListDigraph>(); |
---|
[228] | 173 | checkDigraphValidityErase<ListDigraph>(); |
---|
[57] | 174 | } |
---|
[171] | 175 | { // Checking SmartDigraph |
---|
| 176 | checkDigraph<SmartDigraph>(); |
---|
[228] | 177 | checkDigraphValidity<SmartDigraph>(); |
---|
[171] | 178 | } |
---|
| 179 | } |
---|
[57] | 180 | |
---|
[171] | 181 | int main() { |
---|
[228] | 182 | checkDigraphs(); |
---|
| 183 | checkConcepts(); |
---|
[57] | 184 | return 0; |
---|
| 185 | } |
---|