Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:49:15+00:00 2026-06-03T12:49:15+00:00

I want to layout the graph of an RNA folding using BGL, it has

  • 0

I want to layout the graph of an RNA folding using BGL, it has a guaranteed plane structure and all edges should have the same length (there are two kinds of edges: the 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 cooldown 100, 200, 400). Longer cooldowns just press the vertices into the corners (images show the complete layout). The edges seem to be consistently too long…

output

I’d like to specify a target length for the edges, and not have the simulation stop until it’s been reached within some margin.

My code is cobbled together from the boost samples, but I don’t need to stick to property maps etc, I just want a layout without having to resort to GraphViz.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:49:17+00:00Added an answer on June 3, 2026 at 12:49 pm

    It looks like the layout is starting to work in your righthand-most image, but that the space is too small for it to unfold into the right shape: maybe try using a more compact random layout to start with?

    Or a stronger attractive force might help too. Note that according to the documentation the default attractive force function, square_distance_attractive_force divides the attractive force by the edge descriptor — so smaller edge descriptors mean closer vertices.


    You can work out a “target-length” (sort of) for edges by considering that, for a well laid out planar graph, each vertex is only close to the vertices that it’s linked to by edges. This is pretty similar to the simple case where we have two vertices joined by a single edge (and if you had a regular grid of vertices, it wouldn’t be out by a factor of more than 4):

    • The (default) repulsive force function is (vertex descriptor value, V)^2/distance for all vertex pairs.
    • The (default) attractive force function is distance^2/(edge descriptor value, E) for vertices linked by edges.

    These are in equilibrium when:

    V2 / distance = distance2 / E

    so:

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement chart like structure. For bar graph I'm using no. of
I have a data structure that represents a directed graph, and I want to
I have some graph, which I want to display using JUNG2 like in the
I'm creating a bar graph like structure using buttons and textviews. I want to
I want to set layout something like What i thought that i will have
I have an XML layout and want to add my own custom SurfaceView to
I want to create a layout for an Android app that has a numeric
I want to create a layout that has 6 TextViews on the very top,
I have a page with a table, and I want its layout to look
I want to plot three graphs in a 1x3 layout. Only the first graph

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.