Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Become a Traffic Wizard: A Beginner's Guide to Routing Traffic with Apache AGE

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Become a Traffic Wizard: A Beginner's Guide to Routing Traffic with Apache AGE


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Introduction

If you're an aspiring web developer or system administrator, you're probably familiar with the term "traffic routing." Essentially, traffic routing refers to the process of directing users from one spot to another. In other words, it's a route directory in maps and also the backbone of how the internet works by requesting to the appropriate server or resource in a distributed computing environment.

Apache AGE is a powerful open-source software that can be used to route traffic, balance loads, and improve overall performance. However, for beginners, it can be overwhelming to know where to start with Apache AGE.

That's why I've put together this comprehensive guide to help you become a traffic routing wizard using Apache AGE. In this blog post, we'll cover the basics of traffic routing for optimizing your routing configuration. Whether you're just starting out or you're looking to improve your existing skills, this guide has something for everyone. So, let's dive in and learn how to route traffic like a pro with Apache AGE!

Background

For this guide, we'll be using the SkyTrain lines in Vancouver as our example dataset.

The SkyTrain is a rapid transit system that serves the Metro Vancouver area in British Columbia, Canada. The system consists of three lines and 53 stations, where 20 stations are served by the Expo Line, 14 by the Millennium Line, 15 by the Canada Line, 1 by both the Expo and Canada Lines, and 3 by both the Expo and Millennium Lines [1]. The SkyTrain is a popular mode of transportation for commuters and tourists alike, and it's important to find out the most efficient route in order to cut costs and time.

Skytrain and Seabus Map
Skytrain and Seabus Map (Image source)

To set up the data for the SkyTrain system, we'll need to create a dataset that contains information about each station and the connections between them. This dataset will include nodes for each station, and relationships between the nodes to represent the connections between stations.

By using the SkyTrain system as the example dataset, we can demonstrate how to set up data for a real-world traffic routing scenario. This will allow you to apply the concepts and techniques you learn to your own projects, whether you're working on a transportation system, a web application, or any other distributed computing environment.

Setting Up the Data

Let's first create a new graph to work with. We can do this by the following command:

SELECT create_graph('SkyTrain');

A graph called 'SkyTrain' has been newly created. Now we would like to create nodes and relationships to match the connections from the transit map. The CREATE clause will be used to do this.

SELECT *
FROM cypher('SkyTrain', $$
    CREATE (tss:Station {name: '22nd Street', line: ['Expo']}),
        (tna:Station {name: '29th Avenue', line: ['Expo']}),
        (abd:Station {name: 'Aberdeen', line: ['Canada']}),
        (bra:Station {name: 'Braid', line: ['Expo']}),
        (btw:Station {name: 'Brentwood Town Centre', line: ['Millennium']}),
        (bgp:Station {name: 'Bridgeport', line: ['Canada']}),
        (bch:Station {name: 'Broadway-City Hall', line: ['Canada']}),
        (bql:Station {name: 'Burquitlam', line: ['Millennium']}),
        (bur:Station {name: 'Burrard', line: ['Expo']}),
        (col:Station {name: 'Columbia', line: ['Expo']}),
        (cmb:Station {name: 'Commercial-Broadway', line: ['Expo', 'Millennium']}),
        (cqc:Station {name: 'Coquitlam Central', line: ['Millennium']}),
        (edm:Station {name: 'Edmonds', line: ['Expo']}),
        (gtw:Station {name: 'Gateway', line: ['Expo']}),
        (gil:Station {name: 'Gilmore', line: ['Millennium']}),
        (gvl:Station {name: 'Granville', line: ['Expo']}),
        (hdm:Station {name: 'Holdom', line: ['Millennium']}),
        (ilc:Station {name: 'Inlet Centre', line: ['Millennium']}),
        (jcw:Station {name: 'Joyce-Collingwood', line: ['Expo']}),
        (ked:Station {name: 'King Edward', line: ['Canada']}),
        (kgg:Station {name: 'King George', line: ['Expo']}),
        (lld:Station {name: 'Lafarge Lake-Douglas', line: ['Millennium']}),
        (lcw:Station {name: 'Lake City Way', line: ['Millennium']}),
        (lfa:Station {name: 'Langara-49th Avenue', line: ['Canada']}),
        (ldn:Station {name: 'Lansdowne', line: ['Canada']}),
        (lcn:Station {name: 'Lincoln', line: ['Millennium']}),
        (ltc:Station {name: 'Lougheed Town Centre', line: ['Expo', 'Millennium']}),
        (mss:Station {name: 'Main Street-Science World', line: ['Expo']}),
        (mdv:Station {name: 'Marine Drive', line: ['Canada']}),
        (mtn:Station {name: 'Metrotown', line: ['Expo']}),
        (mct:Station {name: 'Moody Centre', line: ['Millennium']}),
        (nnm:Station {name: 'Nanaimo', line: ['Expo']}),
        (nwm:Station {name: 'New Westminster', line: ['Expo']}),
        (ofa:Station {name: 'Oakridge-41st Avenue', line: ['Canada']}),
        (ovg:Station {name: 'Olympic Village', line: ['Canada']}),
        (pat:Station {name: 'Patterson', line: ['Expo']}),
        (pwu:Station {name: 'Production Way-University', line: ['Expo', 'Millennium']}),
        (ren:Station {name: 'Renfrew', line: ['Millennium']}),
        (rbh:Station {name: 'Richmond-Brighouse', line: ['Canada']}),
        (ryo:Station {name: 'Royal Oak', line: ['Expo']}),
        (rpt:Station {name: 'Rupert', line: ['Millennium']}),
        (sap:Station {name: 'Sapperton', line: ['Expo']}),
        (srd:Station {name: 'Scott Road', line: ['Expo']}),
        (sic:Station {name: 'Sea Island Centre', line: ['Canada']}),
        (sbl:Station {name: 'Sperling-Burnaby Lake', line: ['Millennium']}),
        (sct:Station {name: 'Stadium-Chinatown', line: ['Expo']}),
        (src:Station {name: 'Surrey Central', line: ['Expo']}),
        (tem:Station {name: 'Templeton', line: ['Canada']}),
        (vcc:Station {name: 'Vancouver City Centre', line: ['Canada']}),
        (vck:Station {name: 'VCC-Clark', line: ['Millennium']}),
        (wtf:Station {name: 'Waterfront', line: ['Canada', 'Expo']}),
        (yrh:Station {name: 'Yaletown-Roundhouse', line: ['Canada']}),
        (yvr:Station {name: 'YVR-Airport', line: ['Canada']}),
        (rbh)-[:Route {time: 2}]->(ldn)-[:Route {time: 2}]->(abd)-[:Route {time: 3}]->(bgp)-[:Route {time: 3}]->(mdv)-[:Route {time: 3}]->(lfa)-[:Route {time: 3}]->(ofa)-[:Route {time: 5}]->(ked)-[:Route {time: 2}]->(bch)-[:Route {time: 4}]->(ovg)-[:Route {time: 2}]->(yrh)-[:Route {time: 2}]->(vcc)-[:Route {time: 1}]->(wtf),
        (yvr)-[:Route {time: 2}]->(sic)-[:Route {time: 2}]->(tem)-[:Route {time: 3}]->(bgp),
        (wtf)-[:Route {time: 4}]->(bur)-[:Route {time: 1}]->(gvl)-[:Route {time: 2}]->(sct)-[:Route {time: 2}]->(mss)-[:Route {time: 3}]->(cmb)-[:Route {time: 3}]->(nnm)-[:Route {time: 2}]->(tna)-[:Route {time: 3}]->(jcw)-[:Route {time: 2}]->(pat)-[:Route {time: 1}]->(mtn)-[:Route {time: 2}]->(ryo)-[:Route {time: 3}]->(edm)-[:Route {time: 2}]->(tss)-[:Route {time: 3}]->(nwm)-[:Route {time: 1}]->(col)-[:Route {time: 4}]->(sap)-[:Route {time: 2}]->(bra)-[:Route {time: 3}]->(ltc)-[:Route {time: 2}]->(pwu),
        (col)-[:Route {time: 3}]->(srd)-[:Route {time: 3}]->(gtw)-[:Route {time: 2}]->(src)-[:Route {time: 2}]->(kgg),
        (vck)-[:Route {time: 2}]->(cmb)-[:Route {time: 2}]->(ren)-[:Route {time: 2}]->(rpt)-[:Route {time: 2}]->(gil)-[:Route {time: 1}]->(btw)-[:Route {time: 2}]->(hdm)-[:Route {time: 3}]->(sbl)-[:Route {time: 2}]->(lcw)-[:Route {time: 2}]->(pwu),
        (ltc)-[:Route {time: 3}]->(bql)-[:Route {time: 4}]->(mct)-[:Route {time: 2}]->(ilc)-[:Route {time: 3}]->(cqc)-[:Route {time: 2}]->(lcn)-[:Route {time: 1}]->(lld)
$$) AS (x agtype);

Each node created has a label called Station and two properties that are the name and line. The line property takes an array variable as the stations may belong to more than one type of line. Aliases are given to each node which are used to set the relationships between the stations with Route labels consisting a time property.

Exploring the Data

Now that we have successfully created and set up our graph, let's explore the information we can retrieve from the data.

Using the following query will display all the names of the existing stations:

SELECT *
FROM cypher('SkyTrain', $$
    MATCH (n:Station)
    RETURN n.name
$$) AS (station agtype);

All 53 station names should be outputted. If not, check that you have created the nodes and relationships correctly. Don't worry if you are encountering issues; run the query SELECT * FROM cypher('SkyTrain', $$ MATCH (n) DETACH DELETE n $$) AS (a agtype); to remove all nodes and relationships and then try setting up the data again by copying and pasting the query from the previous section.

To view station names from specified lines, run the following query:

SELECT *
FROM cypher('SkyTrain', $$
    MATCH (n:Station)
    WHERE 'Canada' IN n.line
    RETURN n.name
$$) AS (station agtype);

You will be able to view the station names that belong to the 'Canada' line. Add the AND clause to further filter the results, for example, replace the line with the WHERE clause to WHERE 'Canada' IN n.line AND 'Expo' IN n.line and you will see that only the 'Waterfront' station gets outputted.

To check which station connects to another, run the following query:

SELECT *
FROM cypher('SkyTrain', $$
    MATCH (a:Station)-[r:Route]-(b:Station)
    RETURN a.name, r.time, b.name
$$) AS (station_from agtype, time agtype, station_to agtype);

Three columns will be displayed, showing the station names from and to one another with the time it takes to travel between. You might notice that there are duplicates going to and from stations, as the query ignores the direction of the relationships, which is the favoured option in this case as a train is able to go back and forth between stations in practice.

Finding the Optimal Path

The optimal path in this case will be defined as the most time efficient path. The path with the least total travel time would be the desired selection. Running the query below will show all the paths available from 'Richmond-Brighouse' station to 'Lafarge Lake-Douglas' station.

SELECT *
FROM cypher('SkyTrain', $$
    MATCH paths = (a:Station {name: 'Richmond-Brighouse'})-[:Route*]-(b:Station {name: 'Lafarge Lake-Douglas'})
    WITH paths, relationships(paths) AS rels
    UNWIND rels AS rel
    WITH nodes(paths) AS path,
        collect(rel.time) AS times,
        sum(rel.time) AS total_time
    RETURN total_time, times, path
$$) AS (total_time agtype, times agtype, path agtype)
ORDER BY total_time;

The query searches for connections from a starting point to an end point, in this case from 'Richmond-Brighouse' station to 'Lafarge Lake-Douglas' station, and saves the information into a variable called paths. The relationships contained in the variable is stored into another vairable rels. The UNWIND clause removes the inner arrays from rels and splits them into different rows of the output, which can be referenced as rel. The nodes in the path is saved into path, the time of each route is saved into times, and the total travel time is saved into total_time, which then are returned to be displayed in the final table. Here is what the output should look like:

 total_time |                                                    times                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           path
------------+--------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 77         | [2, 2, 3, 3, 3, 3, 5, 2, 4, 2, 2, 1, 4, 1, 2, 2, 3, 2, 2, 2, 1, 2, 3, 2, 2, 2, 3, 4, 2, 3, 2, 1]             | [{"id": 1125899906842769, "label": "Station", "properties": {"line": ["Canada"], "name": "Richmond-Brighouse"}}::vertex, {"id": 1125899906842755, "label": "Station", "properties": {"line": ["Canada"], "name": "Lansdowne"}}::vertex, {"id": 1125899906842733, "label": "Station", "properties": {"line": ["Canada"], "name": "Aberdeen"}}::vertex, {"id": 1125899906842736, "label": "Station", "properties": {"line": ["Canada"], "name": "Bridgeport"}}::vertex, {"id": 1125899906842759, "label": "Station", "properties": {"line": ["Canada"], "name": "Marine Drive"}}::vertex, {"id": 1125899906842754, "label": "Station", "properties": {"line": ["Canada"], "name": "Langara-49th Avenue"}}::vertex, {"id": 1125899906842764, "label": "Station", "properties": {"line": ["Canada"], "name": "Oakridge-41st Avenue"}}::vertex, {"id": 1125899906842750, "label": "Station", "properties": {"line": ["Canada"], "name": "King Edward"}}::vertex, {"id": 1125899906842737, "label": "Station", "properties": {"line": ["Canada"], "name": "Broadway-City Hall"}}::vertex, {"id": 1125899906842765, "label": "Station", "properties": {"line": ["Canada"], "name": "Olympic Village"}}::vertex, {"id": 1125899906842782, "label": "Station", "properties": {"line": ["Canada"], "name": "Yaletown-Roundhouse"}}::vertex, {"id": 1125899906842779, "label": "Station", "properties": {"line": ["Canada"], "name": "Vancouver City Centre"}}::vertex, {"id": 1125899906842781, "label": "Station", "properties": {"line": ["Canada", "Expo"], "name": "Waterfront"}}::vertex, {"id": 1125899906842739, "label": "Station", "properties": {"line": ["Expo"], "name": "Burrard"}}::vertex, {"id": 1125899906842746, "label": "Station", "properties": {"line": ["Expo"], "name": "Granville"}}::vertex, {"id": 1125899906842776, "label": "Station", "properties": {"line": ["Expo"], "name": "Stadium-Chinatown"}}::vertex, {"id": 1125899906842758, "label": "Station", "properties": {"line": ["Expo"], "name": "Main Street-Science World"}}::vertex, {"id": 1125899906842741, "label": "Station", "properties": {"line": ["Expo", "Millennium"], "name": "Commercial-Broadway"}}::vertex, {"id": 1125899906842768, "label": "Station", "properties": {"line": ["Millennium"], "name": "Renfrew"}}::vertex, {"id": 1125899906842771, "label": "Station", "properties": {"line": ["Millennium"], "name": "Rupert"}}::vertex, {"id": 1125899906842745, "label": "Station", "properties": {"line": ["Millennium"], "name": "Gilmore"}}::vertex, {"id": 1125899906842735, "label": "Station", "properties": {"line": ["Millennium"], "name": "Brentwood Town Centre"}}::vertex, {"id": 1125899906842747, "label": "Station", "properties": {"line": ["Millennium"], "name": "Holdom"}}::vertex, {"id": 1125899906842775, "label": "Station", "properties": {"line": ["Millennium"], "name": "Sperling-Burnaby Lake"}}::vertex, {"id": 1125899906842753, "label": "Station", "properties": {"line": ["Millennium"], "name": "Lake City Way"}}::vertex, {"id": 1125899906842767, "label": "Station", "properties": {"line": ["Expo", "Millennium"], "name": "Production Way-University"}}::vertex, {"id": 1125899906842757, "label": "Station", "properties": {"line": ["Expo", "Millennium"], "name": "Lougheed Town Centre"}}::vertex, {"id": 1125899906842738, "label": "Station", "properties": {"line": ["Millennium"], "name": "Burquitlam"}}::vertex, {"id": 1125899906842761, "label": "Station", "properties": {"line": ["Millennium"], "name": "Moody Centre"}}::vertex, {"id": 1125899906842748, "label": "Station", "properties": {"line": ["Millennium"], "name": "Inlet Centre"}}::vertex, {"id": 1125899906842742, "label": "Station", "properties": {"line": ["Millennium"], "name": "Coquitlam Central"}}::vertex, {"id": 1125899906842756, "label": "Station", "properties": {"line": ["Millennium"], "name": "Lincoln"}}::vertex, {"id": 1125899906842752, "label": "Station", "properties": {"line": ["Millennium"], "name": "Lafarge Lake-Douglas"}}::vertex]
 90         | [2, 2, 3, 3, 3, 3, 5, 2, 4, 2, 2, 1, 4, 1, 2, 2, 3, 3, 2, 3, 2, 1, 2, 3, 2, 3, 1, 4, 2, 3, 3, 4, 2, 3, 2, 1] | [{"id": 1125899906842769, "label": "Station", "properties": {"line": ["Canada"], "name": "Richmond-Brighouse"}}::vertex, {"id": 1125899906842755, "label": "Station", "properties": {"line": ["Canada"], "name": "Lansdowne"}}::vertex, {"id": 1125899906842733, "label": "Station", "properties": {"line": ["Canada"], "name": "Aberdeen"}}::vertex, {"id": 1125899906842736, "label": "Station", "properties": {"line": ["Canada"], "name": "Bridgeport"}}::vertex, {"id": 1125899906842759, "label": "Station", "properties": {"line": ["Canada"], "name": "Marine Drive"}}::vertex, {"id": 1125899906842754, "label": "Station", "properties": {"line": ["Canada"], "name": "Langara-49th Avenue"}}::vertex, {"id": 1125899906842764, "label": "Station", "properties": {"line": ["Canada"], "name": "Oakridge-41st Avenue"}}::vertex, {"id": 1125899906842750, "label": "Station", "properties": {"line": ["Canada"], "name": "King Edward"}}::vertex, {"id": 1125899906842737, "label": "Station", "properties": {"line": ["Canada"], "name": "Broadway-City Hall"}}::vertex, {"id": 1125899906842765, "label": "Station", "properties": {"line": ["Canada"], "name": "Olympic Village"}}::vertex, {"id": 1125899906842782, "label": "Station", "properties": {"line": ["Canada"], "name": "Yaletown-Roundhouse"}}::vertex, {"id": 1125899906842779, "label": "Station", "properties": {"line": ["Canada"], "name": "Vancouver City Centre"}}::vertex, {"id": 1125899906842781, "label": "Station", "properties": {"line": ["Canada", "Expo"], "name": "Waterfront"}}::vertex, {"id": 1125899906842739, "label": "Station", "properties": {"line": ["Expo"], "name": "Burrard"}}::vertex, {"id": 1125899906842746, "label": "Station", "properties": {"line": ["Expo"], "name": "Granville"}}::vertex, {"id": 1125899906842776, "label": "Station", "properties": {"line": ["Expo"], "name": "Stadium-Chinatown"}}::vertex, {"id": 1125899906842758, "label": "Station", "properties": {"line": ["Expo"], "name": "Main Street-Science World"}}::vertex, {"id": 1125899906842741, "label": "Station", "properties": {"line": ["Expo", "Millennium"], "name": "Commercial-Broadway"}}::vertex, {"id": 1125899906842762, "label": "Station", "properties": {"line": ["Expo"], "name": "Nanaimo"}}::vertex, {"id": 1125899906842732, "label": "Station", "properties": {"line": ["Expo"], "name": "29th Avenue"}}::vertex, {"id": 1125899906842749, "label": "Station", "properties": {"line": ["Expo"], "name": "Joyce-Collingwood"}}::vertex, {"id": 1125899906842766, "label": "Station", "properties": {"line": ["Expo"], "name": "Patterson"}}::vertex, {"id": 1125899906842760, "label": "Station", "properties": {"line": ["Expo"], "name": "Metrotown"}}::vertex, {"id": 1125899906842770, "label": "Station", "properties": {"line": ["Expo"], "name": "Royal Oak"}}::vertex, {"id": 1125899906842743, "label": "Station", "properties": {"line": ["Expo"], "name": "Edmonds"}}::vertex, {"id": 1125899906842731, "label": "Station", "properties": {"line": ["Expo"], "name": "22nd Street"}}::vertex, {"id": 1125899906842763, "label": "Station", "properties": {"line": ["Expo"], "name": "New Westminster"}}::vertex, {"id": 1125899906842740, "label": "Station", "properties": {"line": ["Expo"], "name": "Columbia"}}::vertex, {"id": 1125899906842772, "label": "Station", "properties": {"line": ["Expo"], "name": "Sapperton"}}::vertex, {"id": 1125899906842734, "label": "Station", "properties": {"line": ["Expo"], "name": "Braid"}}::vertex, {"id": 1125899906842757, "label": "Station", "properties": {"line": ["Expo", "Millennium"], "name": "Lougheed Town Centre"}}::vertex, {"id": 1125899906842738, "label": "Station", "properties": {"line": ["Millennium"], "name": "Burquitlam"}}::vertex, {"id": 1125899906842761, "label": "Station", "properties": {"line":["Millennium"], "name": "Moody Centre"}}::vertex, {"id": 1125899906842748, "label": "Station", "properties": {"line": ["Millennium"], "name": "Inlet Centre"}}::vertex, {"id": 1125899906842742, "label": "Station", "properties": {"line": ["Millennium"], "name": "Coquitlam Central"}}::vertex, {"id": 1125899906842756, "label": "Station", "properties": {"line": ["Millennium"], "name": "Lincoln"}}::vertex, {"id": 1125899906842752, "label": "Station", "properties": {"line": ["Millennium"], "name": "Lafarge Lake-Douglas"}}::vertex]
(2 rows)

There are 2 different routes in total that can be taken. From this information, we can deduce that the optimal path takes 77 minutes using the Canada line until 'Waterfront' station, exchanging to the Expo line until 'Commercial-Broadway' station, and finally exchanging to the Millennium line until the final destination.

Efficiency may depend of different factors, whether it be cost, number of line exchanges made, and so on. Play around with the conditions to fit your specifications and see which path is the most efficient in terms of your definition!

Visualizing the Data

In this section, we will utilize AgeViewer to visualize the graphs that we have created in order to better understand the data.

Let's first view our entire map using the following query:

SELECT *
FROM cypher('SkyTrain', $$
    MATCH (n)-[r]-(m)
    RETURN n, r, m
$$) AS (n agtype, r agtype, m agtype);

The displayed graph may initially show an unorganized view of the nodes and relationships; however, by changing the layout options (or dragging each node to a specific position manually), we are able to better organize them. For this example, I have used the 'Klay' layout to view the path in a straight line.

Query Result

To view station names and their connections from specified lines, run the following query:

SELECT *
FROM cypher('SkyTrain', $$
    MATCH (n)-[r]-(m)
    WHERE 'Canada' IN n.line
    RETURN n, r, m
$$) AS (n agtype, r agtype, m agtype);

You should get a graph similar to the one below. Just like in the 'Exploring the Data' section, you will be able to view the station names that belong to the 'Canada' line, this time along with their connected routes. Add the AND clause to further filter the results, for example, replace the line with the WHERE clause to WHERE 'Canada' IN n.line AND 'Expo' IN n.line and you will see that only the 'Waterfront' station and its connections get outputted.

Query Result

Finally, running the query below will show the most optimal path from 'Richmond-Brighouse' station to 'Lafarge Lake-Douglas' station.

SELECT paths, rel
FROM cypher('SkyTrain', $$
    MATCH paths = (a:Station {name: 'Richmond-Brighouse'})-[:Route*]-(b:Station {name: 'Lafarge Lake-Douglas'})
    WITH paths, relationships(paths) AS rels
    UNWIND rels AS rel
    WITH paths AS paths,
        rel AS rel,
        collect(rel.time) AS times,
        sum(rel.time) AS total_time
    RETURN paths, rel, times, total_time
$$) AS (paths agtype, rel agtype, times agtype, total_time agtype)
ORDER BY total_time
LIMIT 1;

This query is slightly altered from the previous query in the 'Finding the Optimal Path' section. The relationships are included in the output this time, and only the top row of the result is chosen as it will be the most time efficient path.

Query Result

Conclusion

In this guide, we've explored how to route traffic using Apache AGE. We began by discussing the importance of setting up data that is relevant to a practical application, and used the SkyTrain system in Vancouver as an example dataset. We then walked through the steps involved in setting up the data, including creating nodes for each station and relationships between them to represent the connections between stations. Finally, we looked at different methods on producing and visualizing tables and graphs that will be of use upon deciding on the most optimal path.

With the skills and knowledge you've gained from this guide, you'll be well-equipped to take on any traffic routing challenge that comes your way. Start using Apache AGE today and become a traffic routing wizard!

...



๐Ÿ“Œ Become a Traffic Wizard: A Beginner's Guide to Routing Traffic with Apache AGE


๐Ÿ“ˆ 90.67 Punkte

๐Ÿ“Œ Open Routing: Facebook gibt interne Plattform fรผr Backbone-Routing frei


๐Ÿ“ˆ 28.74 Punkte

๐Ÿ“Œ Advanced Routing: Homematic IP bekommt intelligentes Routing


๐Ÿ“ˆ 28.74 Punkte

๐Ÿ“Œ How to become a full stack Reverse Engineer? A Beginner Guide!


๐Ÿ“ˆ 28.67 Punkte

๐Ÿ“Œ Age of Empires II: DE Beginner's Guide: Conquer this epic RTS


๐Ÿ“ˆ 28.35 Punkte

๐Ÿ“Œ Age Calculator Using HTML, CSS, and JavaScript: A Beginnerโ€™s Guide


๐Ÿ“ˆ 28.35 Punkte

๐Ÿ“Œ How to Be a Blockchain Programming WIZARD: Beginner to PRO


๐Ÿ“ˆ 26.9 Punkte

๐Ÿ“Œ An Age-by-Age Guide to Online Safety for Kids


๐Ÿ“ˆ 26.57 Punkte

๐Ÿ“Œ How to handle API routing with Node.js and Express [19 of 26] | Beginner's Series to Node.js


๐Ÿ“ˆ 26.1 Punkte

๐Ÿ“Œ Become an Excel Wizard With Python


๐Ÿ“ˆ 25.43 Punkte

๐Ÿ“Œ Become a color-matching wizard with this $60 sensor


๐Ÿ“ˆ 25.43 Punkte

๐Ÿ“Œ Getting started with Apache AgeDB: A Beginner's Guide


๐Ÿ“ˆ 25.15 Punkte

๐Ÿ“Œ O11y Guide: Beginner's Guide To Open Source Instrumenting Java


๐Ÿ“ˆ 25.07 Punkte

๐Ÿ“Œ A Beginner's Guide to Radix Sort: Step-by-Step Guide and Python Code


๐Ÿ“ˆ 25.07 Punkte

๐Ÿ“Œ Beginning the Beginner's series [1 of 51] | Beginner's Series to: JavaScript


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ Beginning the Beginner's series [1 of 51] | Beginner's Series to: JavaScript


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ Introduction [1 of 8] | Beginner's Series to: Dev Containers | Beginner's Series to: Dev Containers


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ What are Web APIs? [1 of 18] | Beginner's Series to: Web APIs | Beginner's Series to: Web APIs


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ What is Serverless and why is it so popular now? [1 of 16] | Beginner's Series to: Serverless | Beginner's Series to: Serverless


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ Introduction to the series [1 of 35] | Beginner's Series to: Rust | Beginner's Series to Rust


๐Ÿ“ˆ 23.47 Punkte

๐Ÿ“Œ Step-by-Step Guide to Install PostgreSQL via Package Management for Apache AGE on Ubuntu


๐Ÿ“ˆ 23.36 Punkte

๐Ÿ“Œ Apache Traffic Control Traffic Router TCP Connection Slowloris denial of service


๐Ÿ“ˆ 22.52 Punkte

๐Ÿ“Œ Apache Traffic Control Traffic Router TCP Connection Slowloris Denial of Service


๐Ÿ“ˆ 22.52 Punkte

๐Ÿ“Œ Service-Meshes: Kuma 0.3 bietet Traffic Routing


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Optimize for internet traffic with Peering Service and the routing preference option


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Routing: Zu viel Traffic verantwortlich fรผr IBM-Cloud-Ausfall


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Re-Routing Traffic, Pseudo Keyloggers, TLS Inside, LockBit, Cobalt Strike & Defender - PSW #750


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Re-Routing Traffic, Pseudo Keyloggers, TLS Inside, LockBit, Cobalt Strike & Defender - PSW #750


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Air Traffic Routing With Memgraph


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Nigerian Firm Takes Blame For Routing Google Traffic Through China


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Routing made easier with traffic camera images and more


๐Ÿ“ˆ 22.26 Punkte

๐Ÿ“Œ Ethernity Networksโ€™ solution aggregates 5G traffic and provides virtual routing within 5G DU


๐Ÿ“ˆ 22.26 Punkte











matomo