i have a weighted graph that represents cities(nodes) and thier distances(weights) on a map. I want to mark two or more cities and get the city that is most in the middle of both. There might be more than one city between this middle city and the marked city but it should be the shortest path for both marked cities. Kind of the nearest neighbor from two nodes.
I searched for graph algroithms like dijkstra and geodesic graphs but i don't know how i could use those to do this task. Am i missing an important algorithm for this?
(My graph contains some node-objects with a list of edge-object each. The edge contains a float as the weight)
Related
If I understood well, the osmnx method graph_from_address generates a graph in which a node refers to the intersection of two or more streets, whereas edge refers to a single street connecting two (or more) intersections.
Following this figure, from reference[1], it seems osmnx method graph_from_address generates something like Fig 1 (b) (axial graph), rather than a connectivity graph as defined in Fig 1(c) of same reference, where streets are nodes instead of edges.
enter image description here
Is there a osmnx method to extract streets as nodes, rather than as edges?
[1] Bin Jiang (2009) Ranking spaces for predicting human movement in an urban
environment, International Journal of Geographical Information Science, 23:7, 823-837, DOI:
10.1080/13658810802022822
PS: I have not found anything equivalent in the doc
I am working on a dataset of cities and towns spread across North America with the objective of finding the shortest path between a starting point and an ending point. I decided to use the Haversine distance as my heuristic function. But, my dataset doesn't have the latitude and longitude coordinates for some of the towns that could lie in the shortest distance path. How am I supposed to calculate the heuristic in this case? Would taking the average of the heuristics of the neighboring towns make sense?
It is given that a town/city without its corresponding coordinates cant be the starting point or the ending point.
Is there a different heuristic I should be considering instead of the Haversive distance?
If I remember correctly (don’t trust me on this!) a heuristic that returns zero for some nodes is still "legal" (in the sense that when you get to the end node, you know it’s optimal), so that would be a brutal solution. Obviously, doing this for too many nodes would wreck your search performance!
I think that interpolating between neighbour locations risks creating an inadmissible heuristic.
I am running a taxicab distance function on a list of coordinates and I would like to convert the outcome integer to a mile or km quantity. For example:
0.0117420 = |40.721319 - 40.712278| + |-73.844311 - -73.841610|
Where 0.0117420 is the output I would like to convert to mi/km. How could I go about this?
This appears to be a situation where you are trying to navigate from (40.721319, -73.844311) to (40.712278, -73.841610) where these are lat / lon pairs, and you want to navigate using a "Manhattan" routing rather than a direct great circle route.
It looks like you are considering these points as opposite corners of a "rectangle" where travel is only allowed along north, south, east and west headings to move from one point to another and where travel along the path always brings the traveler closer to the destination point.
An approximation of this is to find one of the corners of the bounding rectangle for all such paths. There are two of them, one at (40.721319, -73.841610) and the other at (40.712278, -73.844311). So, you can pick one of these and chose that as a waypoint for approximating the length each possible "Manhattan routes" between the two points. If we chose the first, you will need to calculate the distance from the starting point to the waypoint then to the destination point. Such as:
l(0) = (40.721319, -73.844311)
l(1) = (40.721319, -73.841610)
l(2) = (40.712278, -73.841610)
Using the Haversine equations we see the distance from l(0) to l(1) is approximately 0.2276km and the distance from l(1) to l(2) is approximately 1.005km making the entire route about 1.2326km.
This is approximately the length of any "Manhattan route" you pick where the distance is strictly decreasing along the path taken between the two points. There are also some errors due to the curvature of the Earth, but for points this close to each other and so distant from either of the poles, this should be good enough for most applications.
I am trying to compute a Voronoi tesselation in 2D with the Manhattan distance in R.
Ideally this would be a function that takes a set of two-dimensional points and outputs a list of polygons that partition the space. I am not certain what representations of Voronoi tesselations are standard.
There are of course many ways to do this with the Euclidean metric (packages like deldir and qhull make this very easy), but I haven't found a way to do this for the manhattan distance. A search using sos's findFn('voronoi') also yielded no results.
Info: taxicabgeometry.net
Interactive: Manhattan-metric Voronoi diagram(Click version)
I've been rolling my own in python, and can sum up the basics here:
Between neighboring centroids is a perpendicular line, in manhattan metric - two rays and a 45 degree diagonal most likely, if the centroids are randomly generated, but a straight horizontal, vertical, or 45 degree diagonal line may also occur. Given a set of such lines for every centroid pair, the edges separating the regions are among them. Collect intersect points of each pair of lines which are equal-distant (within an epsilon), in manhattan metric, to it's 3 nearest centroids. Also collect the two mid points of the 45 degree diagonal which are similarly equal-distant to their nearest two centroids. The outer polies won't be closed. How to deal with them depends on what you need. The poly borders and border verts will need sorting, so your polies aren't a zigzagged mess. Winding order can be determined if they should be clockwise or other. More can be done, just depends on what you need.
Unfortunately, this gets exponentially slower the more points are involved. The intersecting of every bisector to every other bisector is the bottleneck. I've been attempting an insertion method, with some success, but . Now I'm thinking to try first creating a nearest-neighbor linkage between the centroids. If the neighbors are known, the bisectors to intersect will be minimal, and many centroids can be computed quickly.
Anyway, the brute-force approach does work:
The point near the cursor is actually 2 points of a tiny diagonal. It's a precise method, but more complicated than it first seems. The java code from the interactive link above may be faster, but was difficult to get solid and precise geometry from.
Sorry, I dont know R.
Maybe the question is about finding the maximum area of a square that match inside a circumcircle (of a triangle). The equation for such a square abs(x)+abs(y)=r (www.mathematische-basteleien.de/taxicabgeometry.htm). When you have a mesh of triangles the voronoi diagram is the dual.
I'll try to describe my problem as simplest as possible.
Assume I have a map where I plot as points the cities within the map. Cities are then connected by line segments representing roads, so now there's a graph with line segments that represent the euclidean distance for each road (these are the original weights).
I need to make a new graph with line segments representing the actual road lengths (new weights), while trying as much as possible to keep the original geometry unmodified.
I'm thinking metric multidimensional scaling is the way to go, but maybe there's something simpler.