I am trying to implement DFS, BFS and UCS (uniform cost search) to find routes between different train stations using this CSV file. If you open the data file with any text editor, you will see the content of the file as:
"Harrow & Wealdstone", "Kenton", "Bakerloo", 3, "5", "0"
"Kenton", "South Kenton", "Bakerloo", 2, "4", "0"
· · ·
"Bank/Monument", "Waterloo", "Waterloo & City", 4, "1", "0"
Each row in the CSV file represents a Tube “step” and is in the following format:
[StartingStation], [EndingStation], [TubeLine], [AverageTimeTaken], [MainZone], [SecondaryZone]
where:
StartingStation
: a starting stationEndingStation
: a directly connected ending stationTubeLine
: the tube line connecting the named stationsAverageTimeTaken
: the average time, in minutes, taken between the named stationsMainZone
: the main zone of the stationsSecondaryZone
: the secondary zone of the stations, which is "0" if the station is in only one zone
I have implemented the search algorithms but am having trouble converting the CSV data into a suitable graph (using NetworkX) as input for the algorithms.
I want to print information related to the search e.g. stations, cost, the number of nodes expanded, etc. How to represent a state and how to construct a new state from each station reachable from the one in the current state but not already visited in the current path so far? The code below produces an empty output when printing tube_data
? Thanks.
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
tube_data = pd.read_csv('tubedata.csv')
Graphtype = nx.Graph()
tube_data = nx.read_edgelist(tube_data, delimiter=',')