Recent content by valesdn

  1. V

    Why does not this Erdos-Renyi C code work?

    This function returns the printf, where there is all information about the connection of all nodes with a selected one (source). However I should find only the nearest neighbours and possibile consider a directed graph. Sorry, Willem: what should it be into the loop? Because I didn't...
  2. V

    Why does not this Erdos-Renyi C code work?

    dfs(i) is the depth first search function. I would like to find the neighbourhood of a node(my source). However it doesn't work, because it prints all the numbers and not only the neighbours of a selected vertex.
  3. V

    Why does not this Erdos-Renyi C code work?

    Thank you, Willem. I didn't understand what you mean about the CONNECTIVITY. Yes, you have supposed right about neighbour: a node can have more than one neighbour. The probability of edges may change. If I consider the following dfs function, I don't find the only nearest neighbour of my code...
  4. V

    Why does not this Erdos-Renyi C code work?

    Thank you, Mark44 for your reply. It doesn't compile the adjacency matrix: the indices of the matrix are the edges between the nodes, but I didn't want to do that. I wanted something 'cleaner' and elegant, like an adjacency list or matrix in order to calculate the fitness (...but I don't know...
  5. V

    Why does not this Erdos-Renyi C code work?

    Homework Statement I need to write an Erdos-Renyi random graph, by using the adjacency matrix (or alternatively list) and calculate the fitness of the graph. Definition: G(n, p) is a random graph with n vertices where each possible edge has probability p of existing.Homework Equations The...
  6. V

    Long idum in Modeling Financial Market

    Thank you so much, Mark44, for helping me.
  7. V

    Long idum in Modeling Financial Market

    Thank you so much, Mark. Actually I have this part of code that I want to "translate" in C: for(i = 0; i < DIM; i++){ if(ran2(&idum) <CONNECTIVITY){ j = ran2(&idum)*DIM; if(i != j ){ matrix[i][j] = 1...
  8. V

    Long idum in Modeling Financial Market

    Thank you, Mark, for your help. So what can I do if I want to select randomly a new neighbour or vertex (after I have fixed another to attach it)? What should the condition (if/for) be?
  9. V

    Long idum in Modeling Financial Market

    Thanks for your reply. I need to create a directed graph where I fix a vertex and then I randomly select a new neighbour that it will be linked with the 'fixed vertex'. And so on, in order to create a connected graph. That's all ;) I tried to create a directed graph and my code currently is...
  10. V

    Long idum in Modeling Financial Market

    Thank you, FactChecker. I know: my code is bad written, but it is working, anyway. However, I am having some trouble selecting a vertex of my graph in order to randomly select a neighbour. I tried to write this function: void random_matrix() { double value; int i, j; float...
  11. V

    Long idum in Modeling Financial Market

    Thank you for your prompt reply, FactChecker. I read the attached link. However, I don't understand where I should put rand() in my code, considering that I need to select a vertex which randomly selects a new possible neighbour. And finally, I should calculate the probability of switching from...
  12. V

    Long idum in Modeling Financial Market

    What I need is a vertex which randomly select a new possible neighbour. I would like to calculate the probability of switching from the old neighbour, k, to the new selected one. Any advices would be greatly appreciated :)
  13. V

    Long idum in Modeling Financial Market

    [Edit]: Maybe I have finally written a code that is working! #include <stdio.h> #include <stdlib.h>/* Adjacency matrix */int V, E, visited[15], graph[15][15]; void dfs(int i) { int j; visited[i]=1; printf("%d",i+1); for(j=0;j<V;j++) {...
  14. V

    Long idum in Modeling Financial Market

    Hello Mark, I tried to re-write my C code. It doesn't work anyway, so I think there is something wrong. I have unexpectedly no error messages. Could you please check it and tell me where errors are? Many thanks. My goal is to build an undirected graph. #include <stdio.h> #include <stdlib.h>...
  15. V

    Long idum in Modeling Financial Market

    Thank you, Mark. Yes, I know that there are several other problems with my code. I will check them asap and I will add your advices on the rand() and stand() functions.