How to construct a large graph (~1e5) that has max, min, and avg degree using the logical sparse adj matrix that computes faster. Also, how to ensure that the graph is not broken (there are no subsets of disconnected graphs in the main graph)?
1 view (last 30 days)
I have the following code for generating a small (~1e3) graph that I can control the degree of (code 1). This has n (number of nodes), min, max and avg degree as the inputs.
% dl=10; %dl=degree limit
% generating adj
disp('a is symmetric')
But then I have figured out a way to generate random graphs using a logical array that takes less time and memory to compute (code 2). This has only nodes and connectivity as the inputs.
function [a,ed] = Random_graph_genar_function_v4(nodes, connectivity)
a=a | logical(sprandsym(nodes,connectivity/nPasses));
a(1:nodes+1:end)=0; %zero the diagonal
The final code need not have connectivity, but it must have n, min, max, and avg degree as the inputs.
I would like to integrate the two. I see that degree(graph) can return the degree and I can discard the nodes that do not have the desired degree. But, I am unsure about how to ensure that the graphs that I construct have the degree between (min, max). Thanks in advance.
Also, it need not be a function, if having a function induces function call lags. I am not sure if calling the function and retrieving the values can introduce the time lag or not.