alpar@906: /* -*- C++ -*-
alpar@921:  * src/test/suurballe_test.cc - Part of LEMON, a generic C++ optimization library
alpar@906:  *
alpar@906:  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906:  * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906:  *
alpar@906:  * Permission to use, modify and distribute this software is granted
alpar@906:  * provided that this copyright notice appears in all copies. For
alpar@906:  * precise terms see the accompanying LICENSE file.
alpar@906:  *
alpar@906:  * This software is provided "AS IS" with no warranty of any kind,
alpar@906:  * express or implied, and with no claim as to its suitability for any
alpar@906:  * purpose.
alpar@906:  *
alpar@906:  */
alpar@906: 
alpar@899: #include <iostream>
alpar@921: #include <lemon/list_graph.h>
alpar@921: #include <lemon/suurballe.h>
alpar@899: //#include <path.h>
alpar@899: #include "test_tools.h"
alpar@899: 
alpar@921: using namespace lemon;
alpar@899: 
alpar@899: 
alpar@899: bool passed = true;
alpar@899: 
alpar@899: 
alpar@899: int main()
alpar@899: {
marci@941:   typedef ListGraph Graph;
marci@941:   typedef Graph::Node Node;
marci@941:   typedef Graph::Edge Edge;
alpar@899: 
marci@941:   Graph graph;
alpar@899: 
alpar@899:   //Ahuja könyv példája
alpar@899: 
alpar@899:   Node s=graph.addNode();
alpar@899:   Node v1=graph.addNode();  
alpar@899:   Node v2=graph.addNode();
alpar@899:   Node v3=graph.addNode();
alpar@899:   Node v4=graph.addNode();
alpar@899:   Node v5=graph.addNode();
alpar@899:   Node t=graph.addNode();
alpar@899: 
alpar@899:   Edge s_v1=graph.addEdge(s, v1);
alpar@899:   Edge v1_v2=graph.addEdge(v1, v2);
alpar@899:   Edge s_v3=graph.addEdge(s, v3);
alpar@899:   Edge v2_v4=graph.addEdge(v2, v4);
alpar@899:   Edge v2_v5=graph.addEdge(v2, v5);
alpar@899:   Edge v3_v5=graph.addEdge(v3, v5);
alpar@899:   Edge v4_t=graph.addEdge(v4, t);
alpar@899:   Edge v5_t=graph.addEdge(v5, t);
alpar@899:   
alpar@899: 
marci@941:   Graph::EdgeMap<int> length(graph);
alpar@899: 
alpar@899:   length.set(s_v1, 6);
alpar@899:   length.set(v1_v2, 4);
alpar@899:   length.set(s_v3, 10);
alpar@899:   length.set(v2_v4, 5);
alpar@899:   length.set(v2_v5, 1);
alpar@899:   length.set(v3_v5, 5);
alpar@899:   length.set(v4_t, 8);
alpar@899:   length.set(v5_t, 8);
alpar@899: 
alpar@899:   std::cout << "Minlengthpaths algorithm test..." << std::endl;
alpar@899: 
alpar@899:   
alpar@899:   int k=3;
marci@941:   Suurballe< Graph, Graph::EdgeMap<int> >
marci@941:     surb_test(graph, length, s, t);
alpar@899: 
marci@941:   check(  surb_test.run(k) == 2 && surb_test.totalLength() == 46,
alpar@899: 	  "Two paths, total length should be 46");
alpar@899: 
alpar@899:   check(  surb_test.checkComplementarySlackness(),
alpar@899: 	  "Complementary slackness conditions are not met.");
alpar@899: 
marci@941:   //  typedef DirPath<Graph> DPath;
alpar@899:   //  DPath P(graph);
alpar@899: 
alpar@899:   /*
alpar@899:   surb_test.getPath(P,0);
alpar@899:   check(P.length() == 4, "First path should contain 4 edges.");  
marci@941:   std::cout<<P.length()<<std::endl;
alpar@899:   surb_test.getPath(P,1);
alpar@899:   check(P.length() == 3, "Second path: 3 edges.");
marci@941:   std::cout<<P.length()<<std::endl;
alpar@899:   */  
alpar@899: 
alpar@899:   k=1;
marci@941:   check(  surb_test.run(k) == 1 && surb_test.totalLength() == 19,
alpar@899: 	  "One path, total length should be 19");
alpar@899: 
alpar@899:   check(  surb_test.checkComplementarySlackness(),
alpar@899: 	  "Complementary slackness conditions are not met.");
alpar@899:  
alpar@899:   //  surb_test.getPath(P,0);
alpar@899:   //  check(P.length() == 4, "First path should contain 4 edges.");  
alpar@899: 
marci@941:   std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
marci@941: 	    << std::endl;
alpar@899: 
alpar@899:   return passed ? 0 : 1;
alpar@899: 
alpar@899: }