After a very long, but intensive, night, I’m happy to announce that Orient, the PHP library used to work with OrientDB, has integrated an interesting feature, an implementation of Dijkstra’s algorithm.
First of all, let me tell you that, as a pretty new implementation, I’m pretty sure a couple bugs will be spotted in the next days; second, the design of the algorithm and the entities connected to it could probably be better, so I recommend you to just take a look at the final result, ‘cause the internals will probably change a bit.
Given the following graph:
how do you calculate the best way to reach Tokio from Rome?
Ok, that’s easy, you can count with your mind when you have such a small dataset:
and as you probably already know, the simplest solution is to fly from Rome to Amsterdam To LA to Tokio: the distance is 13 (hours? 13k miles? No matter now).
(You can also reach Amsterdam via Paris, but we don’t care for the aim of this post)
The dataset grows… enter Orient
But as your dataset grows, you need to automate the process of finding shortest paths.
So, you have basically created some fixtures ( a fake graph, the one of the pictures above ), and we can finally calculate the shortest path from Rome to Tokio:
<?php$algorithm=newAlgorithm\Dijkstra($graph);$algorithm->setStartingVertex($rome);$algorithm->setEndingVertex($tokio);echo$algorithm->getLiteralShortestPath().": distance ".$algorithm->getDistance();// the real method to get the SP is $algorithm->solve(), the ones used above are for printing a nice result
which will output:
Rome - Amsterdam - Los Angeles - Tokio : distance 13
If you have suggestions and questions, feel free to ask everything here; also, if you spot a bug, pull requests are welcome.
It contains 160+ pages of content dedicated to securing web applications and improving your security awareness when building
web apps, with chapters ranging from explaining how to secure HTTP cookies with the right flags to understanding why it is
important to consider joining a bug bounty program.