equal
deleted
inserted
replaced
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 * |
2 * |
3 * This file is a part of LEMON, a generic C++ optimization library. |
3 * This file is a part of LEMON, a generic C++ optimization library. |
4 * |
4 * |
5 * Copyright (C) 2003-2010 |
5 * Copyright (C) 2003-2013 |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 * |
8 * |
9 * Permission to use, modify and distribute this software is granted |
9 * Permission to use, modify and distribute this software is granted |
10 * provided that this copyright notice appears in all copies. For |
10 * provided that this copyright notice appears in all copies. For |
52 "4 6 11\n" |
52 "4 6 11\n" |
53 "4 7 12\n" |
53 "4 7 12\n" |
54 "5 6 13\n" |
54 "5 6 13\n" |
55 "5 7 14\n" |
55 "5 7 14\n" |
56 "6 7 15\n"; |
56 "6 7 15\n"; |
57 |
57 |
58 |
58 |
59 // Check with general graphs |
59 // Check with general graphs |
60 template <typename Param> |
60 template <typename Param> |
61 void checkMaxCliqueGeneral(Param rule) { |
61 void checkMaxCliqueGeneral(Param rule) { |
62 typedef ListGraph GR; |
62 typedef ListGraph GR; |
63 typedef GrossoLocatelliPullanMc<GR> McAlg; |
63 typedef GrossoLocatelliPullanMc<GR> McAlg; |
64 typedef McAlg::CliqueNodeIt CliqueIt; |
64 typedef McAlg::CliqueNodeIt CliqueIt; |
65 |
65 |
66 // Basic tests |
66 // Basic tests |
67 { |
67 { |
68 GR g; |
68 GR g; |
69 GR::NodeMap<bool> map(g); |
69 GR::NodeMap<bool> map(g); |
70 McAlg mc(g); |
70 McAlg mc(g); |
79 mc.cliqueMap(map); |
79 mc.cliqueMap(map); |
80 check(map[u], "Wrong clique map"); |
80 check(map[u], "Wrong clique map"); |
81 CliqueIt it1(mc); |
81 CliqueIt it1(mc); |
82 check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID, |
82 check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID, |
83 "Wrong CliqueNodeIt"); |
83 "Wrong CliqueNodeIt"); |
84 |
84 |
85 GR::Node v = g.addNode(); |
85 GR::Node v = g.addNode(); |
86 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
86 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
87 check(mc.cliqueSize() == 1, "Wrong clique size"); |
87 check(mc.cliqueSize() == 1, "Wrong clique size"); |
88 mc.cliqueMap(map); |
88 mc.cliqueMap(map); |
89 check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map"); |
89 check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map"); |
107 GR::NodeMap<bool> map(g); |
107 GR::NodeMap<bool> map(g); |
108 std::istringstream input(test_lgf); |
108 std::istringstream input(test_lgf); |
109 graphReader(g, input) |
109 graphReader(g, input) |
110 .nodeMap("max_clique", max_clique) |
110 .nodeMap("max_clique", max_clique) |
111 .run(); |
111 .run(); |
112 |
112 |
113 McAlg mc(g); |
113 McAlg mc(g); |
114 mc.iterationLimit(50); |
114 mc.iterationLimit(50); |
115 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
115 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
116 check(mc.cliqueSize() == 4, "Wrong clique size"); |
116 check(mc.cliqueSize() == 4, "Wrong clique size"); |
117 mc.cliqueMap(map); |
117 mc.cliqueMap(map); |
131 template <typename Param> |
131 template <typename Param> |
132 void checkMaxCliqueFullGraph(Param rule) { |
132 void checkMaxCliqueFullGraph(Param rule) { |
133 typedef FullGraph GR; |
133 typedef FullGraph GR; |
134 typedef GrossoLocatelliPullanMc<FullGraph> McAlg; |
134 typedef GrossoLocatelliPullanMc<FullGraph> McAlg; |
135 typedef McAlg::CliqueNodeIt CliqueIt; |
135 typedef McAlg::CliqueNodeIt CliqueIt; |
136 |
136 |
137 for (int size = 0; size <= 40; size = size * 3 + 1) { |
137 for (int size = 0; size <= 40; size = size * 3 + 1) { |
138 GR g(size); |
138 GR g(size); |
139 GR::NodeMap<bool> map(g); |
139 GR::NodeMap<bool> map(g); |
140 McAlg mc(g); |
140 McAlg mc(g); |
141 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
141 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
154 template <typename Param> |
154 template <typename Param> |
155 void checkMaxCliqueGridGraph(Param rule) { |
155 void checkMaxCliqueGridGraph(Param rule) { |
156 GridGraph g(5, 7); |
156 GridGraph g(5, 7); |
157 GridGraph::NodeMap<char> map(g); |
157 GridGraph::NodeMap<char> map(g); |
158 GrossoLocatelliPullanMc<GridGraph> mc(g); |
158 GrossoLocatelliPullanMc<GridGraph> mc(g); |
159 |
159 |
160 mc.iterationLimit(100); |
160 mc.iterationLimit(100); |
161 check(mc.run(rule) == mc.ITERATION_LIMIT, "Wrong termination cause"); |
161 check(mc.run(rule) == mc.ITERATION_LIMIT, "Wrong termination cause"); |
162 check(mc.cliqueSize() == 2, "Wrong clique size"); |
162 check(mc.cliqueSize() == 2, "Wrong clique size"); |
163 |
163 |
164 mc.stepLimit(100); |
164 mc.stepLimit(100); |
177 checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED); |
177 checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED); |
178 |
178 |
179 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::RANDOM); |
179 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::RANDOM); |
180 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED); |
180 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED); |
181 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED); |
181 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED); |
182 |
182 |
183 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::RANDOM); |
183 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::RANDOM); |
184 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED); |
184 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED); |
185 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED); |
185 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED); |
186 |
186 |
187 return 0; |
187 return 0; |
188 } |
188 } |