I am currently building an an application in C# which helps students use and understand the algorithms in the D1 module of my Maths A-Level course as part of my COMP4 project.
A portion of these algorithms use graphs which need to be inputted as a distance matrix, then a true scale isomorphic graph needs to be drawn onto a windows form. As shown in the diagram linked below.
https://www.dropbox.com/s/k5sl2y98pml8mji/DistanceMatrix.png?dl=0
For the sake of simplicity assume you have the following functions
DrawLine(int aX, int aY, int bX, int bY) : void
// Draws line to screen given start and end points.
DrawNode(int x, int y) : void
// Draws node circle to screen given x and y co-ordinates of centre of circle.
So I started by representing the distance matrix in classes
public class Node : DataItem , INode
{
public IList<IArc> Arcs { get; set; }
public Node(string nodeName, IList<IArc> nodeNeighbors)
{
this.Name = nodeName;
Arcs = nodeNeighbors;
}
public Node(string nodeName)
{
this.Name = nodeName;
Arcs = new List<IArc>();
}
}
public class Arc : DataItem, IArc
{
public Arc(string arcName, decimal arcWeight, INode destinationNode)
{
this.Magnitude = arcWeight;
this.Name = arcName;
this.DestinationNode = destinationNode;
}
public INode DestinationNode { get; set; }
}
public class DataItem : IDataItem
{
public string Name { get; set; }
public decimal Magnitude { get; set; }
}
public class GraphDataSet<TNode> : DataSet<TNode>, IGraphSet<TNode> where TNode : INode
{
public int NumberOfNodes { get; set; }
public GraphDataSet(decimal[,] distanceMatrix, int NumberOfNodes)
{
for (int i = 0; i < NumberOfNodes; i++)
{
TNode NodeToAdd = default(TNode);
NodeToAdd.Name = Convert.ToString(i);
}
for (int i = 0; i < NumberOfNodes; i++)
{
for (int j = 0; j < NumberOfNodes; j++)
{
if (distanceMatrix[i, j] != 0)
{
INode Destination = GetItem(i);
GetItem(i).Arcs.Add(new Arc(i + ":" + Destination.Name ,distanceMatrix[i, j], Destination));
}
}
}
}
}
I have got to this point and ensured that inputted data is represented correctly but now I am not sure where to go in terms of actually drawing the item to the screen.
I have considered different strategies such as having an off screen drawing kind of queue where the details are drafted to. An exception is thrown if collisions occur or if the graph starts going off screen, but cannot see it working in the long run.
If it makes any difference in terms of language features I am using c#.net with framework version limited to 4.0.3 (due to college computers).
I am happy to use an external library if the problem is too complex in this context but would prefer to use my own code if possible.
All suggestions and advice welcome.