Shortest route between 2 cities

From: Date: Tue, 19 Jun 2001 04:44:15 +0000
Subject: Shortest route between 2 cities
Groups: php.general 
Request: Send a blank email to php-general+get-54326@lists.php.net to get a copy of this message
Greetings All! I'm looking for a code which will find the shortest route between 2 cities, with data being stored in SQL tables listed below. Anyone has coded such a task ever? The most know algorithm for this is called Dijkstra's algoritm. Is there anyone with math skills enough to code this? This will be sure a big asset for our PHP community as any site dealing with some shippment/ticket/route problems will require such code. I'm including the structure of tables used. CREATE TABLE Cities ( cityID int(4) unsigned NOT NULL auto_increment, cityName varchar(20) NOT NULL, PRIMARY KEY (cityID), UNIQUE cityID (cityID, cityName) ); INSERT INTO Cities VALUES ( '1', 'A'); INSERT INTO Cities VALUES ( '2', 'B'); INSERT INTO Cities VALUES ( '3', 'C'); INSERT INTO Cities VALUES ( '4', 'D'); INSERT INTO Cities VALUES ( '5', 'E'); INSERT INTO Cities VALUES ( '6', 'F'); INSERT INTO Cities VALUES ( '7', 'G'); INSERT INTO Cities VALUES ( '8', 'H'); INSERT INTO Cities VALUES ( '9', 'I'); CREATE TABLE CityMatrix ( matrixID int(4) unsigned NOT NULL auto_increment, SourceCityID int(4) unsigned DEFAULT '0' NOT NULL, DestinationCityID int(4) unsigned DEFAULT '0' NOT NULL, Distance int(5) unsigned DEFAULT '0' NOT NULL, Fare int(4) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (matrixID), UNIQUE matrixID (matrixID) ); # Dumping data for table 'CityMatrix' INSERT INTO CityMatrix VALUES ( '1', '1', '4', '5', '10'); INSERT INTO CityMatrix VALUES ( '2', '3', '4', '50', '5'); INSERT INTO CityMatrix VALUES ( '4', '5', '7', '85', '8'); INSERT INTO CityMatrix VALUES ( '5', '1', '3', '70', '4'); INSERT INTO CityMatrix VALUES ( '6', '9', '6', '39', '6'); INSERT INTO CityMatrix VALUES ( '7', '8', '4', '10', '1'); -- Vahan Yerkanian vp.technical@abideweb.com Vice President, Design & Development Website @ http://www.abideweb.com/ AbideWeb Technologies, LLC Phone +3741 238650 | Mobile +3749 416358

« previous php.general (#54326) next »