Package: apache-age-dijkstra
Implement Shortest Path (Dijkstra) with Apache AGEApache AGEis a PostgreSQL extension that provides graph database functionality. The goal of the Apache AGE project is to create single storage that can handle both relational and graph model data so that users can use standard ANSI SQL along with openCypher, the Graph query language. This repository hosts the development of the Python driver for this Apache extension (currently in Incubator status). Thanks for checking it out.Apache AGE is:Powerful-- AGE adds graph database support to the already popular PostgreSQL database: PostgreSQL is used by organizations including Apple, Spotify, and NASA.Flexible-- AGE allows you to perform openCypher queries, which make complex queries much easier to write.Intelligent-- AGE allows you to perform graph queries that are the basis for many next level web services such as fraud & intrustion detection, master data management, product recommendations, identity and relationship management, experience personalization, knowledge management and more.FeaturesShortest Path implemented using dijkstra algorithmUsed Apache AGE graph databaseInstallationRequirementsPython 3.9 or higherThis module runs onpsycopg2andantlr4-python3sudo apt-get update
sudo apt-get install python3-dev libpq-dev
pip install --no-binary :all: psycopg2Install via PIPpip install apache-age-dijkstra
pip install antlr4-python3-runtime==4.9.3Build from Sourcegit clone https://github.com/Munmud/apache-age-dijkstra
cd apache-age-python
python setup.py installView SamplesShortest Distance between citiesInstructionImportfromage_dijkstraimportAge_DijkstraMaking connection to postgresql (when usingthis docker reepository)con=Age_Dijkstra()con.connect(host="localhost",# default is "172.17.0.2"port="5430",# default is "5432"dbname="postgresDB",# default is "postgres"user="postgresUser",# default is "postgres"password="postgresPW",# default is "agens"printMessage=True# default is False)Get all edgesedges=con.get_all_edge()structure :{ v1 : start_vertex,  v2 : end_vertex, e : edge_object }Get all verticesnodes=[]forxincon.get_all_vertices():nodes.append(x['property_name'])Create adjacent matrices using edgesinit_graph={}fornodeinnodes:init_graph[node]={}foredgeinedges:v1=edge['v1']['vertices_property_name']v2=edge['v2']['vertices_property_name']dist=int(edge['e']['edge_property_name'])init_graphinit_graph[v1][v2]=distInitialized Graphfromage_dijkstraimportGraphgraph=Graph(nodes,init_graph)Use dijkstra Algorithmprevious_nodes,shortest_path=Graph.dijkstra_algorithm(graph=graph,start_node="vertices_property_name")Print shortest PathGraph.print_shortest_path(previous_nodes,shortest_path,start_node="vertices_property_name",target_node="vertices_property_name")Create Verticescon.set_vertices(graph_name="graph_name",label="label_name",property={"key1":"val1",})Create Edgecon.set_edge(graph_name="graph_name",label1="label_name1",prop1={"key1":"val1",},label2="label_name2",prop2={"key1":"val1",},edge_label="Relation_name",edge_prop={"relation_property_name":"relation_property_value"})For more information aboutApache AGEApache Incubator Age:https://age.apache.org/Github:https://github.com/apache/incubator-ageDocumentation:https://age.incubator.apache.org/docs/apache-age-dijkstra GitHub:https://github.com/Munmud/apache-age-dijkstraapache-age-python GitHub:https://github.com/rhizome-ai/apache-age-pythonLicenseApache-2.0 License