various fixes

[SVN r11513]
This commit is contained in:
Jeremy Siek 2001-11-01 20:30:32 +00:00
parent 36e2a3074f
commit bb0fc3a38c
20 changed files with 105 additions and 411 deletions

View File

@ -48,82 +48,46 @@ namespace boost
using namespace boost;
typedef adjacency_list < listS, // Store out-edges of each vertex in a std::list
listS, // Store vertex set in a std::list
directedS, // The file dependency graph is directed
typedef adjacency_list< listS, // Store out-edges of each vertex in a std::list
listS, // Store vertex set in a std::list
directedS, // The file dependency graph is directed
// vertex properties
property < vertex_name_t,
std::string,
property <
vertex_compile_cost_t, float,
property <
vertex_distance_t, float,
property <
vertex_color_t,
default_color_type > >>>,
property < vertex_name_t, std::string,
property < vertex_compile_cost_t, float,
property < vertex_distance_t, float,
property < vertex_color_t, default_color_type > > > >,
// an edge property
property <
edge_weight_t, float >>
property < edge_weight_t, float > >
file_dep_graph2;
typedef
graph_traits <
file_dep_graph2 >::vertex_descriptor
vertex_t;
typedef
graph_traits <
file_dep_graph2 >::edge_descriptor
edge_t;
typedef graph_traits<file_dep_graph2>::vertex_descriptor vertex_t;
typedef graph_traits<file_dep_graph2>::edge_descriptor edge_t;
int
main()
{
std::ifstream file_in("makefile-dependencies.dat");
typedef
graph_traits <
file_dep_graph2 >::vertices_size_type
size_type;
typedef graph_traits<file_dep_graph2>::vertices_size_type size_type;
size_type
n_vertices;
file_in >> n_vertices; // read in number of vertices
std::istream_iterator < std::pair < size_type,
size_type > >input_begin(file_in), input_end;
std::istream_iterator<std::pair<size_type, size_type> >
input_begin(file_in), input_end;
file_dep_graph2
g(input_begin, input_end, n_vertices);
typedef
property_map <
file_dep_graph2,
vertex_name_t >::type
name_map_t;
typedef
property_map <
file_dep_graph2,
vertex_compile_cost_t >::type
typedef property_map < file_dep_graph2, vertex_name_t >::type name_map_t;
typedef property_map < file_dep_graph2, vertex_compile_cost_t >::type
compile_cost_map_t;
typedef
property_map <
file_dep_graph2,
vertex_distance_t >::type
typedef property_map <file_dep_graph2, vertex_distance_t >::type
distance_map_t;
typedef
property_map <
file_dep_graph2,
vertex_color_t >::type
typedef property_map <file_dep_graph2, vertex_color_t >::type
color_map_t;
name_map_t
name_map =
get(vertex_name, g);
compile_cost_map_t
compile_cost_map =
get(vertex_compile_cost, g);
distance_map_t
distance_map =
get(vertex_distance, g);
color_map_t
color_map =
get(vertex_color, g);
name_map_t name_map = get(vertex_name, g);
compile_cost_map_t compile_cost_map = get(vertex_compile_cost, g);
distance_map_t distance_map = get(vertex_distance, g);
color_map_t color_map = get(vertex_color, g);
std::ifstream name_in("makefile-target-names.dat");
std::ifstream compile_cost_in("target-compile-costs.dat");

View File

@ -1,57 +0,0 @@
//=======================================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
//
// This file is part of the Boost Graph Library
//
// You should have received a copy of the License Agreement for the
// Boost Graph Library along with the software; see the file LICENSE.
// If not, contact Office of Research, Indiana University,
// Bloomington, IN 47405.
//
// Permission to modify the code and to distribute the code is
// granted, provided the text of this NOTICE is retained, a notice if
// the code was modified is included with the above COPYRIGHT NOTICE
// and with the COPYRIGHT NOTICE in the LICENSE file, and that the
// LICENSE file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <cassert>
template < typename InputIterator, typename T, typename BinaryOperator >
T accumulate(InputIterator first, InputIterator last, T init,
BinaryOperator binary_op)
{
for (; first != last; ++first)
init = binary_op(init, *first);
return init;
}
int
main()
{
// using accumulate with a vector
std::vector < double >x(10, 1.0);
double sum1;
sum1 = std::accumulate(x.begin(), x.end(), 0.0, std::plus < double >());
// using accumulate with a linked list
std::list < double >y;
double sum2;
// copy vector's values into the list
std::copy(x.begin(), x.end(), std::back_inserter(y));
sum2 = std::accumulate(y.begin(), y.end(), 0.0, std::plus < double >());
assert(sum1 == sum2); // they should be equal
return 0;
}

View File

@ -78,7 +78,7 @@ main()
int weight[n_edges] = { -4, 8, 5, -2, 9, -3, 7, 2, 6, 7 };
typedef adjacency_list < vecS, vecS, directedS,
no_property, property < edge_weight_t, int >>Graph;
no_property, property < edge_weight_t, int > > Graph;
Graph g(edge_array.begin(), edge_array.end());
graph_traits < Graph >::edge_iterator ei, ei_end;
int i = 0;
@ -86,7 +86,7 @@ main()
get(edge_weight, g)[*ei] = weight[i];
std::vector < int >distance(N, std::numeric_limits < short >::max());
std::vector < int >parent(N);
std::vector < std::size_t >parent(N);
for (i = 0; i < N; ++i)
parent[i] = i;
distance[z] = 0;
@ -103,10 +103,6 @@ main()
std::cout << "negative cycle" << std::endl;
std::ofstream dot_file("figs/bellman-eg.dot");
#if 0
write_graphviz(dot_file, g, make_label_writer(name),
make_edge_writer(g, &parent[0]));
#else
dot_file << "digraph D {\n"
<< " rankdir=LR\n"
<< " size=\"5,3\"\n"
@ -129,6 +125,5 @@ main()
}
}
dot_file << "}";
#endif
return EXIT_SUCCESS;
}

View File

@ -1,98 +0,0 @@
//=======================================================================
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
//
// This file is part of the Boost Graph Library
//
// You should have received a copy of the License Agreement for the
// Boost Graph Library along with the software; see the file LICENSE.
// If not, contact Office of Research, University of Notre Dame, Notre
// Dame, IN 46556.
//
// Permission to modify the code and to distribute modified code is
// granted, provided the text of this NOTICE is retained, a notice that
// the code was modified is included with the above COPYRIGHT NOTICE and
// with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
// file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================
#include <boost/config.hpp>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <boost/graph/edge_list.hpp>
#include <boost/graph/bellman_ford_shortest_paths.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/graph_utility.hpp>
//
// Example, page 533 CLR
//
// u*===*v
// *|\ **
// / | \ / |
// z | x |
// \ | / \ |
// **/ *|
// x----*y
//
// (didn't draw the y->z edge)
//
// Sample Output (distance and parent):
//
// u: 2 v
// v: 4 x
// x: 7 z
// y: -2 u
// z: 0 z
//
int
main(int,char*)
{
enum { u, v, x, y, z, N };
char name[] = "uvxyz";
typedef std::pair<int,int> E;
E edges[] = { E(u,y), E(u,x), E(u,v),
E(v,u),
E(x,y), E(x,v),
E(y,v), E(y,z),
E(z,u), E(z,x) };
int weight[] = { -4, 8, 5,
-2,
9, -3,
7, 2,
6, 7 };
typedef boost::edge_list<E*, E, std::ptrdiff_t> Graph;
Graph g(edges, edges + sizeof(edges) / sizeof(E));
std::vector<int> distance(N, std::numeric_limits<short>::max());
std::vector<int> parent(N, -1);
distance[z] = 0;
parent[z] = z;
bool r = boost::bellman_ford_shortest_paths
(g, int(N),
boost::weight_map(weight).
distance_map(&distance[0]).
predecessor_map(&parent[0]));
if (r)
for (int i = 0; i < N; ++i)
std::cout << name[i] << ": " << distance[i]
<< " " << name[parent[i]] << std::endl;
else
std::cout << "negative cycle" << std::endl;
return 0;
}

View File

@ -84,7 +84,7 @@ main()
{
typedef adjacency_list < listS, vecS, directedS,
property < vertex_name_t, char >,
property < edge_weight_t, double >>graph_t;
property < edge_weight_t, double > > graph_t;
graph_t g;
property_map < graph_t, vertex_name_t >::type name_map =

View File

@ -32,7 +32,7 @@
#include <boost/graph/visitors.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/neighbor_bfs.hpp>
#include <boost/property_map.hpp>
/*
@ -142,7 +142,7 @@ int main(int , char* [])
p[s] = s;
boost::neighbor_breadth_first_search
(G, s,
boost::visitor(boost::make_bfs_visitor
boost::visitor(boost::make_neighbor_bfs_visitor
(std::make_pair(boost::record_distances(d, boost::on_tree_edge()),
boost::record_predecessors(&p[0],
boost::on_tree_edge())))));

View File

@ -1,89 +0,0 @@
//=======================================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
//
// This file is part of the Boost Graph Library
//
// You should have received a copy of the License Agreement for the
// Boost Graph Library along with the software; see the file LICENSE.
// If not, contact Office of Research, Indiana University,
// Bloomington, IN 47405.
//
// Permission to modify the code and to distribute the code is
// granted, provided the text of this NOTICE is retained, a notice if
// the code was modified is included with the above COPYRIGHT NOTICE
// and with the COPYRIGHT NOTICE in the LICENSE file, and that the
// LICENSE file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================
#include <string>
#include <iostream>
class Point
{
public:
virtual bool equal(const Point * p) const = 0;
};
class ColorPoint:public Point
{
public:
ColorPoint(float x, float y, std::string c):x(x), y(y), color(c)
{
}
virtual bool equal(const ColorPoint * p) const
{
return color == p->color && x == p->x && y == p->y;
}
protected:
float x, y;
std::string color;
};
class ColorPoint2:public Point
{
public:
ColorPoint2(float x, float y, std::string s):x(x), y(y), color(s)
{
}
virtual bool equal(const Point * p) const
{
const ColorPoint2 *cp = dynamic_cast < const ColorPoint2 * >(p);
return color == cp->color && x == cp->x && y == cp->y;
}
protected:
float x, y;
std::string color;
};
void
print_equal(const Point * a, const Point * b)
{
std::cout << std::boolalpha << a->equal(b) << std::endl;
}
template < typename PointType > void
print_equal2(const PointType * a, const PointType * b)
{
std::cout << std::boolalpha << a->equal(b) << std::endl;
}
int
main()
{
Point *p = new ColorPoint2(0.0, 0.0, "blue");
Point *q = new ColorPoint2(0.0, 0.0, "green");
print_equal(p, q);
ColorPoint *a = new ColorPoint(0.0, 0.0, "blue");
ColorPoint *b = new ColorPoint(0.0, 0.0, "green");
print_equal2(a, b);
return 0;
}

View File

@ -33,7 +33,7 @@ main()
using namespace boost;
typedef int weight_t;
typedef adjacency_list < vecS, vecS, directedS,
property < vertex_name_t, char >>graph_t;
property < vertex_name_t, char > > graph_t;
enum
{ a, b, c, d, e, f, g, N };

View File

@ -35,7 +35,7 @@ int
main(int, char *[])
{
typedef adjacency_list < listS, vecS, directedS,
no_property, property < edge_weight_t, int >>graph_t;
no_property, property < edge_weight_t, int > > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
typedef std::pair < int, int >Edge;

View File

@ -80,7 +80,7 @@ namespace boost
typedef adjacency_list < vecS, vecS, directedS, no_property,
property < edge_capacity_t, degree_size_type,
property < edge_residual_capacity_t, degree_size_type,
property < edge_reverse_t, edge_descriptor > >>>FlowGraph;
property < edge_reverse_t, edge_descriptor > > > > FlowGraph;
vertex_descriptor u, v, p, k;
edge_descriptor e1, e2;

View File

@ -39,7 +39,7 @@ main()
property < vertex_name_t, std::string >,
property < edge_capacity_t, long,
property < edge_residual_capacity_t, long,
property < edge_reverse_t, Traits::edge_descriptor > >>>Graph;
property < edge_reverse_t, Traits::edge_descriptor > > > > Graph;
Graph g;

View File

@ -30,7 +30,7 @@ main()
{
using namespace boost;
typedef adjacency_list < vecS, vecS, undirectedS,
no_property, property < edge_weight_t, int >>Graph;
no_property, property < edge_weight_t, int > > Graph;
typedef graph_traits < Graph >::edge_descriptor Edge;
typedef graph_traits < Graph >::vertex_descriptor Vertex;
typedef std::pair < int, int >E;

View File

@ -35,7 +35,7 @@ main()
read_graphviz("figs/telephone-network.dot", g_dot);
typedef adjacency_list < vecS, vecS, undirectedS, no_property,
property < edge_weight_t, int >>Graph;
property < edge_weight_t, int > > Graph;
Graph g(num_vertices(g_dot));
property_map < GraphvizGraph, edge_attribute_t >::type
edge_attr_map = get(edge_attribute, g_dot);

View File

@ -1,46 +0,0 @@
//=======================================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
//
// This file is part of the Boost Graph Library
//
// You should have received a copy of the License Agreement for the
// Boost Graph Library along with the software; see the file LICENSE.
// If not, contact Office of Research, Indiana University,
// Bloomington, IN 47405.
//
// Permission to modify the code and to distribute the code is
// granted, provided the text of this NOTICE is retained, a notice if
// the code was modified is included with the above COPYRIGHT NOTICE
// and with the COPYRIGHT NOTICE in the LICENSE file, and that the
// LICENSE file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================
//=======================================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
//
// This file is part of the Boost Graph Library
//
// You should have received a copy of the License Agreement for the
// Boost Graph Library along with the software; see the file LICENSE.
// If not, contact Office of Research, Indiana University,
// Bloomington, IN 47405.
//
// Permission to modify the code and to distribute the code is
// granted, provided the text of this NOTICE is retained, a notice if
// the code was modified is included with the above COPYRIGHT NOTICE
// and with the COPYRIGHT NOTICE in the LICENSE file, and that the
// LICENSE file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================

View File

@ -0,0 +1,20 @@
15
0 5
0 7
0 11
1 5
1 11
2 5
2 9
2 11
3 7
4 5
5 13
6 7
7 13
8 9
9 12
10 11
11 12
12 14
13 12

View File

@ -0,0 +1,15 @@
dax.h
yow.h
boz.h
zow.h
bar.cpp
bar.o
foo.cpp
foo.o
zig.cpp
zig.o
zag.cpp
zag.o
libzigzag.a
libfoobar.a
killerapp

View File

@ -53,28 +53,16 @@ typedef adjacency_list < listS, // Store out-edges of each vertex in a std::list
listS, // Store vertex set in a std::list
directedS, // The file dependency graph is directed
// vertex properties
property < vertex_name_t,
std::string,
property <
vertex_compile_cost_t, float,
property <
vertex_distance_t, float,
property <
vertex_color_t,
default_color_type > >>>,
property < vertex_name_t, std::string,
property < vertex_compile_cost_t, float,
property < vertex_distance_t, float,
property < vertex_color_t, default_color_type > > > >,
// an edge property
property <
edge_weight_t, float >>
property < edge_weight_t, float > >
file_dep_graph2;
typedef
graph_traits <
file_dep_graph2 >::vertex_descriptor
vertex_t;
typedef
graph_traits <
file_dep_graph2 >::edge_descriptor
edge_t;
typedef graph_traits<file_dep_graph2>::vertex_descriptor vertex_t;
typedef graph_traits<file_dep_graph2>::edge_descriptor edge_t;
template < typename Graph, typename ColorMap, typename Visitor > void
@ -82,21 +70,11 @@ dfs_v2(const Graph & g,
typename graph_traits < Graph >::vertex_descriptor u,
ColorMap color, Visitor vis)
{
typedef typename
property_traits <
ColorMap >::value_type
color_type;
typedef
color_traits <
color_type >
ColorT;
typedef typename property_traits < ColorMap >::value_type color_type;
typedef color_traits < color_type > ColorT;
color[u] = ColorT::gray();
vis.discover_vertex(u, g);
typename
graph_traits <
Graph >::out_edge_iterator
ei,
ei_end;
typename graph_traits < Graph >::out_edge_iterator ei, ei_end;
for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei)
if (color[target(*ei, g)] == ColorT::white()) {
vis.tree_edge(*ei, g);
@ -139,9 +117,7 @@ template < typename OutputIterator > struct topo_visitor:
topo_order(order)
{
}
template <
typename
Graph > void
template < typename Graph > void
finish_vertex(typename graph_traits < Graph >::vertex_descriptor u,
const Graph &)
{

View File

@ -30,7 +30,7 @@ main()
{
using namespace boost;
typedef adjacency_list < vecS, vecS, undirectedS,
property < vertex_distance_t, int, property < edge_weight_t, int >>>Graph;
property<vertex_distance_t, int>, property < edge_weight_t, int > > Graph;
typedef std::pair < int, int >E;
const int num_nodes = 5;
E edges[] = { E(0, 2), E(1, 1), E(1, 3), E(1, 4), E(2, 1), E(2, 3),
@ -39,16 +39,15 @@ main()
int weights[] = { 1, 2, 1, 2, 7, 3, 1, 1 };
Graph g(num_nodes, edges, edges + sizeof(edges) / sizeof(E), weights);
std::vector < graph_traits < Graph >::vertex_descriptor >
p(num_vertices(G));
p(num_vertices(g));
prim_minimum_spanning_tree(g, &p[0]);
std::vector < Graph::vertex_descriptor >::iterator i;
for (i = p.begin(); i != p.end(); ++i)
cout << "parent[" << i - p.begin()
<< "] = " << identity_property_map()[*i] << endl;
else
cout << "parent[" << i - p.begin() << "] = no parent" << endl;
for (std::size_t i = 0; i != p.size(); ++i)
if (p[i] != i)
std::cout << "parent[" << i << "] = " << p[i] << std::endl;
else
std::cout << "parent[" << i << "] = no parent" << std::endl;
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,15 @@
0.0
0.0
0.0
0.0
0.0
1.5
0.0
2.8
0.0
3.6
0.0
8.7
1.1
1.5
2.1

View File

@ -23,7 +23,7 @@ namespace boost {
DistanceMap distance, WeightMap weight, ColorMap color,
PredecessorMap pred,
DijkstraVisitor vis, Compare compare, Combine combine,
DistInf inf_gen, DistZero zero)
DistInf inf, DistZero zero)
{
typedef typename graph_traits<VertexListGraph>::vertex_descriptor Vertex;
std::vector<Vertex> rev_topo_order;
@ -32,11 +32,11 @@ namespace boost {
typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
put(distance, *ui, inf_gen());
put(distance, *ui, inf);
put(pred, *ui, *ui);
}
put(distance, s, zero());
put(distance, s, zero);
vis.discover_vertex(s, g);
std::vector<Vertex>::reverse_iterator i;
for (i = rev_topo_order.rbegin(); i != rev_topo_order.rend(); ++i) {
@ -78,9 +78,9 @@ namespace boost {
choose_param(get_param(params, distance_compare_t()), std::less<D>()),
choose_param(get_param(params, distance_combine_t()), std::plus<D>()),
choose_param(get_param(params, distance_inf_t()),
generate_infinity<D>()),
std::numeric_limits<D>::max()),
choose_param(get_param(params, distance_zero_t()),
generate_zero<D>()));
D()));
}
// Handle DistanceMap and ColorMap defaults