Return path - Bug Algorithms - path

I am trying to develop a simple algorithm in a MBSE tool to obtain a path between a start and an end points.
Here a summary:
Example
I have all informations regarding the start and end point, as well as I know everything for each polygon points (x and y positions, distance to the next point, indexes). What I do at the moment is to check the intersection between the m-line (Start-End line) and each separate polygon line,** one at the time** and to return the intersection points sorted by distance to the start point and the index where this intersection is found. (see Picture)
I think this is similar to the Bug2 algorithm, however I know in advance all the coordinates.
I would like to obtain the green path shown in the picture: [End, E, A, 29, B, C, 53, 52, 51, D, Start]. Ideally this path is the shortest to reach the end point. The problem that I am having at the moment is that I cannot extract the path and to check the shortest distance.
Any good ideas on how I could do that? I am missing a good logic to do that. Any suggestion/articles would be really appreciated. Thanks in advance.
(I am assuming: -all point sorted in counterclockwise order -I have to followthe polygon edges, I cannot cross the polygons)
I am able to found the intersection points, and the index where the intersections are happening. This information is local for each polygons, polygons are not ordered. I have tried to slice arrays and try to merge together the coordinates, however I don't like this approach and was looking for something more clean to merge together the local informations available for each polygons and to make them a path. I have explored Dijkstra algorithm to solve the issue, but maybe there is also something else.

Related

Findings common paths in two graphs using python-networkx

I have two DiGraphs, say G and H, and I would like to count how many paths of G are part of H.
For any node pairs (src, dst) I can generate the paths between them using the 'all_simple_paths' function to get the generators:
G_gen = nx.all_simple_paths(G, src, dst)
H_gen = nx.all_simple_paths(H, src, dst)
Since the amount of paths is considerably high (the graphs have typically 100 nodes) I cannot resort to building lists etc.. (e.g. list(G_gen)) so I am wondering if there are smarter ways to deal with it. In addition, I would also like to distinguish based on the path lengths.
.. or maybe a better solution can be found with a different module ?
Thanks in advance for any help on this.
Thierry
I wonder if there is some reason why nx.intersection (see here) wouldn't work here? I'm not sure if it checks for direction under the hood but it doesn't seem to force outputs to standard Graph output either. Below might work:
# Create a couple of random preferential attachment graphs
G = nx.barabasi_albert_graph(100, 5)
H = nx.barabasi_albert_graph(100, 5)
# Convert to directed
G = G.to_directed()
H = H.to_directed()
# Get intersection
intersection = nx.intersection(G, H)
# Print info for each
print(nx.info(G))
print(nx.info(H))
print(nx.info(intersection))
which outputs:
>>> DiGraph with 100 nodes and 950 edges
>>> DiGraph with 100 nodes and 950 edges
>>> DiGraph with 100 nodes and 176 edges
The nodes are all shared in the example since the node ids are just simple integers and so they follow the same generation index. With real data I suppose your node sets might not be equivalent like here and you probably will see differences there too.
On the path lengths I'm not quite sure how you would go about that. The intersection just checks which nodes and edges are shared between two graphs and returns those that are in both, unaware of any other conditions I suspect. There might be a way to impose some additional constraints by adapting the source code with of the intersection function with some conditional checks.
I guess this doesn't check the number of paths but rather the number of edges, so I suppose you're looking for something more specific than this. But at the very least no path can exist outside of the intersection, since all shared paths must contain the same edges in both (since if an edge is missing from a path in either, it cannot exist as a path in the shared solution).
Hope this helps in some way shape or form, though I feel I've oversimplified your question quite a bit.
EDIT: Intuitively, the full solution to your question might be to simply enumerate all possible paths in the intersection.

Comsol: Infinite Element Domain module

I want to simulate a 2D heat transfer process in the subsurface on a region which is infinite on the r-direction. So, as you know, the very basic way to model this is to draw a geometry that is very long in the r direction. I have done this, and the results that I obtain is correct as in this case, the results are matched with the analytical solution. As you know, there is a capability in Comsol called infinite element domain which serves the purpose to the problem mentioned above. In this case, we need to define a limited geometry on which we want to solve the PDE, and also need to draw a small domain acting as the Infinite Element Domain. However, in this case, the results are not correct because they are not matched with the analytical solution. Is there anything that I am missing to correctly use Infinite Element Domain in comsol?
Any help or comment would be appreciated.
Edit:
I edited the post to be more specific.
Please consider the following figure where a fluid with high temperature is being injected into a region with lower temperature:
https://i.stack.imgur.com/BQycC.png
The equation to solve is:
https://i.stack.imgur.com/qrZcK.png
With the following initial and boundary conditions (note that the upper and lower boundary condition is no-flux):
https://i.stack.imgur.com/l7pHo.png
We want to obtain the temperature profile over the length of rw<r<140 m (rw is very small and is equal to 0.005 m here) at different times. One way to model this numerically in Comsol is to draw a rectangle that is 2000 m in the r-direction, and get results only in the span of r [rw,140] m:
https://i.stack.imgur.com/BKCOi.png
The results of this case is fine, because they are well-matched with the analytical solution.
Another way to model this is to replace the above geometry with a bounded one that is [rw, 140] m in the r-direction and then augment it with an Infinite Element domain that is meshed mapped, as follows:
https://i.stack.imgur.com/m9ksm.png
Here, I have set the thickness of Infinite Element to 10 m in the r-direction. However, the results in this case are not matched with the analytical solution (or the above case where Infinite Element domain was not used). Is there anything that I am missing in Comsol? I have also changed some variables with regard to Infinite Element in Comsol such as physical width or distance, but I didn't see any changes in the results.
BTW, here are the results:
https://i.stack.imgur.com/cdaPH.png

trace patterns such that each node is visited only once(eulerian path) using opencv

Here is my problem which I am trying to solve since one complete year. With no success till end of the year. I have to seek help and a concrete solutions from the stackoverflow experts.
My problem statement:
I have been working with some design patterns which I want to trace if eulerian path exist(as shown in below gifs), programmatically. Below are the patterns and the way I wanna draw them(gifs).
What I wanna achieve:
Give the design pattern images as input. I want trace the design pattern image in a single stroke as shown in the gifs(gifs animations are just examples of how the patterns is drawn in single stroke). Once I get the x and y coordinates of the image in single stroke fashion(eulerian path). I will feed those coordinates to my program to just trace those coordinates.
Thing to be noted in the animation:
1) basically its an undetected graph (the nodes being the vertices of your shapes, the edges if exists being the strokes between 2 vertices). (eulerian path)
Here are the 15 unique shapes which I used to build the patterns with:
I have more then 400 patterns(3 patterns already shown below) and till now I am not able to find a generic solution for this. I have manually got the x y coordinates of the patterns and placed it in sequence. But that is not at all scalable.
How to trace the patterns such that each node is visited only once ?:
1st kind of pattern and the way it should be drawn:
2nd kind of pattern and the way it should be drawn:
3rd kind of pattern and the way it should be drawn:
Perhaps you can look into the traveling salesman problem if your still struggling with the above. TSP visits cities only once. And if in your case each node is a crossing for your strike-through then this might help.
Check here for the python code to look at. I've checked and the print statement looks nice and structured. Well done cMinor!
Edit based on discussion: file 1, file2, file3.

Is there a counter-example for this algorithm finding the Euler Path in a Eulerian Graph?

The following is the given algorithm for finding a Euler Path in a Eulerian Graph. However, it is said that there is an counter example with less than 10 vertices. The given Eulerian Graph is undirected and every vertex has even degree and it will start and end at the same vertex.
1. Perform a DFS traversal of G and number the vertices in DFS-preorder.
2. Re-initialize all vertices and edges of G as unused.
3. Produce a cycle as follows:
Start from the vertex with preorder number 1 (computed in step 1), and
repeatedly go to the vertex with highest preorder number possible along
an unused edge.
Stop when all edges incident to the current vertex are used.
I have been trying vertices from 6 to 9 for the last 3 days and I really couldn't come up with one example. Any help is appreciated! Thank you.
It's a little pedantic based on the definition that a Euler graph is a graph where each vertex has even degrees, so what if we considered that the graph was unconnected?
A---C E---G
| | | |
B---D F---H
To run DFS on different components - there would need to be a step prior to #1 which discovers the complete graph.
The following graph would also not work as the algo would take the path: {0,3,4,7,1,3,2,1,0} missing 5,6.
I am posting this as an answer because I didnt know how to show the graph correctly in comment as you could have seen.
Well correct me if i m wrong but wont the algo be struck for following graph-
A---B
\ /
C
/ \
D---E
With DFS- C A B D E
Now as C is node number 1 we will start from it and will have to visit it again to go to other cycle.
Similar graphs with 2 or more cycles with common node will give error if what i understood of your code is correct.
PS- Can anyone tell how start newline in comment

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances.
I'd like to morph a collection of 2D points (as defined by x,y coordinates in the Euclidian plane) onto a Poincare disc, but I have no idea what the algorithm is supposed to be like. At this point I don't even know if it's possible to create a mapping between Euclidian 2-space and a Poincare disc...
Any pointers?
Goodwill,
David
You describe your data as a collection of points. But from your comments, you want to make lines in the plane still map to lines in the disk. You seem to want to preserve the "structure" of the space somehow, which is probably why you use the term "morph". I think that you want a conformal map.
There is no conformal bijection between the disk and the plane. There is such a mapping between the half-plane and the disk, and it preserves "lines", but not the kind that you want, unfortunately.
You said "I don't even know if it's possible to create a mapping" ... there are a number of mappings for you to choose from (see the Unit Disk page for an example) but there are none with all the features you seem to want.
If I understand everything correctly, the answer you get on the other forum is for the Beltrami–Klein model. Once you have that, you can get to the coordinates in the Poicare' disk with
p = b / (1 + sqrt(1 - b * b))
Where p is the vector of coordinates in the Poincare' disk (i.e. what you need) and b is the one in the Beltrami–Klein model (i.e. what you get from the other answer).

Resources