//CONSTRUCTOR public DijkstraDraw(String[] a, int n) { SetWeights(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13]); SetNetworkNumber(n); switch (networkNumber) { case 1: DijkstraAlgorithm.BuildNetwork1(a); break; case 2: DijkstraAlgorithm.BuildNetwork2(a); break; case 3: DijkstraAlgorithm.BuildNetwork3(a); break; case 4: DijkstraAlgorithm.BuildNetwork4(a); break; } DijkstraAlgorithm.Initialize(); DijkstraAlgorithm.CreateTableValuesArray(); DijkstraAlgorithm.CreateVisitedEdges(); // crate the canvas skiaview = new SKCanvasView(); skiaview.PaintSurface += PaintSurface; currentStep = 0; maxStep = 31; }
/********************************************************************** *********************************************************************/ void DrawConnectionsNetwork3() { bool[,] visitedEgdes = DijkstraAlgorithm.GetVisistedEdges(); DrawConnection(routerX, routerU, visitedEgdes[currentStep, 1]); DrawConnection(routerX, routerW, visitedEgdes[currentStep, 11]); DrawConnection(routerX, routerY, visitedEgdes[currentStep, 12]); DrawConnection(routerU, routerV, visitedEgdes[currentStep, 0]); DrawConnection(routerV, routerX, visitedEgdes[currentStep, 8]); DrawConnection(routerV, routerW, visitedEgdes[currentStep, 10]); //DrawConnections(canvas, routerV, routerY); DrawConnection(routerW, routerY, visitedEgdes[currentStep, 13]); DrawConnection(routerW, routerZ, visitedEgdes[currentStep, 4]); DrawConnection(routerZ, routerY, visitedEgdes[currentStep, 5]); SKPoint p = new SKPoint(xPercent(0.15f), yPercent(0.6f)); SKPath curveUY = new SKPath(); curveUY.MoveTo(routerU); curveUY.CubicTo(routerU, p, routerY); if (visitedEgdes[currentStep, 3]) { canvas.DrawPath(curveUY, sk_Visited); } else { if (currentStep != maxStep) { canvas.DrawPath(curveUY, sk_RouterContour); } } }
/********************************************************************** *********************************************************************/ public static void DrawForwardingTable() { String[] a = DijkstraAlgorithm.GetForwardingTable(); canvas.DrawText(a[0], new SKPoint(xPercent(0.34f), yPercent(0.985f)), sk_TableCaption); canvas.DrawText(a[1], new SKPoint(xPercent(0.48f), yPercent(0.985f)), sk_TableCaption); canvas.DrawText(a[2], new SKPoint(xPercent(0.62f), yPercent(0.985f)), sk_TableCaption); canvas.DrawText(a[3], new SKPoint(xPercent(0.76f), yPercent(0.985f)), sk_TableCaption); canvas.DrawText(a[4], new SKPoint(xPercent(0.9f), yPercent(0.985f)), sk_TableCaption); }
/********************************************************************** *********************************************************************/ public void DrawRouters() { String[,] tableContents = DijkstraAlgorithm.GetTableValues(); String visitedNodes = tableContents[currentStep, 8]; DrawRouter(routerZ, "Z", visitedNodes.Contains('z')); DrawRouter(routerU, "U", visitedNodes.Contains('u')); DrawRouter(routerV, "V", visitedNodes.Contains('v')); DrawRouter(routerW, "W", visitedNodes.Contains('w')); DrawRouter(routerX, "X", visitedNodes.Contains('x')); DrawRouter(routerY, "Y", visitedNodes.Contains('y')); }
/********************************************************************** *********************************************************************/ void DrawConnectionsNetwork1() { bool[,] visitedEgdes = DijkstraAlgorithm.GetVisistedEdges(); DrawConnection(routerX, routerU, visitedEgdes[currentStep, 1]); DrawConnection(routerX, routerW, visitedEgdes[currentStep, 11]); DrawConnection(routerX, routerY, visitedEgdes[currentStep, 12]); DrawConnection(routerU, routerV, visitedEgdes[currentStep, 0]); //DrawConnections(canvas, routerV, routerX); DrawConnection(routerV, routerW, visitedEgdes[currentStep, 10]); DrawConnection(routerV, routerY, visitedEgdes[currentStep, 9]); //DrawConnections(canvas, routerW, routerY); DrawConnection(routerW, routerZ, visitedEgdes[currentStep, 4]); DrawConnection(routerZ, routerY, visitedEgdes[currentStep, 5]); }
/********************************************************************** *********************************************************************/ void DrawConnectionsNetwork4() { bool[,] visitedEgdes = DijkstraAlgorithm.GetVisistedEdges(); DrawConnection(routerX, routerU, visitedEgdes[currentStep, 1]); //DrawConnections(canvas, routerX, routerW); DrawConnection(routerX, routerY, visitedEgdes[currentStep, 12]); DrawConnection(routerU, routerV, visitedEgdes[currentStep, 0]); DrawConnection(routerV, routerX, visitedEgdes[currentStep, 8]); DrawConnection(routerV, routerW, visitedEgdes[currentStep, 10]); //DrawConnections(canvas, routerV, routerY); DrawConnection(routerW, routerY, visitedEgdes[currentStep, 13]); DrawConnection(routerW, routerZ, visitedEgdes[currentStep, 4]); DrawConnection(routerZ, routerY, visitedEgdes[currentStep, 5]); SKPoint p = new SKPoint(xPercent(0.15f), -yPercent(0.1f)); SKPath curveUW = new SKPath(); curveUW.MoveTo(routerU); curveUW.CubicTo(routerU, p, routerW); if (visitedEgdes[currentStep, 2]) { canvas.DrawPath(curveUW, sk_Visited); } else { if (currentStep != maxStep) { canvas.DrawPath(curveUW, sk_RouterContour); } } SKPoint p2 = new SKPoint(xPercent(0.15f), yPercent(0.6f)); SKPath curveUY = new SKPath(); curveUY.MoveTo(routerU); curveUY.CubicTo(routerU, p2, routerY); if (visitedEgdes[currentStep, 3]) { canvas.DrawPath(curveUY, sk_Visited); } else { if (currentStep != maxStep) { canvas.DrawPath(curveUY, sk_RouterContour); } } SKPoint p3 = new SKPoint(xPercent(0.85f), -yPercent(0.1f)); SKPath curveZV = new SKPath(); curveZV.MoveTo(routerZ); curveZV.CubicTo(routerZ, p3, routerV); if (visitedEgdes[currentStep, 6]) { canvas.DrawPath(curveZV, sk_Visited); } else { if (currentStep != maxStep) { canvas.DrawPath(curveZV, sk_RouterContour); } } SKPoint p4 = new SKPoint(xPercent(0.85f), yPercent(0.6f)); SKPath curveZX = new SKPath(); curveZX.MoveTo(routerZ); curveZX.CubicTo(routerZ, p4, routerX); if (visitedEgdes[currentStep, 7]) { canvas.DrawPath(curveZX, sk_Visited); } else { if (currentStep != maxStep) { canvas.DrawPath(curveZX, sk_RouterContour); } } }
/********************************************************************** *********************************************************************/ public static void DrawTableContents() { String[,] tableContents = DijkstraAlgorithm.GetTableValues(); String visitedNodes = tableContents[currentStep, 8]; for (int i = 0; i <= currentStep; i++) { // check which is the current table row and write text in this row int round = Int32.Parse(tableContents[i, 1]); float yValueContent = 0; switch (round) { case 0: yValueContent = yPercent(0.615f); break; case 1: yValueContent = yPercent(0.665f); break; case 2: yValueContent = yPercent(0.715f); break; case 3: yValueContent = yPercent(0.765f); break; case 4: yValueContent = yPercent(0.815f); break; case 5: yValueContent = yPercent(0.865f); break; } canvas.DrawText(tableContents[i, 2], new SKPoint(xPercent(0.2f), yValueContent), sk_TableCaption); canvas.DrawText(tableContents[i, 3], new SKPoint(xPercent(0.34f), yValueContent), sk_TableCaption); canvas.DrawText(tableContents[i, 4], new SKPoint(xPercent(0.48f), yValueContent), sk_TableCaption); canvas.DrawText(tableContents[i, 5], new SKPoint(xPercent(0.62f), yValueContent), sk_TableCaption); canvas.DrawText(tableContents[i, 6], new SKPoint(xPercent(0.76f), yValueContent), sk_TableCaption); canvas.DrawText(tableContents[i, 7], new SKPoint(xPercent(0.9f), yValueContent), sk_TableCaption); char visitedNodeToMark = visitedNodes[round]; yValueContent = yValueContent - yPercent(0.05f); //previous row/round // every new round/ every 7th step if (i % 6 == 0) { //overdraw the previously visited connection in red switch (visitedNodeToMark) { // v = 1st step previous row (i-5) , w = 2nd step..., x = 3rd step..., y = 4th step..., z = 5th step... case 'v': canvas.DrawText(tableContents[i - 5, 3], new SKPoint(xPercent(0.34f), yValueContent), sk_TableCaptionRed); break; case 'w': canvas.DrawText(tableContents[i - 4, 4], new SKPoint(xPercent(0.48f), yValueContent), sk_TableCaptionRed); break; case 'x': canvas.DrawText(tableContents[i - 3, 5], new SKPoint(xPercent(0.62f), yValueContent), sk_TableCaptionRed); break; case 'y': canvas.DrawText(tableContents[i - 2, 6], new SKPoint(xPercent(0.76f), yValueContent), sk_TableCaptionRed); break; case 'z': canvas.DrawText(tableContents[i - 1, 7], new SKPoint(xPercent(0.9f), yValueContent), sk_TableCaptionRed); break; } } } }