-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphBuilder.cs
30 lines (26 loc) · 1015 Bytes
/
GraphBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace ComputerNetwork.Graphs
{
public class GraphBuilder
{
public GraphBuilder(int numberOfVertices, bool isDirected)
{
NumberOfVertices = numberOfVertices;
IsDirected = isDirected;
adjacencyTable = new double[numberOfVertices, numberOfVertices];
for(var i=0; i < numberOfVertices; i++)
for (var j = 0; j < numberOfVertices; j++)
adjacencyTable[i, j] = double.PositiveInfinity;
}
public int NumberOfVertices { get; }
public bool IsDirected { get; }
private double[,] adjacencyTable { get; }
public GraphBuilder AddEdge(int sourceId, int destinationId, double weight)
{
adjacencyTable[sourceId, destinationId] = weight;
if (!IsDirected)
adjacencyTable[destinationId, sourceId] = weight;
return this;
}
public Graph ToGraph() => new Graph(adjacencyTable, IsDirected);
}
}