-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support to select different heuristics #29
Comments
Thanks for taking the time to think about this. I see two different considerations regarding performance:
|
Thanks @hjweide Will check further on 1, I doubt it is possible. Regarding 2. Yes, we prefer straight lines. We need to trade some performance for what looks nice in drawings. You can't get anymore straight then just x or y. It's really just about giving options for users to pick. I don't think we can ever have a single heuristic that looks nice to everyone. Beauty is in the eye of the beholder... Just x or y is easy to reason about. For the drawings we have, it's not just about connecting a single source and destination, there will be lots of sources, destinations and obstables, and we also want to avoid crosses. |
This makes sense. I suppose we could have a few heuristic functions implemented in C++ and let the user select one from Python by passing an argument. This wouldn't allow arbitrary heuristics, but would allow the user some flexibility without a performance penalty. I don't expect that I'll have much time to work on this soon, would you be interested in submitting a PR? I'd be happy to provide guidance if needed. |
Thanks @hjweide Yes, that was the exact approach I was thinking. Will send through a PR when ready. I wonder if also there penalty to passing more arguments to the Heuristic, the breaking ties one in particular needs to know alot more properties. Cheers |
In terms of computational overhead I think any arguments you might add are negligible compared to the I haven't thought about this in detail, but I was thinking something like:
|
I made a program to get through obstacles, and this project already brought down the python method I was using from 5 seconds to 0.05 seconds and without having to resize the original to 1/10th. If you added a heuristic that preferred going outwards for a bit first, that would make it even better because it takes a few seconds for me to turn. I appreciate your guys work. |
Not sure if outward is actually needed, you can always create some obstacles in the weights to make sure it goes outward. |
what about distance consequences for being N pixels close to borders, to encourage staying away from black pixels? |
That would be expensive to calculate inside a heuristic function, best to just add that as obstacles in the grid.
Updated, orthogonal x and y, so that it changes direction in the middle rather than at the end. For drawing good outward lines from one node to another node, check what side is the starting point:
This should give good outward lines and work well with lines coming back as well. |
Right. The heuristic is meant to eliminate bad solutions quickly to find the optimal solution faster. It is not meant to define what the optimal solution looks like. If you don't want to go near walls, raise the cost of those areas. |
Closing this as it is supported now |
Thinking to use this implementation to draw lines between connectors, which means we favour nice looking lines.
At the moment I can see it is hard coded to use Manhattan distance when diagonal support is disabled.
Is it possible to also add below heuristics and update to allow selecting the heuristic from python?
abs(current.y - goal.y)
abs(current.x - goal.x)
dx1 = current.x - goal.x
dy1 = current.y - goal.y
dx2 = start.x - goal.x
dy2 = start.y - goal.y
cross = abs(dx1dy2 - dx2dy1)
heuristic += cross*0.001
See http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html
Not sure if possible to even allow defining the heuristic in python without affecting performance.
The code change is minimal as you would know.
The text was updated successfully, but these errors were encountered: