public void GenerateTestDataSet()
        {
            string path = Directory.GetCurrentDirectory();
            string suffix = @"bin\Debug";
            char[] trailingChars = suffix.ToCharArray();
            path = path.TrimEnd(trailingChars) + @"\Unpassed data\TestNodeSize";

            //for (int i = 0; i < 7; i++)
            //{

                Dictionary<int, Dictionary<int, decimal>> adjList = new Dictionary<int, Dictionary<int, decimal>>();
                int size = 50;//(int)Math.Pow(10, i + 1); //size of random graph can be ajusted, when size>1000 it will generate OutOfMemoryException
                string pathToTxt = path + size + ".txt";
                string pathToGexf = path + size + ".gexf";
                Random r = new Random();
                int startId = r.Next(1, size + 1);
                int endId = r.Next(1, size + 1);
                double density = 0.2; //density of random graph can be adjusted
                RandomGraphGenerator graph = new RandomGraphGenerator(size, density, 1, 300);
                adjList = graph.getAdjList();

                IOhelper.writeDataToFile(pathToTxt, "StartId: " + startId + "  EndId: " + endId, adjList);
                IOhelper.outPutGraphData(pathToGexf, adjList, startId, endId);
            //}
        }
Example #2
0
        public void streessTestWithWeightOf1()
        {
            int i = 0;
            while (i < 1)
            {
                Dictionary<int, Dictionary<int, decimal>> adjList = new Dictionary<int, Dictionary<int, decimal>>();
                int size = 1000;
                Random r = new Random();
                int startId = r.Next(1, size +1);
                int endId = r.Next(1, size +1);
                try
                {

                    double density = 0.2;
                    RandomGraphGenerator graph = new RandomGraphGenerator(size, density, 1, 1);
                    adjList = graph.getAdjList();
                    int withF = FindPath.shortestPathWithFibonacci(adjList, startId, endId).Count;
                    if (withF != 0)
                    {
                        withF = withF - 1;
                    }

                    int withoutF = FindPath.shortestPathWithoutFibonacci(adjList, startId, endId).Count;
                    if (withoutF != 0)
                    {
                        withoutF = withoutF - 1;
                    }

                    int leastS = FindPath.leastStopsPathWithIds(adjList, startId, endId).Count;
                    if (leastS != 0)
                    {
                        leastS = leastS-1;
                    }

                    int BFS = FindPath.breathFirstSearchWithIds(adjList, startId, endId);

                    Assert.AreEqual(withF, leastS);
                    Assert.AreEqual(withF, withoutF);
                    Assert.AreEqual(withoutF, leastS);

                    Assert.AreEqual(leastS, BFS);

                    System.Diagnostics.Debug.WriteLine(i + "");
                }
                catch (NullReferenceException e)
                {
                    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                    throw new Exception();
                }
                catch (AssertFailedException e)
                {

                    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                    throw new Exception();
                }
                i++;
            }
        }
Example #3
0
        public void stressTestForKShortestPath()
        {
            int i = 0;
            while(i<1)
            {
                Dictionary<int, Dictionary<int, decimal>> adjList = new Dictionary<int, Dictionary<int, decimal>>();
                int size = 100; //size of random graph can be ajusted
                Random r = new Random();
                int startId = r.Next(1, size + 1);
                int endId = r.Next(1, size + 1);

                double density = 0.1; //density of random graph can be adjusted
                RandomGraphGenerator graph = new RandomGraphGenerator(size, density, 1, 300);
                adjList = graph.getAdjList();

                //try
                //{
                //List<List<PathStop>> allPaths = FindPath.getAllPossiblePathsBetweenTwoPoints(adjList, startId, endId);
                    int numberOfPath = 50;
                    List<List<PathStop>> kPaths = FindPath.getKShortestPath(adjList, startId, endId, numberOfPath);

                    if (startId == endId)
                    {
                        Assert.AreEqual(1, kPaths.Count);
                        Assert.AreEqual(0, Convert.ToInt32(kPaths[0][0].driveHour));
                    }
                    else
                    {
                        int n;
                        if (kPaths.Count > numberOfPath)
                        {
                            n = numberOfPath;
                        }
                        else
                        {
                            n = kPaths.Count;
                        }
                        for (int j = 1; j < n; j++)
                        {
                            if (kPaths[j][kPaths[j].Count - 1].driveHour < kPaths[j - 1][kPaths[j - 1].Count - 1].driveHour)
                                Assert.Fail();
                        }

                        for (int j = 0; j < n; j++)
                        {
                            for (int h = 0; h < kPaths[j].Count; h++)
                            {
                                for (int x = h+1; x < kPaths[j].Count; x++)
                                {
                                    if (kPaths[j][h].stationID == kPaths[j][x].stationID)
                                    {
                                        Assert.Fail();
                                    }
                                }
                            }
                        }

                        //for (int j = 0; j < numberOfPath; j++)
                        //{

                        //    Assert.AreEqual(kPaths[j][kPaths[j].Count - 1].driveHour, allPaths[j][allPaths[j].Count - 1].driveHour);
                        //}
                    }
                    System.Diagnostics.Debug.WriteLine(i + "");
                    i++;
                //}
                //catch (ArgumentOutOfRangeException e)
                //{

                //    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                //    outPutGraphData(adjList, startId, endId);
                //    throw e;
                //}
                //catch (AssertFailedException e)
                //{

                //    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                //    outPutGraphData(adjList, startId, endId);
                //    throw e;
                //}
                Assert.AreEqual(1, 1);

            }
        }
Example #4
0
        public void streessTestWithRandomWeight()
        {
            int i = 0;
            while (i<1)//can be adjusted
            {
                Dictionary<int, Dictionary<int, decimal>> adjList = new Dictionary<int, Dictionary<int, decimal>>();
                int size = 1000; //size of random graph can be ajusted
                Random r = new Random();
                int startId = r.Next(1, size + 1);
                int endId = r.Next(1, size + 1);
                try
                {

                    double density = 0.1; //density of random graph can be adjusted
                    RandomGraphGenerator graph = new RandomGraphGenerator(size, density, 1, 300);
                    adjList = graph.getAdjList();
                    List<PathStop> routeWF = FindPath.shortestPathWithFibonacci(adjList, startId, endId);
                    decimal lastStopDistanceWF = 0;
                    if (routeWF.Count != 0)
                    {
                        lastStopDistanceWF = routeWF[routeWF.Count-1].driveHour;
                    }

                    List<PathStop> routeWoutF = FindPath.shortestPathWithoutFibonacci(adjList, startId, endId);
                    int withoutF = FindPath.shortestPathWithoutFibonacci(adjList, startId, endId).Count;
                    decimal lastStopDistanceWoutF = 0;
                    if (routeWoutF.Count != 0)
                    {
                        lastStopDistanceWoutF = routeWoutF[routeWoutF.Count - 1].driveHour;
                    }

                    Assert.AreEqual(lastStopDistanceWF, lastStopDistanceWoutF);
                    System.Diagnostics.Debug.WriteLine(i + "");

                }
                catch (NullReferenceException e)
                {
                    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                    outPutGraphData(adjList, startId, endId);
                    throw e;
                }
                catch (AssertFailedException e)
                {

                    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                    outPutGraphData(adjList, startId, endId);
                    throw e;
                }

                catch (IndexOutOfRangeException e)
                {

                    writeDataToFile(e.Message + "Start: " + startId + "  End: " + endId, adjList);
                    outPutGraphData(adjList, startId, endId);
                    throw e;
                }
                catch(OutOfMemoryException e)
                {
                    throw e;
                }
                i++;
            }
        }