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

Directional Edges #77

Open
devedse opened this issue Feb 21, 2024 · 3 comments
Open

Directional Edges #77

devedse opened this issue Feb 21, 2024 · 3 comments

Comments

@devedse
Copy link

devedse commented Feb 21, 2024

Hello, I was trying to use your graph library to find the shortest way between multiple recipes.

It's for the following game:
https://neal.fun/infinite-craft/

The idea is that you can combine words to form other words. E.g.:
Fire + Water = Steam

And then:
Earth + Steam = Mud

I have created a Graph using your library which I'd like to use to find out what Path I should take.

The graph now uses intermediate nodes:
Earth => Earth+Steam => Mud
Steam => Earth+Steam

What I want is to have this directional though. Because you can not go from Mud back to Earth.

Is there a way to inform the Dijkstra shortest path finder to only use edges in a specific direction?

P.s. if you're interested in looking at my code / helping me solve it I can give you access. The repo is currently private.

@Kemsekov
Copy link
Owner

Kemsekov commented Feb 24, 2024

Hello!

Each path finding algorithm have a PathType parameter.

You can see more detailed example here.

https://github.com/Kemsekov/GraphSharp.Samples/blob/main/samples%2FFindPathByMeetInTheMiddle%2FProgram.cs

In general you just invoke methods trough Do object.

var paths = G.Do.FindShortestPathsDijkstra(sourceNodeId,e=>1,pathType:PathType.OutEdges);

var pathToNode = paths.GetPath(targetNodeId);

sourceNode is start of the path

targetNode is end of the path

e=>1 is function to get weight of the edge

PathType.OutEdges is how algorithm build path, so with out edges it will build paths only by directed edges from previous node to next, so if a->b then this pair a->b can be in a path

@devedse
Copy link
Author

devedse commented Feb 24, 2024

I don't see the PathType parameter, but I do see the bool undirected. When checking out the code it seems to do the same.

Thanks for the explanation :).

I'm still playing around with the graph a bit on how I can somehow visualize it as the visualization I tried to copy over from one of the samples doens't really work for me.

It seems to put everything in the bottom left corner:
image

But I probably need to write an algorithm for automatic positioning of my graph nodes, or is that also included in the library?

@Kemsekov
Copy link
Owner

Kemsekov commented Feb 24, 2024

Yeah, I believe you just using old version of library.

I strongly recommend you to update to last nuget version.

I will not lie - I was developing this library for my daily use and it is not backwards compatible.

I will add readme to samples library with institutions how to run so you could play around with it and see how it works.

And about positioning;
Use Arrange method - it will try to assign 2d positions to nodes so distance between them will match weight of edges between them.

I don't have documentation for this project, but I have samples that are small enough and could be run to understand how to work with library.

I will update readme for samples RN
https://github.com/Kemsekov/GraphSharp.Samples

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

2 participants