Fruchterman Reingold mock up

I want to expand the graph of RNA folding using BGL, it has a guaranteed plane structure, and all edges must have the same length (there are two types of edges: normal sequence and bonds in red), like this

rna secondary structure http://www.ncrna.org/frnadb/sec_structure/png/FR096703.png

namespace boost {
    enum vertex_position_t { vertex_position };
    BOOST_INSTALL_PROPERTY(vertex, position);
};

template<class PairIterator>
void layout(std::string seq, PairIterator begin, PairIterator end) {
    using namespace boost; using namespace std;

    // backbone edges + bonding edges
    vector<pair<size_t,size_t>> edge_list(begin, end);
    for(size_t i = 0 ; i < seq.size() - 1 ; i++)
        edge_list.push_back(make_pair(i, i + 1));

    typedef rectangle_topology<> topology;
    typedef topology::point_type point;
    boost::minstd_rand random;
    topology space(random, -1000, -1000, 2000, 2000);

    adjacency_list<vecS, vecS, undirectedS,
        property<vertex_position_t, point>
    > g(edge_list.begin(), edge_list.end(), seq.size());

    random_graph_layout(g, get(vertex_position, g), space);
    fruchterman_reingold_force_directed_layout(g, get(vertex_position, g), space,
        cooling(linear_cooling<double>(100)));

    // draw
}

However, this gives me a very random layout (for a 100, 200, 400 cooldown). Longer cooldowns simply push the vertices into the corners (images show the full layout). The edges seem too long ...

output

I would like to indicate the length of the target for the edges and not stop the simulation until it is reached with some limit.

My code is paved with boost samples, but I don’t need to stick to property maps, etc., I just want a layout without resorting to GraphViz.

+3
1

, , : , , ?

. , , square_distance_attractive_force - .


" " () , , , . , , ( , 4 ):

  • ( ) (vertex descriptor value, V)^2/distance .
  • ( ) distance^2/(edge descriptor value, E) , .

, :

V 2/distance = distance 2/E

:

= V (2/3) E (1/3)

+3