Exemple #1
0
        private IDictionary <string, E> mapWithEdges;    // lazy loaded

        protected GraphGenericsImpl(
            IList <E> edges,
            GraphEdgesValidationDesired graphEdgesValidationDesired
            )
        {
            this.edges = new ReadOnlyCollection <E>(edges);
            if (graphEdgesValidationDesired == GraphEdgesValidationDesired.YES)
            {
                GraphEdgesValidator <PathGenerics <E, V, W>, E, V, W> .ValidateEdgesForGraphCreation <PathGenerics <E, V, W>, E, V, W>(this.edges);
            }
        }
Exemple #2
0
        private void VerifyExpectedResults(IList <Edge> edges)
        {
            // the parameter GraphEdgesValidationDesired.NO will be used so therefore do the validation once externally here first
            GraphEdgesValidator <Path, Edge, Vertex, Weight> .ValidateEdgesForGraphCreation <Path, Edge, Vertex, Weight>(edges);

            ExpectedPath[] expectedPaths = GetExpectedPaths();

            IList <PathFinderFactory> pathFinderFactories = PathFinderFactories.CreatePathFinderFactories();

            foreach (PathFinderFactory pathFinderFactory in pathFinderFactories)
            {
                VerifyExpectedPaths(a, d, edges, pathFinderFactory, expectedPaths);
            }
        }
Exemple #3
0
        private static void PerformRoadRoutingForTheImplementations(
            IList <Road> roads,
            City startCity,
            City endCity,
            IList <PathFinderFactoryGenerics <PathFinderGenerics <PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality>, PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality> > pathFinderFactories
            )
        {
            // the parameter GraphEdgesValidationDesired.NO will be used so therefore do the validation once externally here first
            GraphEdgesValidator <PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality> .ValidateEdgesForGraphCreation <PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality>(roads);

            foreach (PathFinderFactoryGenerics <PathFinderGenerics <PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality>, PathGenerics <Road, City, WeightDeterminedByRoadLengthAndQuality>, Road, City, WeightDeterminedByRoadLengthAndQuality> pathFinderFactory in pathFinderFactories)
            {
                PerformRoadRouting(roads, startCity, endCity, pathFinderFactory);
            }
        }
Exemple #4
0
        /**
         * Overloaded method. Note that the last parameter can be null if we only want to compare
         * results from different implementations.
         * The second last parameter is used when we also have an expected path retrieved for example from an xml file.
         * The last parameter can be used temporarirly for "debugging" purposes when we want to display the results to the console
         * See comment at class level.
         */
        public void AssertExpectedResultsOrAssertImplementationsWithEachOther(
            IList <Edge> edgesForBigGraph,
            Vertex startVertex,
            Vertex endVertex,
            int numberOfPathsToFind,
            IList <PathFinderFactory> pathFinderFactoriesForImplementationsToTest,
            IList <Path> expectedListOfPaths,
            string optionalPathToResourceXmlFile,
            bool shouldTestResultsWithImplementationsAgainstEachOther = false
            )
        {
            // TODO: clean up this method e.g. regarding "shouldAlsoTestResultsWithImplementationsAgainstEachOther"
            //this.SetConsoleOutputDesired(ConsoleOutputDesired.TIME_MEASURE);
            string messagePrefixWithInformationAboutXmlSourcefileWithTestData = optionalPathToResourceXmlFile == null ? "" : "Xml file with test data: " + optionalPathToResourceXmlFile + " . ";

            output("Number of edges in the graph to be tested : " + edgesForBigGraph.Count);
            IDictionary <string, IList <Path> > shortestPathsPerImplementation = new Dictionary <string, IList <Path> >();

            // the parameter GraphEdgesValidationDesired.NO will be used so therefore do the validation once externally here first
            GraphEdgesValidator <Path, Edge, Vertex, Weight> .ValidateEdgesForGraphCreation <Path, Edge, Vertex, Weight>(edgesForBigGraph);

            PathParser <Path, Edge, Vertex, Weight> pathParser = PathParser <Path, Edge, Vertex, Weight> .CreatePathParserDefault(edgesForBigGraph);

            //assertThat("At least some implementation should be used", pathFinderFactoriesForImplementationsToTest.size(), greaterThanOrEqualTo(1));
            // TODO: "hamcrest" syntax similar to above java code
            Assert.That(pathFinderFactoriesForImplementationsToTest.Count >= 1, "At least some implementation should be used");
            for (int i = 0; i < pathFinderFactoriesForImplementationsToTest.Count; i++)
            {
                PathFinderFactory pathFinderFactory = pathFinderFactoriesForImplementationsToTest[i];
                output("Will now test file " + optionalPathToResourceXmlFile + " with impl " + pathFinderFactory.GetType().Name);
                TimeMeasurer tm         = TimeMeasurer.Start();
                PathFinder   pathFinder = pathFinderFactory.CreatePathFinder(
                    edgesForBigGraph,
                    GraphEdgesValidationDesired.NO                 // do the validation one time instead of doing it for each pathFinderFactory
                    );
                IList <Path> shortestPaths = pathFinder.FindShortestPaths(startVertex, endVertex, numberOfPathsToFind);
                Assert.IsNotNull(shortestPaths);
                //assertThat("At least some path should be found", shortestPaths.size(), greaterThanOrEqualTo(1));
                Assert.That(shortestPaths.Count >= 1, "At least some path should be found"); // TODO "hamcrest" syntax as java above
                output(
                    messagePrefixWithInformationAboutXmlSourcefileWithTestData
                    + "Seconds: " + tm.GetSeconds()
                    + ". Implementation: " + pathFinder.GetType().Name,
                    ConsoleOutputDesired.TIME_MEASURE
                    );
                if (isAllConsoleOutputDesired())
                {
                    DisplayListOfShortestPath(shortestPaths);
                    output("Implementation class for above and below output: " + pathFinderFactory.GetType().Name);
                    DisplayAsPathStringsWhichCanBeUsedInXml(shortestPaths, pathParser);
                }
                shortestPathsPerImplementation.Add(pathFinder.GetType().Name, shortestPaths);
            }
            IList <string> nameOfImplementations = new List <string>(shortestPathsPerImplementation.Keys);

            if (expectedListOfPaths != null)
            {
                AssertResultsWithExpectedPaths(
                    expectedListOfPaths,
                    optionalPathToResourceXmlFile,
                    shortestPathsPerImplementation
                    );
            }
            else // if(expectedListOfPaths != null) {
            if (shouldTestResultsWithImplementationsAgainstEachOther)
            {
                AssertResultsWithImplementationsAgainstEachOther(
                    optionalPathToResourceXmlFile,
                    shortestPathsPerImplementation
                    );
            }
        }