![]() |
| ||
| Randomly Generated Network Hi Everyone, Good day to you all. I am solving a problem : to Generate a Random Network. I hv divided the problem into two parts. First generate a Graph, then from the graph from a network. Here the code generates a random graph. User Gives n ->no. of nodes , and the prog. generates the graph with n nodes. Constraints: 1. No Self Loop 2. Each node must have atleast 3 edges 3. Each node can have at max 7 edges. ------------------------------------------------- Here is what the problem is. I have used int in all, as a result the program runs fine for an input ( n ) < 32768 . But I would like the program to run for input of an even larger number. For that i used the Replace all function of my IDE ( code::blocks) and replaced all int with long . Except the MAIN of course. No Luck. Still the program goes into infinte loop for n>32768. I Know why that happens, int resets to n when input is 32768+n . So changing it to Long should have solved the problem. I thought so. :( :( :( :( --------------------------------------------------- Now what the program does : Struct adj -> The Adjacency List. Adj shall store the node number, and the number of edges node n has, and the address of next nodes. struct nodes ->Stores the node number and the edge length (from n) and the address of next nodes. edc : Global , tracks how many nodes has atleast 3 edges. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Function : randomed : Generates Random no. based on lower bound a, upper bound b ( for the edge length ); checknd : checks whether a node exists in the list, if not adds it, else discards it. disp : outputs the adjacency list to a file. -=-=-=-=-=-=--=-=-=-=-=-=-=-=-=- #include<iostream>I would really like to know how can i make this program accept and run with bigger input. :) Your time reading my post is most appreciated. Thanks a lot for your time. Regards MiniGWeek |
| ||
| Re: Randomly Generated Network you are using a 16 bit compiler. which one? |
| ||
| Re: Randomly Generated Network I am using Code::Blocks editor, and the minigw compiler that comes along with it. ALso Just tested it with Visual CPP Express Edition 2005 , same problem. |
| ||
| Re: Randomly Generated Network lol My dilemma is solved. here is why the above was not working for an input greater than 32768 .. because rand() is a pseudorandom number generator between the seed [ set by srand() or the default if u do nt use srand() ] and RAND_MAX . RAND_MAX is an integer constant defined in cstdib. Its value is 32767. As a result all the nodes randomly generated , lied between 32678. it seems i need to define my own function usinf rand() such that for an input greater than 32768 , it caters to that. Thank u all for dropping by :) |
| All times are GMT -4. The time now is 6:45 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC