Boost logo

Boost Users :

Subject: Re: [Boost-users] Trouble w/ fruchterman-reingold
From: eric (eric.burns_at_[hidden])
Date: 2012-10-04 09:19:19


By the way, I thought there might be an issue w/ my using a rectangle
topology for the random_graph_layout and then a square topology for the
fructerman_reingold ... so I changed it all to use the rectangle topology,
but that didn't fix the problem.

New code is below:

using namespace boost;

// Declare global types

enum vertex_position_t { vertex_position };
namespace boost { BOOST_INSTALL_PROPERTY(vertex, position); }
//typedef square_topology<>::point_type point;
typedef rectangle_topology<>::point_type point;

struct simple_edge
{
  int first, second;
};

struct spring_attractive_force {
  template<typename Graph, typename T>
  T
  operator()(typename graph_traits<Graph>::edge_descriptor,
             T k,
             T d,
             const Graph&) const
  {
    return d;
  }
};

struct magnetic_repulsive_force {
  template<typename Graph, typename T>
  T
  operator()(typename graph_traits<Graph>::vertex_descriptor,
             typename graph_traits<Graph>::vertex_descriptor,
             T k,
             T d,
             const Graph&) const
  {
    return 1 / (d * d);
  }
};

int _tmain(int argc, _TCHAR* argv[])
{
typedef adjacency_list<listS, listS, undirectedS,
                                 // Vertex properties
                                 property&lt;vertex_index_t, int,
                                 property&lt;vertex_position_t, point> >,
                                 // Edge properties
                                 property<edge_weight_t, double> > Graph;
        enum {A, B, C, D, E, F, G, H};
        simple_edge triangular_edges[14] = {
                {A, B}, {B, C}, {C, A},
                {D, E}, {E, F}, {F, G}, {G, H}, {H, D},
                {D, F}, {F, H}, {H, E}, {E, G}, {G, D}
        };

        Graph g(&triangular_edges[0], &triangular_edges[13], 8);

        // Generate (x,y) coordinates for every node
        
        // - Randomly layout vertices of graph

        minstd_rand gen;
        rectangle_topology<> rect_top(gen, -25, -25, 25, 25);
        random_graph_layout(g, get(vertex_position, g), rect_top);

        // - Run Fruchterman Reingold algorithm on them

        //typedef square_topology<> Topology;
        //Topology topology(gen, 50.0);
        fruchterman_reingold_force_directed_layout(g, get(vertex_position, g), /*
topology */ rect_top,
                                attractive_force(spring_attractive_force()).
                                repulsive_force(magnetic_repulsive_force()).
                                force_pairs(all_force_pairs()).
                                cooling(linear_cooling<double>(100)));
}

--
View this message in context: http://boost.2283326.n4.nabble.com/Trouble-w-fruchterman-reingold-tp4636494p4636523.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net