Implement Dijkstra Algorithm using cypher query in apache age - cypher

I have a graph named "CITIES" which contains vertices which are cities themselves and edges between those cities and there is one property on those edges which is the distance between the edges. I want to find shortest path between any 2 cities using the Dijkstra algorithm. How would I use cypher query language to do that. I am using apache age extension.

There isn't a direct approach to that. Because Dijkstra Algorithm requires a lot steps to follow and the steps changes depending on how you store the node and edges. But There is one way that you can do this in your project. There are drivers in the repo where you can connect age in some programming language. After connecting the database make query for nodes and edges and then write your own dijstkra algorithm for the shortest path.

There is not yet an in built AGE method to find the shortest path between two vertices in any algorithm be it Dijkstra, Floyd Warshall, Bellman Ford or any other.
But as you can query the vertices and edges using cypher queries. You can write Postgres functions to follow a particular algorithm and find out the shortest distance.
You can also refer the article for Postgres functions:
https://www.postgresqltutorial.com/postgresql-plpgsql/postgresql-create-function/

You can use apache-age-dijkstra python package to quickly implement dijkstra algorithm (shortest path)

Related

Find all the faces between a source and a target faces

I've used the CGAL::Surface_mesh_shortest_path before to find the exact shortest path in a topological manner. But now I want something simpler that seem to be missing from the library that is finding the logical path from one face to another, returning a list of the faces in between.
Is there any way to do it without having to implement a tree search from scratch?
CGAL offers a class Dual as a wrapper around a mesh. As the name suggests you obtain a dual graph. If your mesh has boundaries you have to filter them out with a boost::filtered_graph. Now you can run boost::dijkstra_shortest_paths. Now for any vertex the predecessor map will lead you to the source vertex.
You can find a self contained example here.
You probably can add a visitor so that you stops by throwing an exception as soon the shortest path algorithm reaches your target vertex.

Does Redis geo have the capability for storing polygon?

I followed several example about geospatial support in Redis. I tried to add POINT features to my Redis dataset without any problem, and subsequently I can query POINT names within certain radius (in meters, km, miles) of a certain coordinate (or a certain member of POINT).
The next immediate feature i need to try is POINT-in-POLYGON query. Now I am curious :
Does Redis geo have the capability for storing polygon?
If yes, does this polygon capability come as native or need another stack of software/extension?
I think it is still not possible to store polygons with redis geospatial.
But I found an article explaining how to load a custom lua script to query points (stored in redis) within a polygon. The GEOSEARCH command allows you to do that for a bounding box out of the box if it is enough for you.

Optimizing Ant Colony System for TSP

I have implemented an Ant Colony System for symmetric TSP in Java using Dorigo's paper from the following link :
http://people.idsia.ch/~luca/acs-bio97.pdf
I also adapted the following strategy:
1.while not all ants have constructed a solution, each ant moves 1 step to a new city and updates the pheromone on the edge used using Dorigo's local pheromone update.
The ant producing the shortest path globally updates the pheromone on the edges used using Dorigo's global update formula
After a number of iterations the shortest path found in all iterations is returned
Is there a way I can improve the algorithm in order to give better results ?
For Example for TSP instance ch130 found in TSPLIB the optimal solution is 6110 and my algorithm is returning the answer 6223.
My ACS so far has parameters set as those defined in Dorigo's paper
There are a few things you can do to improve your solution:
Increase the number of iterations. There is a possibility that there is no stagnation yet, and new solutions can be achieved.
Increase the parameter associated with the visibility (heuristic) function to favor exploration of other solutions.
Have a look at the following two papers for more details. The first one combines ACO with a genetic algorithm to fine-tune the hyper-parameters which are used to configure ACO. The authors conclude that this method improves the convergence of ACO. The second paper use an adaptive procedure to set these parameters at runtime. As the authors claim these parameters are problem specific and depending problem which currently being solved, tunning needs to be performed to improve the convergence time of the algorithm.
Botee, Hozefa M., and Eric Bonabeau. "Evolving ant colony optimization." Advances in complex systems 1, no. 02n03 (1998): 149-159.
Stützle, Thomas, Manuel López-Ibánez, Paola Pellegrini, Michael Maur, Marco Montes De Oca, Mauro Birattari, and Marco Dorigo. "Parameter adaptation in ant colony optimization." In Autonomous search, pp. 191-215. Springer, Berlin, Heidelberg, 2011.
I guess the most straight forward way to improve the performance would be integrating with a local search method, e.g. 2-opt, 3-opt, and Lin-Ker heuristic. In practice, with the integration of these local search methods, a not very big scale TSP, e.g. ch130 can solve to the optimum easily.

how to fix neighbor relationship of newly created tetrahedron after Bowyer-Watson point insertion

I'm implementing Bowyer-Watson point insertion algorithm and I'm wondering if there is any better way to fix neighbor relationship of newly created tetrahedron after a point is inserted.
One possible solution may be every tetrahedron that sharing the inserted point search its neighbor by comparing if there are 3 points are same between two tetrahedrons. But this solution seems slow, I don't know how CGAL implement this. Any ideas?
UPDATE:
the pseudocode of Bowyer-Watson: http://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm
In my opinion your algorithm and the bowyer-watson incremental are the fastest. You can try a point-in polygon test but its very complicated. For example you can search for rectangles and then use a point-in polygon test. Or you can try hierarchical point-in-polygon like the kirkpatrick data structure but it's a very difficult problem.

Table Structure for a Map system like Fallensword

I need help to structure a Map system like fallensword.com. Basically, there are different maps you can move around on. (You choose a map you start on then you can move around) And on the map there are for example caves, that you can enter, and you get on another map, etc.
How do I structure that SQL? I guess I need a x/y colum, but then what. What more should I have, there are sometimes NPC (that you attack) and sometimes NPC that you get a quest from, and sometimes, a house/cave or something (you can enter/get quest out of)
Any ideas?
A kd tree or a quadtree can help you much to solve your problem. A quadtree reduces the 2d complexity to a 1d complexity. It's used in many maps applications like bing or google maps. A good start is Nick's spatial index quadtree hilbert curve blog. You can use mysql with a spatial index but if you want to write a game this isn't the right place to ask. There is game.stackexchange.