1

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 station
  • EndingStation: a directly connected ending station
  • TubeLine: the tube line connecting the named stations
  • AverageTimeTaken: the average time, in minutes, taken between the named stations
  • MainZone: the main zone of the stations
  • SecondaryZone: 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=',')
  • 1
    Please add a programming-language tag. Is all this code essential to demonstrate the problem (_having trouble converting the CSV data into a suitable graph (using NetworkX) as input for the algorithms_) ? Please see : [mre] – c0der Nov 10 '21 at 05:06

0 Answers0