# HG changeset patch # User Alpar Juttner # Date 2008-12-01 15:11:31 # Node ID fa341dd6ab2325fa86afd80e1c6eeaa31bba2822 # Parent 5a7dbeaed70e9741b4702363f1e6b8b84864526a Transform circulation demo to test diff --git a/demo/Makefile.am b/demo/Makefile.am --- a/demo/Makefile.am +++ b/demo/Makefile.am @@ -1,19 +1,16 @@ EXTRA_DIST += \ demo/CMakeLists.txt \ - demo/circulation-input.lgf \ demo/digraph.lgf if WANT_DEMO noinst_PROGRAMS += \ demo/arg_parser_demo \ - demo/circulation_demo \ demo/graph_to_eps_demo \ demo/lgf_demo endif WANT_DEMO demo_arg_parser_demo_SOURCES = demo/arg_parser_demo.cc -demo_circulation_demo_SOURCES = demo/circulation_demo.cc demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc demo_lgf_demo_SOURCES = demo/lgf_demo.cc diff --git a/demo/circulation-input.lgf b/demo/circulation-input.lgf deleted file mode 100644 --- a/demo/circulation-input.lgf +++ /dev/null @@ -1,32 +0,0 @@ -@nodes -coordinates_x coordinates_y delta label --396.638 -311.798 0 0 -154.409 -214.714 13 1 --378.119 -135.808 0 2 --138.182 -58.0452 0 3 -55 -76.1018 0 4 --167.302 169.88 0 5 -71.6876 38.7452 0 6 --328.784 257.777 0 7 -354.242 67.9628 -13 8 -147 266 0 9 -@edges - label lo_cap up_cap -0 1 0 0 20 -0 2 1 0 0 -1 1 2 0 3 -1 2 3 0 8 -1 3 4 0 8 -2 5 5 0 5 -3 2 6 0 5 -3 5 7 0 5 -3 6 8 0 5 -4 3 9 0 3 -5 7 10 0 3 -5 6 11 0 10 -5 8 12 0 10 -6 8 13 0 8 -8 9 14 0 20 -8 1 15 0 5 -9 5 16 0 5 -@end diff --git a/demo/circulation_demo.cc b/demo/circulation_demo.cc deleted file mode 100644 --- a/demo/circulation_demo.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- mode: C++; indent-tabs-mode: nil; -*- - * - * This file is a part of LEMON, a generic C++ optimization library. - * - * Copyright (C) 2003-2008 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -///\ingroup demos -///\file -///\brief Demonstrating the usage of LEMON's General Flow algorithm -/// -/// This demo program reads a general network circulation problem from the -/// file 'circulation-input.lgf', runs the preflow based algorithm for -/// finding a feasible solution and writes the output -/// to 'circulation-input.lgf' -/// -/// \include circulation_demo.cc - -#include - -#include -#include -#include -#include - -using namespace lemon; - - -int main (int, char*[]) -{ - - typedef ListDigraph Digraph; - typedef Digraph::Node Node; - typedef Digraph::NodeIt NodeIt; - typedef Digraph::Arc Arc; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::ArcMap ArcMap; - typedef Digraph::NodeMap NodeMap; - typedef Digraph::NodeMap DNodeMap; - - Digraph g; - ArcMap lo(g); - ArcMap up(g); - NodeMap delta(g); - NodeMap nid(g); - ArcMap eid(g); - DNodeMap cx(g); - DNodeMap cy(g); - - DigraphReader(g,"circulation-input.lgf"). - arcMap("lo_cap", lo). - arcMap("up_cap", up). - nodeMap("delta", delta). - arcMap("label", eid). - nodeMap("label", nid). - nodeMap("coordinates_x", cx). - nodeMap("coordinates_y", cy). - run(); - - Circulation gen(g,lo,up,delta); - bool ret=gen.run(); - if(ret) - { - std::cout << "\nA feasible flow has been found.\n"; - if(!gen.checkFlow()) std::cerr << "Oops!!!\n"; - DigraphWriter(g, "circulation-output.lgf"). - arcMap("lo_cap", lo). - arcMap("up_cap", up). - arcMap("flow", gen.flowMap()). - nodeMap("delta", delta). - arcMap("label", eid). - nodeMap("label", nid). - nodeMap("coordinates_x", cx). - nodeMap("coordinates_y", cy). - run(); - } - else { - std::cout << "\nThere is no such a flow\n"; - Digraph::NodeMap bar(g); - gen.barrierMap(bar); - if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n"; - - DigraphWriter(g, "circulation-output.lgf"). - arcMap("lo_cap", lo). - arcMap("up_cap", up). - nodeMap("barrier", bar). - nodeMap("delta", delta). - arcMap("label", eid). - nodeMap("label", nid). - nodeMap("coordinates_x", cx). - nodeMap("coordinates_y", cy). - run(); - } - std::cout << "The output is written to file 'circulation-output.lgf'\n\n"; - -} diff --git a/test/Makefile.am b/test/Makefile.am --- a/test/Makefile.am +++ b/test/Makefile.am @@ -8,6 +8,7 @@ check_PROGRAMS += \ test/bfs_test \ + test/circulation_test \ test/counter_test \ test/dfs_test \ test/digraph_test \ @@ -33,6 +34,7 @@ XFAIL_TESTS += test/test_tools_fail$(EXEEXT) test_bfs_test_SOURCES = test/bfs_test.cc +test_circulation_test_SOURCES = test/circulation_test.cc test_counter_test_SOURCES = test/counter_test.cc test_dfs_test_SOURCES = test/dfs_test.cc test_digraph_test_SOURCES = test/digraph_test.cc diff --git a/test/circulation_test.cc b/test/circulation_test.cc new file mode 100644 --- /dev/null +++ b/test/circulation_test.cc @@ -0,0 +1,118 @@ +/* -*- mode: C++; indent-tabs-mode: nil; -*- + * + * This file is a part of LEMON, a generic C++ optimization library. + * + * Copyright (C) 2003-2008 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +///\ingroup demos +///\file +///\brief Demonstrating the usage of LEMON's General Flow algorithm +/// +/// This demo program reads a general network circulation problem from the +/// file 'circulation-input.lgf', runs the preflow based algorithm for +/// finding a feasible solution and writes the output +/// to 'circulation-input.lgf' +/// +/// \include circulation_demo.cc + +#include + +#include "test_tools.h" +#include +#include +#include + +using namespace lemon; + +char test_lgf[] = + "@nodes\n" + "label delta\n" + "0 0\n" + "1 13\n" + "2 0\n" + "3 0\n" + "4 0\n" + "5 0\n" + "6 0\n" + "7 0\n" + "8 -13\n" + "9 0\n" + "@edges\n" + " label lo_cap up_cap\n" + "0 1 0 0 20\n" + "0 2 1 0 0\n" + "1 1 2 0 3\n" + "1 2 3 0 8\n" + "1 3 4 0 8\n" + "2 5 5 0 5\n" + "3 2 6 0 5\n" + "3 5 7 0 5\n" + "3 6 8 0 5\n" + "4 3 9 0 3\n" + "5 7 10 0 3\n" + "5 6 11 0 10\n" + "5 8 12 0 10\n" + "6 8 13 0 8\n" + "8 9 14 0 20\n" + "8 1 15 0 5\n" + "9 5 16 0 5\n" + "@attributes\n" + "source 1\n" + "sink 8\n"; + +int main (int, char*[]) +{ + + typedef ListDigraph Digraph; + typedef Digraph::Node Node; + typedef Digraph::NodeIt NodeIt; + typedef Digraph::Arc Arc; + typedef Digraph::ArcIt ArcIt; + typedef Digraph::ArcMap ArcMap; + typedef Digraph::NodeMap NodeMap; + typedef Digraph::NodeMap DNodeMap; + + Digraph g; + ArcMap lo(g); + ArcMap up(g); + NodeMap delta(g); + NodeMap nid(g); + ArcMap eid(g); + Node source, sink; + + std::istringstream input(test_lgf); + DigraphReader(g,input). + arcMap("lo_cap", lo). + arcMap("up_cap", up). + nodeMap("delta", delta). + arcMap("label", eid). + nodeMap("label", nid). + node("source",source). + node("sink",sink). + run(); + + Circulation gen(g,lo,up,delta); + bool ret=gen.run(); + check(ret,"A feasible solution should have been found."); + check(gen.checkFlow(), "The found flow is corrupt."); + + delta[source]=14; + delta[sink]=-14; + + bool ret2=gen.run(); + check(!ret2,"A feasible solution should not have been found."); + check(gen.checkBarrier(), "The found barrier is corrupt."); + +}