Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some problem with atypical graph #125

Open
Paulo-21 opened this issue Mar 25, 2024 · 4 comments
Open

Some problem with atypical graph #125

Paulo-21 opened this issue Mar 25, 2024 · 4 comments

Comments

@Paulo-21
Copy link

Hello,

I have some trouble with your librairy with graph like this one :

Node(0).
Node(1).
Node(2).
Node(3).
Node(4).
Node(5).
Node(6).
Node(7).
Node(8).
Node(9).
Node(10).
Node(11).
Node(12).
Node(13).
Node(14).
edge(12,9).
edge(11,6).
edge(5,4).
edge(12,7).

As you can see some nodes exist but aren't linked to any nodes.
I can't add them to the graph by the edges() function.
I'm also try to compute the page rank of this graph.
Is there is a trick i can do like when a node is alone it has always the same ranking or something, so that i don't have to had it it the graph ?
Or can we find a solution about that ?

Thank you

@knutwalker
Copy link
Collaborator

Hi,

I believe your situation is similar to #123 -- You want to have a certain number of nodes regardless of whether they are connected. You can use the same trick I mentioned in that issue -- adding a Vec<()> of node_count length as node_values (this doesn't have any additional memory overhead because () is a zero-sized type):

let g: DirectedCsrGraph<u32> = GraphBuilder::new()
    .edges(vec![(12, 9), (11, 6), (5, 4), (12, 7)])
    .node_values(vec![(); 15])  // <<== add a Vec<()> of size `node_count`
    .build();

assert_eq!(g.node_count(), 15);

@s1ck
Copy link
Collaborator

s1ck commented Mar 26, 2024

Thanks @Paulo-21 for opening the issue and thanks @knutwalker for sharing the workaround.

Let's add a node_count method on the builder which can be used to override the highest node id that we internally infer from the edges. I assume this is a rather common use case. wdyt?

@knutwalker
Copy link
Collaborator

Yes, sounds like a great idea

@Paulo-21
Copy link
Author

Paulo-21 commented Mar 26, 2024

Hi,

I believe your situation is similar to #123 -- You want to have a certain number of nodes regardless of whether they are connected. You can use the same trick I mentioned in that issue -- adding a Vec<()> of node_count length as node_values (this doesn't have any additional memory overhead because () is a zero-sized type):

let g: DirectedCsrGraph<u32> = GraphBuilder::new()
    .edges(vec![(12, 9), (11, 6), (5, 4), (12, 7)])
    .node_values(vec![(); 15])  // <<== add a Vec<()> of size `node_count`
    .build();

assert_eq!(g.node_count(), 15);

Yes ty, i have seen this issue and it work fine for me

Thanks @Paulo-21 for opening the issue and thanks @knutwalker for sharing the workaround.

Let's add a node_count method on the builder which can be used to override the highest node id that we internally infer from the edges. I assume this is a rather common use case. wdyt?

Perhaps knowing the total number of nodes before building the graph could increase the speed of graph creation because we don't have to reallocate memory when we encounter a node with an id higher up in the list of edges ?
I don't know how it works under the hood btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants