1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/graph/src/johnson-test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,92 @@
1.4 +//=======================================================================
1.5 +// Copyright 2002 Indiana University.
1.6 +// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
1.7 +//
1.8 +// Distributed under the Boost Software License, Version 1.0. (See
1.9 +// accompanying file LICENSE_1_0.txt or copy at
1.10 +// http://www.boost.org/LICENSE_1_0.txt)
1.11 +//=======================================================================
1.12 +/*
1.13 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.14 +*/
1.15 +
1.16 +
1.17 +/* Expected Output
1.18 + 0 1 2 3 4 5 6 7 8 9
1.19 + 0 0 99 111 123 103 107 125 105 111 123
1.20 + 1 99 0 12 24 4 8 26 6 12 24
1.21 + 2 111 12 0 12 16 20 24 18 24 26
1.22 + 3 123 24 12 0 28 30 12 30 26 14
1.23 + 4 103 4 16 28 0 4 22 2 8 20
1.24 + 5 107 8 20 30 4 0 18 6 4 16
1.25 + 6 125 26 24 12 22 18 0 24 14 2
1.26 + 7 105 6 18 30 2 6 24 0 10 22
1.27 + 8 111 12 24 26 8 4 14 10 0 12
1.28 + 9 123 24 26 14 20 16 2 22 12 0
1.29 +*/
1.30 +
1.31 +#include <boost/config.hpp>
1.32 +#include <fstream>
1.33 +#include <iostream>
1.34 +#include <vector>
1.35 +#include <iomanip>
1.36 +#include <boost/property_map.hpp>
1.37 +#include <boost/graph/adjacency_list.hpp>
1.38 +#include <boost/graph/graphviz.hpp>
1.39 +#include <boost/graph/johnson_all_pairs_shortest.hpp>
1.40 +#ifdef __SYMBIAN32__
1.41 +#include "std_log_result.h"
1.42 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.43 +#endif
1.44 +int main()
1.45 +{
1.46 + using namespace boost;
1.47 + typedef adjacency_list<vecS, vecS, undirectedS, no_property,
1.48 + property< edge_weight_t, int,
1.49 + property< edge_weight2_t, int > > > Graph;
1.50 + const int V = 10;
1.51 + typedef std::pair < int, int >Edge;
1.52 + Edge edge_array[] =
1.53 + { Edge(0,1), Edge(1,2), Edge(2,3), Edge(1,4), Edge(2,5), Edge(3,6),
1.54 + Edge(4,5), Edge(5,6), Edge(4,7), Edge(5,8), Edge(6,9), Edge(7,8),
1.55 + Edge(8,9)
1.56 + };
1.57 +
1.58 + const std::size_t E = sizeof(edge_array) / sizeof(Edge);
1.59 +
1.60 + Graph g(edge_array, edge_array + E, V);
1.61 +
1.62 +
1.63 + property_map < Graph, edge_weight_t >::type w = get(edge_weight, g);
1.64 + int weights[] = { 99, 12, 12, 4, 99, 12, 4, 99, 2, 4, 2, 99, 12 };
1.65 + int *wp = weights;
1.66 +
1.67 + graph_traits < Graph >::edge_iterator e, e_end;
1.68 + for (boost::tie(e, e_end) = edges(g); e != e_end; ++e)
1.69 + w[*e] = *wp++;
1.70 +
1.71 + std::vector < int >d(V, (std::numeric_limits < int >::max)());
1.72 + int D[V][V];
1.73 + johnson_all_pairs_shortest_paths(g, D, distance_map(&d[0]));
1.74 +
1.75 + std::cout << std::setw(5) <<" ";
1.76 + for (int k = 0; k < 10; ++k)
1.77 + std::cout << std::setw(5) << k ;
1.78 + std::cout << std::endl;
1.79 + for (int i = 0; i < 10; ++i) {
1.80 + std::cout <<std::setw(5) << i ;
1.81 + for (int j = 0; j < 10; ++j) {
1.82 + std::cout << std::setw(5) << D[i][j] ;
1.83 + }
1.84 + std::cout << std::endl;
1.85 + }
1.86 +
1.87 +
1.88 +#ifdef __SYMBIAN32__
1.89 +std_log(LOG_FILENAME_LINE,"[End Test Case ]");
1.90 +
1.91 + testResultXml("johnson-test");
1.92 + close_log_file();
1.93 +#endif
1.94 + return 0;
1.95 +}