forked from Pava1n3/Grote-Opdracht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DistanceMatrix.cs
62 lines (57 loc) · 2.43 KB
/
DistanceMatrix.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Grote_Opdracht
{
public class DistanceMatrix
{
/// <summary>
/// Streamreader for AfstandenMatrix.txt.
/// </summary>
StreamReader distanceMatrixReader = new StreamReader(@"..\..\AfstandenMatrix.txt");
/// <summary>
/// Matrix/2D Array that holds all the traveling distances from and to all places.
/// </summary>
private int[,] distanceMatrix = new int[1099, 1099];
/// <summary>
/// Converts the inputfile to the DistanceMatrix.
/// </summary>
public DistanceMatrix()
{
// The first read is here because the first line is "MatrixID1;MatrixID2;Afstand;Rijtijd" and we don't need that line, by doing this we skip over it.
distanceMatrixReader.ReadLine();
string distanceMatrixRead = distanceMatrixReader.ReadLine(); // We read a line from the text file.
string[] distanceMatrixLine; // And store the seperate data from one line in this array.
// Goes over the whole text file and places each line in the array.
while (distanceMatrixRead != null)
{
// Split a string in pieces that are delimited by a semicolon (e.g. "hello;world;!" becomes an array [hello, world, !]).
distanceMatrixLine = distanceMatrixRead.Split(';');
distanceMatrix[Convert.ToInt32(distanceMatrixLine[0]), Convert.ToInt32(distanceMatrixLine[1])] = Convert.ToInt16(distanceMatrixLine[3]);
distanceMatrixRead = distanceMatrixReader.ReadLine();
}
}
/// <summary>
/// Returns the DistanceMatrix
/// </summary>
/// <returns></returns>
public int[,] GetDistanceMatrix
{
get { return distanceMatrix; }
}
/// <summary>
/// Checks the distance between two points.
/// </summary>
/// <param name="startposition">OrderID of the startingposition.</param>
/// <param name="destination">OrderID of the destination.</param>
/// <returns></returns>
public int CheckDistance(int startposition, int destination)
{
int distance = distanceMatrix[startposition, destination];
return distance;
}
}
}