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 8644797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:23:19+00:00 2026-06-12T12:23:19+00:00

I am solving a problem on directed acyclic graph. But I am having trouble

  • 0

I am solving a problem on directed acyclic graph.

But I am having trouble testing my code on some directed acyclic graphs. The test graphs should be large, and (obviously) acyclic.

I tried a lot to write code for generating acyclic directed graphs. But I failed every time.

Is there some existing method to generate acyclic directed graphs I could use?

  • 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-12T12:23:20+00:00Added an answer on June 12, 2026 at 12:23 pm

    I cooked up a C program that does this. The key is to ‘rank’ the nodes, and only draw edges from lower ranked nodes to higher ranked ones.

    The program I wrote prints in the DOT language.

    Here is the code itself, with comments explaining what it means:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define MIN_PER_RANK 1 /* Nodes/Rank: How 'fat' the DAG should be.  */
    #define MAX_PER_RANK 5
    #define MIN_RANKS 3    /* Ranks: How 'tall' the DAG should be.  */
    #define MAX_RANKS 5
    #define PERCENT 30     /* Chance of having an Edge.  */
    
    int main (void)
    {
      int i, j, k,nodes = 0;
      srand (time (NULL));
    
      int ranks = MIN_RANKS
                  + (rand () % (MAX_RANKS - MIN_RANKS + 1));
    
      printf ("digraph {\n");
      for (i = 0; i < ranks; i++)
        {
          /* New nodes of 'higher' rank than all nodes generated till now.  */
          int new_nodes = MIN_PER_RANK
                          + (rand () % (MAX_PER_RANK - MIN_PER_RANK + 1));
    
          /* Edges from old nodes ('nodes') to new ones ('new_nodes').  */
          for (j = 0; j < nodes; j++)
            for (k = 0; k < new_nodes; k++)
              if ( (rand () % 100) < PERCENT)
                printf ("  %d -> %d;\n", j, k + nodes); /* An Edge.  */
    
          nodes += new_nodes; /* Accumulate into old node set.  */
        }
      printf ("}\n");
      return 0;
    }
    

    And here is the graph generated from a test run:

    A randomly generated DAG

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

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
I'm having trouble solving this problem. I have to find all simple paths starting
I'm having trouble solving this problem: Create a function that given a character set
I'm having trouble solving a problem with iterative SQL queries ( which I need
Ok so I am having trouble solving a problem with having a Regex using
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
Problem in MATLAB Code for solving desired 'n' number of simultaneous equations of the
I'm solving a problem that consist in generate the first n<1000000 lucky numbers, but
I'm solving problem of storing files in my web app. I've already done some
I'm thinking about solving my problem and need some help. I need to pay

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.