Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Edge weights cannot be non integers #72

Open
Xiuyu-Li opened this issue Oct 11, 2020 · 2 comments
Open

Edge weights cannot be non integers #72

Xiuyu-Li opened this issue Oct 11, 2020 · 2 comments
Labels

Comments

@Xiuyu-Li
Copy link

Xiuyu-Li commented Oct 11, 2020

It seems like the nxmetis.partition cannot run on graph with edge weights that are not integers. Is there any suggestion on how to deal with this issue? Thank you!

@dschult
Copy link
Member

dschult commented Oct 11, 2020

Typically, you figure out how many decimal places of accuracy you really want (for example 5).
Then you multiply by 10^5 and round to create integer values. The integer values are large, but
they allow the process to work. Any weight related results you compute should change the
units back to your original units by dividing by 10^5.

nx.set_edge_attributes(G, {e: round(wt * 1e5) for e, wt in nx.get_edge_attributes(G, "weight").items()}, "int_weight")

@Xiuyu-Li
Copy link
Author

Typically, you figure out how many decimal places of accuracy you really want (for example 5).
Then you multiply by 10^5 and round to create integer values. The integer values are large, but
they allow the process to work. Any weight related results you compute should change the
units back to your original units by dividing by 10^5.

nx.set_edge_attributes(G, {e: round(wt * 1e5) for e, wt in nx.get_edge_attributes(G, "weight").items()}, "int_weight")

Thanks for the advice! This could work with a tiny modification: need to use int(round(wt * 1e5)) instead of round(wt * 1e5) to make sure that the weights are integers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants