Commit ca9a27f2 authored by Tanmim Hanifa's avatar Tanmim Hanifa
Browse files

implemented some functions to satisfy the graph interface

parent 4f460dbb
using System;
using System.Collections.Generic;
class BrokenGraph : Graph {
public BrokenGraph() {}
public void AddNode(Node a) {}
public void AddEdge(Node a, Node b, int c) {}
public List<Node> Nodes() {
return new List<Node>();
}
public List<Node> Neighbours(Node a) {
return new List<Node>();
}
public int Cost(Node a, Node b) {
return 1;
}
public void Write() {
Console.WriteLine("You need to write a graph data structure.");
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ class Pathfind {
} else {
// First argument selects the graph
Graph graph = new BrokenGraph(); // ***** CHANGE TO YOUR GRAPH CLASS *****
Graph graph = new YellowGraph(); //Change to YellowGraph
Examples.Build(graph, g);
graph.Write();
......@@ -63,7 +63,7 @@ class Pathfind {
Node start = new Node(a);
Node goal = new Node(b);
Pathfinder finder = new AStar(); // ***** CHANGE TO YOUR SEARCH CLASS *****
Pathfinder finder = new AStar(); // ***** Change to GreedyBestFirst when completed *****
finder.SetGraph(g);
List<Node> path = finder.FindPath(start, goal);
if (path != null) {
......
File added
......@@ -18,32 +18,30 @@ class YellowGraph : Graph {
adjMatrix = new int[0,0];
}
// ADD MISSING METHODS HERE
public void AddNode (Node a)
{
public void AddNode (Node a) {
nodes.Add(a); //adds Node a to list nodes
}
public void AddEdge(Node a, Node b, int c)
{
graph.addEdge("a", "b");
public void AddEdge(Node a, Node b, int c) {
adjMatrix[a.Id,b.Id] = c; //adds cost between two nodes in the adjacency matrix to imply of a corresponding edge between the two nodes
}
public List<Node> Nodes() {
return new List<Node>();
return nodes; //returns all the nodes
}
public List<Node> Neighbours(Node a) {
return new List<Node>();
List<Node> neighbours = new List<Node>(); //creates a list nodes
return neighbours; //returns all the neighbours
}
public int Cost(Node a, Node b)
{
return -1;
public int Cost(Node a, Node b) {
if(adjMatrix[a.Id, b.Id] == 0){ //if the cost of a-b edge is 0, then there is no edge so -1 is returned
return -1;
} else
return adjMatrix[a.Id,b.Id]; //else the cost of the edge is returned
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment