[906] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
[1956] | 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[906] | 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 | |
---|
[483] | 19 | #include <iostream> |
---|
| 20 | |
---|
[921] | 21 | #include <lemon/maps.h> |
---|
| 22 | #include <lemon/unionfind.h> |
---|
[774] | 23 | #include "test_tools.h" |
---|
[483] | 24 | |
---|
[921] | 25 | using namespace lemon; |
---|
[483] | 26 | using namespace std; |
---|
| 27 | |
---|
[2205] | 28 | typedef UnionFindEnum<int, StdMap<int, int> > UFE; |
---|
[483] | 29 | |
---|
| 30 | void print(UFE const &ufe) { |
---|
[774] | 31 | cout << "Print the classes of the structure:" << endl; |
---|
[483] | 32 | int i = 1; |
---|
[2205] | 33 | for (UFE::ClassIt cit(ufe); cit != INVALID; ++cit) { |
---|
[483] | 34 | cout << " " << i << " (" << cit << "):" << flush; |
---|
[2205] | 35 | for (UFE::ItemIt iit(ufe, cit); iit != INVALID; ++iit) { |
---|
[483] | 36 | cout << " " << iit << flush; |
---|
| 37 | } |
---|
| 38 | cout << endl; |
---|
| 39 | i++; |
---|
| 40 | } |
---|
| 41 | cout << "done" << endl; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | int main() { |
---|
[2205] | 46 | StdMap<int, int> base; |
---|
[483] | 47 | UFE U(base); |
---|
| 48 | |
---|
[1569] | 49 | U.insert(1); |
---|
| 50 | U.insert(2); |
---|
[483] | 51 | |
---|
[774] | 52 | check(U.join(1,2),"Test failed."); |
---|
[483] | 53 | |
---|
| 54 | U.insert(3); |
---|
| 55 | U.insert(4); |
---|
| 56 | U.insert(5); |
---|
| 57 | U.insert(6); |
---|
| 58 | U.insert(7); |
---|
| 59 | |
---|
[774] | 60 | check(U.join(1,4),"Test failed."); |
---|
| 61 | check(!U.join(2,4),"Test failed."); |
---|
| 62 | check(U.join(3,5),"Test failed."); |
---|
[483] | 63 | |
---|
| 64 | U.insert(8,5); |
---|
| 65 | |
---|
[774] | 66 | check(U.size(4) == 3,"Test failed."); |
---|
| 67 | check(U.size(5) == 3,"Test failed."); |
---|
| 68 | check(U.size(6) == 1,"Test failed."); |
---|
| 69 | check(U.size(2) == 3,"Test failed."); |
---|
[483] | 70 | |
---|
| 71 | U.insert(9); |
---|
| 72 | U.insert(10,9); |
---|
[2205] | 73 | |
---|
[1569] | 74 | check(U.join(8,10),"Test failed."); |
---|
[483] | 75 | |
---|
[1569] | 76 | check(U.move(9,4),"Test failed."); |
---|
| 77 | check(!U.move(9,2),"Test failed."); |
---|
[483] | 78 | |
---|
[1569] | 79 | check(U.size(4) == 4,"Test failed."); |
---|
| 80 | check(U.size(9) == 4,"Test failed."); |
---|
[483] | 81 | |
---|
[1569] | 82 | check(U.move(5,6),"Test failed."); |
---|
[483] | 83 | |
---|
[774] | 84 | check(U.size(5) == 2,"Test failed."); |
---|
| 85 | check(U.size(8) == 3,"Test failed."); |
---|
[483] | 86 | |
---|
[774] | 87 | check(U.move(7,10),"Test failed."); |
---|
| 88 | check(U.size(7) == 4,"Test failed."); |
---|
[483] | 89 | |
---|
| 90 | U.erase(9); |
---|
[1569] | 91 | U.erase(1); |
---|
[483] | 92 | |
---|
[774] | 93 | check(U.size(4) == 2,"Test failed."); |
---|
| 94 | check(U.size(2) == 2,"Test failed."); |
---|
[483] | 95 | |
---|
[1569] | 96 | U.erase(6); |
---|
| 97 | U.split(8); |
---|
[483] | 98 | |
---|
[774] | 99 | check(U.size(4) == 2,"Test failed."); |
---|
| 100 | check(U.size(3) == 1,"Test failed."); |
---|
| 101 | check(U.size(2) == 2,"Test failed."); |
---|
[483] | 102 | |
---|
[774] | 103 | check(U.join(3,4),"Test failed."); |
---|
| 104 | check(!U.join(2,4),"Test failed."); |
---|
[483] | 105 | |
---|
[774] | 106 | check(U.size(4) == 3,"Test failed."); |
---|
| 107 | check(U.size(3) == 3,"Test failed."); |
---|
| 108 | check(U.size(2) == 3,"Test failed."); |
---|
[483] | 109 | |
---|
| 110 | U.makeRep(4); |
---|
| 111 | U.makeRep(3); |
---|
| 112 | U.makeRep(2); |
---|
| 113 | |
---|
[774] | 114 | check(U.size(4) == 3,"Test failed."); |
---|
| 115 | check(U.size(3) == 3,"Test failed."); |
---|
| 116 | check(U.size(2) == 3,"Test failed."); |
---|
[483] | 117 | |
---|
| 118 | |
---|
| 119 | U.eraseClass(4); |
---|
[1569] | 120 | U.eraseClass(7); |
---|
[483] | 121 | |
---|
| 122 | } |
---|