Commit 3a45d7be authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

unneeded stuff

git-svn-id: https://svn.forked.de/graph-tool/trunk@2 d4600afd-f417-0410-95de-beed9576f240
parent a9aff6b4
#include <ext/hash_map>
#include <map>
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/filtered_graph.hpp>
#include "../graph_adaptor.hh"
using namespace boost;
template <class Graph>
void print_graph(Graph &g)
{
boost::vertex_index_t vertex_index;
boost::edge_weight_t edge_weight;
for(typename graph_traits<Graph>::vertex_iterator iter = vertices(g).first;
iter != vertices(g).second; ++iter)
{
typename graph_traits<Graph>::vertex_descriptor v = *iter;
std::cout << get(vertex_index, g, v) << ": ";
for(typename graph_traits<Graph>::out_edge_iterator iter2 = out_edges(v,g).first;
iter2 != out_edges(v,g).second; ++iter2)
std::cout << get(vertex_index, g, target(*iter2,g))
<< "(" << get(edge_weight, g, *iter2) << ") ";
std::cout << std::endl;
}
}
template <class Graph>
void print_graph_adjacency(Graph &g)
{
boost::vertex_index_t vertex_index;
for(typename graph_traits<Graph>::vertex_iterator iter = vertices(g).first;
iter != vertices(g).second; ++iter)
{
typename graph_traits<Graph>::vertex_descriptor v = *iter;
std::cout << get(vertex_index, g, v) << ": ";
for(typename graph_traits<Graph>::adjacency_iterator
iter2 = adjacent_vertices(*iter,g).first;
iter2 != adjacent_vertices(*iter,g).second; ++iter2)
std::cout << get(vertex_index, g, *iter2) <<" ";
std::cout << std::endl;
}
}
int main()
{
typedef adjacency_list
< boost::vecS, // boost::vecS, boost::hash_setS
boost::vecS, //boost::slistS,
boost::bidirectionalS,
boost::property<boost::vertex_index_t, int >,
boost::property<boost::edge_weight_t, int > > Graph;
function_requires<VertexListGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<EdgeListGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<VertexMutableGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<EdgeMutableGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<MutableIncidenceGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<AdjacencyGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<VertexMutablePropertyGraphConcept<UndirectedAdaptor<Graph> > >();
function_requires<EdgeMutablePropertyGraphConcept<UndirectedAdaptor<Graph> > >();
Graph g;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
Vertex v1 = add_vertex(1, g);
Vertex v2 = add_vertex(2, g);
Vertex v3 = add_vertex(3, g);
Vertex v4 = add_vertex(4, g);
Vertex v5 = add_vertex(5, g);
add_edge(v1,v2,1,g);
add_edge(v2,v1,1,g);
add_edge(v5,v4,1,g);
add_edge(v4,v3,1,g);
add_edge(v3,v1,1,g);
add_edge(v3,v2,1,g);
add_edge(v3,v3,1,g);
add_edge(v3,v4,1,g);
add_edge(v3,v5,1,g);
std::cout << "Directed:" << std::endl;
print_graph(g);
typedef UndirectedAdaptor<Graph> Ugraph;
Ugraph ug(g);
std::cout << std::endl << "Undirected:" << std::endl;
print_graph(ug);
std::cout << std::endl << "Undirected (using adjacent_vertices):" << std::endl;
print_graph_adjacency(ug);
ParallelFilter<Graph> directed_filter(g);
filtered_graph<Graph, ParallelFilter<Graph> > gf(g,directed_filter);
std::cout << std::endl<< "Filtered directed:" << std::endl;
print_graph(gf);
ParallelFilter<Ugraph> undirected_filter(ug);
filtered_graph<Ugraph, ParallelFilter<Ugraph> > ugf(ug,undirected_filter);
std::cout << std::endl<< "Filtered undirected:" << std::endl;
print_graph(ugf);
filtered_graph<Ugraph, ParallelFilter<Ugraph> >::edge_iterator e,b;
for (e = edges(ugf).first; e != edges(ugf).second; e++)
{
boost::edge_weight_t tag;
std::cout << get(tag, ugf, *e) << " " ;
}
std::cout << std::endl;
std::cout << "Testing iterators..." << std::endl;
for(graph_traits<Ugraph>::vertex_iterator iter = vertices(ug).first; iter != vertices(ug).second; ++iter)
{
graph_traits<Ugraph>::vertex_descriptor v = *iter;
for(graph_traits<Ugraph>::out_edge_iterator iter2 = out_edges(v,ug).first; iter2 != out_edges(v,ug).second; ++iter2)
{
iter2++;
iter2--;
std::cout << "(" << get(vertex_index, ug, source(*iter2,ug)) << ", " << get(vertex_index, ug, target(*iter2,ug)) << ") ";
}
std::cout << std::endl;
}
std::cout << std::endl << std::endl;
for(graph_traits<Ugraph>::vertex_iterator iter = vertices(ug).first; iter != vertices(ug).second; ++iter)
{
iter++;
iter--;
graph_traits<Ugraph>::vertex_descriptor v = *iter;
for(graph_traits<Ugraph>::out_edge_iterator iter2 = out_edges(v,ug).second;;)
{
if (iter2 == out_edges(v,ug).first)
break;
iter2--;
iter2++;
iter2--;
std::cout << "(" << get(vertex_index, ug, source(*iter2,ug)) << ", " << get(vertex_index, ug, target(*iter2,ug)) << ") ";
}
std::cout << std::endl;
}
}
#include <ext/hash_map>
#include <map>
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/connected_components.hpp>
using namespace boost;
int main()
{
typedef adjacency_list
< listS,
listS,
bidirectionalS,
property<vertex_index_t, int,
property<vertex_index2_t, int> > > Graph;
function_requires<VertexListGraphConcept<Graph> >();
function_requires<EdgeListGraphConcept<Graph > >();
function_requires<VertexMutableGraphConcept<Graph > >();
function_requires<EdgeMutableGraphConcept<Graph> >();
function_requires<MutableIncidenceGraphConcept<Graph> >();
function_requires<AdjacencyGraphConcept<Graph> >();
function_requires<VertexMutablePropertyGraphConcept<Graph> >();
function_requires<EdgeMutablePropertyGraphConcept<Graph> >();
Graph g;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
Vertex v[9];
for (int i = 0; i < 9; ++i)
v[i] = add_vertex(i, g);
for (int i = 0; i < 8; ++i)
add_edge(v[i],v[i+1],g);
add_edge(v[8],v[6],g);
add_edge(v[6],v[7],g);
add_edge(v[7],v[1],g);
add_edge(v[1],v[2],g);
add_edge(v[2],v[4],g);
add_edge(v[4],v[5],g);
vertex_index2_t vertex_index2;
strong_components(g, get(vertex_index2, g));
std::cout << "Directed:" << std::endl;
vertex_index_t vertex_index;
for(graph_traits<Graph>::vertex_iterator iter = vertices(g).first;
iter != vertices(g).second; ++iter)
{
graph_traits<Graph>::vertex_descriptor v = *iter;
std::cout << get(vertex_index, g, v)
<< "(" << get(vertex_index2, g, v) << ") : ";
for(graph_traits<Graph>::out_edge_iterator iter2 = out_edges(v,g).first;
iter2 != out_edges(v,g).second; ++iter2)
std::cout << get(vertex_index, g, target(*iter2,g)) << " ";
std::cout << std::endl;
}
}
#include <ext/hash_map>
#include <map>
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_concepts.hpp>
#include "../filtered_graph.hpp"
#include "../graph_filter.hh"
#include "../graph_adaptor.hh"
using namespace boost;
template <class Graph>
void print_graph(Graph &g)
{
for(typename graph_traits<Graph>::vertex_iterator iter = vertices(g).first;
iter != vertices(g).second; ++iter)
{
typename graph_traits<Graph>::vertex_descriptor v = *iter;
std::cout << g[v].index << ": ";
for(typename graph_traits<Graph>::out_edge_iterator iter2 =
out_edges(v,g).first;
iter2 != out_edges(v,g).second; ++iter2)
std::cout << g[target(*iter2,g)].index
<< "(" << g[*iter2].hidden << ") ";
std::cout << std::endl;
}
}
template <class Graph>
void print_graph_adjacency(Graph &g)
{
for(typename graph_traits<Graph>::vertex_iterator iter = vertices(g).first;
iter != vertices(g).second; ++iter)
{
typename graph_traits<Graph>::vertex_descriptor v = *iter;
std::cout << g[v].index << ": ";
for(typename graph_traits<Graph>::adjacency_iterator
iter2 = adjacent_vertices(*iter,g).first;
iter2 != adjacent_vertices(*iter,g).second; ++iter2)
std::cout << g[*iter2].index <<" ";
std::cout << std::endl;
}
}
struct VertexProperties
{
size_t index;
bool hidden;
};
struct EdgeProperties
{
size_t index;
bool hidden;
};
template <class Graph, class VertexOrEdge>
class HiddenFilter
{
public:
HiddenFilter(): _g(0) {}
HiddenFilter(const Graph &g):_g(&g) {}
bool operator() (VertexOrEdge u) const
{
return (*_g)[u].hidden;
}
private:
Graph const *_g;
};
int main()
{
typedef adjacency_list
< boost::vecS, // boost::vecS, boost::hash_setS
boost::setS, //boost::slistS,
boost::bidirectionalS,
VertexProperties,
EdgeProperties > Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
typedef HiddenFilter<Graph, Vertex> vpred_t;
typedef HiddenFilter<Graph, Edge> epred_t;
function_requires<VertexListGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<EdgeListGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<VertexMutableGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<EdgeMutableGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<MutableIncidenceGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<AdjacencyGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<VertexMutablePropertyGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
function_requires<EdgeMutablePropertyGraphConcept<UncoupledAdaptor<Graph, epred_t, vpred_t> > >();
Graph g;
Vertex v1 = add_vertex(g);
g[v1].index = 1;
g[v1].hidden = true;
Vertex v2 = add_vertex(g);
g[v2].index = 2;
g[v2].hidden = false;
Vertex v3 = add_vertex(g);
g[v3].index = 3;
g[v3].hidden = true;
Vertex v4 = add_vertex(g);
g[v4].index = 4;
g[v4].hidden = false;
Vertex v5 = add_vertex(g);
g[v5].index = 5;
g[v5].hidden = true;
Edge e;
e = add_edge(v1,v2,g).first;
g[e].index = 1;
g[e].hidden = true;
e = add_edge(v2,v3,g).first;
g[e].index = 2;
g[e].hidden = false;
e = add_edge(v3,v4,g).first;
g[e].index = 3;
g[e].hidden = false;
e = add_edge(v4,v5,g).first;
g[e].index = 4;
g[e].hidden = true;
e = add_edge(v5,v1,g).first;
g[e].index = 5;
g[e].hidden = true;
e = add_edge(v5,v1,g).first;
g[e].index = 6;
g[e].hidden = true;
std::cout << "coupled:" << std::endl;
print_graph(g);
vpred_t vpred(g);
epred_t epred(g);
typedef UncoupledAdaptor<Graph, epred_t, vpred_t> Ugraph;
Ugraph ug(g, epred, vpred);
std::cout << std::endl << "uncoupled:" << std::endl;
print_graph(ug);
std::cout << std::endl << "uncoupled (using adjacent_vertices):"
<< std::endl;
print_graph_adjacency(ug);
std::cout << std::endl;
ParallelFilter<Graph> directed_filter(g);
filtered_graph<Graph, ParallelFilter<Graph> > gf(g,directed_filter);
std::cout << std::endl<< "filtered coupled:" << std::endl;
print_graph(gf);
ParallelFilter<Ugraph> undirected_filter(ug);
filtered_graph<Ugraph, ParallelFilter<Ugraph> > ugf(ug,undirected_filter);
std::cout << std::endl<< "filtered uncoupled:" << std::endl;
print_graph(ugf);
typedef graph_traits<filtered_graph<Graph, ParallelFilter<Graph> > >::vertex_descriptor FVertex;
typedef graph_traits<filtered_graph<Graph, ParallelFilter<Graph> > >::edge_descriptor FEdge;
typedef HiddenFilter<filtered_graph<Graph, ParallelFilter<Graph> >, FVertex> fvpred_t;
typedef HiddenFilter<filtered_graph<Graph, ParallelFilter<Graph> >, FEdge> fepred_t;
fvpred_t fvpred(gf);
fepred_t fepred(gf);
typedef UncoupledAdaptor<filtered_graph<Graph, ParallelFilter<Graph> >,
fepred_t, fvpred_t> FUgraph;
FUgraph fug(gf, fepred, fvpred);
std::cout << std::endl<< "uncoupled filtered:" << std::endl;
print_graph(fug);
ParallelFilter<FUgraph> filter_undirected_filter(fug);
filtered_graph<FUgraph, ParallelFilter<FUgraph> > fugf(fug, filter_undirected_filter);
std::cout << std::endl<< "filtered uncoupled filtered:" << std::endl;
print_graph(fugf);
}
//=======================================================================
// Copyright 2002 Indiana University.
// 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.
//
// 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 <iostream>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
#define VERBOSE 1
#include <boost/utility.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/random.hpp>
#include <boost/pending/indirect_cmp.hpp>
#include <boost/random/mersenne_twister.hpp>
enum vertex_id_t { vertex_id = 500 };
enum edge_id_t { edge_id = 501 };
namespace boost {
BOOST_INSTALL_PROPERTY(vertex, id);
BOOST_INSTALL_PROPERTY(edge, id);
}
#include "graph_type.hpp" // this provides a typedef for Graph
using namespace boost;
/*
This program tests models of the MutableGraph concept.
*/
using std::cout;
using std::endl;
using std::cerr;
using std::find;
template <class Graph, class Vertex, class ID>
bool check_vertex_cleared(Graph& g, Vertex v, ID id)
{
typename graph_traits<Graph>::vertex_iterator vi, viend;
for (boost::tie(vi,viend) = vertices(g); vi != viend; ++vi) {
typename graph_traits<Graph>::adjacency_iterator ai, aiend, found;
boost::tie(ai, aiend) = adjacent_vertices(*vi, g);
boost::indirect_cmp<ID, std::equal_to<std::size_t> > cmp(id);
#if (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) && defined(__SGI_STL_PORT)
// seeing internal compiler errors when using std::find_if()
found = aiend;
for ( ; ai != aiend; ++ai)
if (cmp(*ai, v)) {
found = ai;
break;
}
#else
found = std::find_if(ai, aiend, std::bind1st(cmp,v));
#endif
if ( found != aiend ) {
#if VERBOSE
std::cerr << "should not have found vertex " << id[*found] << std::endl;
#endif
return false;
}
}
return true;
}
template <class Graph, class Edge, class EdgeID>
bool check_edge_added(Graph& g, Edge e,
typename graph_traits<Graph>::vertex_descriptor a,
typename graph_traits<Graph>::vertex_descriptor b,
EdgeID edge_id, std::size_t correct_id,
bool inserted)
{
if (! (source(e, g) == a)) {
#if VERBOSE
cerr << " Failed, vertex a not source of e."<< endl;
#endif
return false;
} else if (! (target(e, g) == b)) {
#if VERBOSE
cerr << " Failed, vertex b not source of e."<< endl;
#endif
return false;
} else if (! is_adjacent(g, a, b)) {
#if VERBOSE
cerr << " Failed, not adj."<< endl;
#endif
return false;
} else if (! in_edge_set(g,e)) {
#if VERBOSE
cerr << " Failed, not in edge set."<< endl;
#endif
return false;
} else if (inserted && edge_id[e] != correct_id) {
#if VERBOSE
cerr << " Failed, invalid edge property."<< endl;
#endif
return false;
} else if (!inserted && edge_id[e] != edge_id[edge(a, b, g).first]) {
#if VERBOSE
cerr << " Failed, invalid edge property."<< endl;
#endif
return false;
} else if (num_edges(g) != count_edges(g)) {
#if VERBOSE
cerr << " Failed, invalid number of edges."<< endl;
#endif
return false;
}
return true;
}
template <class Graph>
std::size_t count_edges(Graph& g)
{
std::size_t e = 0;
typename boost::graph_traits<Graph>::edge_iterator ei,ei_end;
for (boost::tie(ei,ei_end) = edges(g); ei != ei_end; ++ei)
++e;
return e;
}
int main(int, char* [])
{
int ret = 0;
std::size_t N = 5, E = 0;
std::size_t old_N;
Graph g;
GraphAdaptor undirected_g(g);
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef boost::graph_traits<Graph>::edge_descriptor Edge;
int i, j;
std::size_t current_vertex_id = 0;
std::size_t current_edge_id = 0;
bool is_failed = false;
property_map<Graph, vertex_id_t>::type vertex_id_map = get(vertex_id, g);
property_map<Graph, edge_id_t>::type edge_id_map = get(edge_id, g);
for (std::size_t k = 0; k < N; ++k)
add_vertex(current_vertex_id++, g);
// also need to test EdgeIterator graph constructor -JGS
mt19937 gen;