コード例 #1
0
ファイル: RoutingTest.cs プロジェクト: 03July/osrmnet
 public void InitOsrmEngine_ShouldCreateOsrmObject()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
     {
         Assert.NotNull(sut);
     }
 }
コード例 #2
0
ファイル: RoutingTest.cs プロジェクト: 03July/osrmnet
        public void RoutingWithAnnotationTrue_ShouldReturnStatusOkWithValidAnnotations()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
            {
                RouteResult routeResult;
                var         result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633)
                    },
                    Annotations = true,
                }, out routeResult);

                var annotations = routeResult.Routes.SelectMany(x => x.Legs).Select(y => y.Annotation).Where(x => x != null);
                var enumerable  = annotations as IList <Annotation> ?? annotations.ToList();
                var distances   = enumerable.SelectMany(x => x.Distance);
                var nodes       = enumerable.SelectMany(x => x.Nodes);

                Assert.Equal(result, Status.Ok);
                AssertValidRoute(routeResult);

                Assert.NotEmpty(distances);
                Assert.NotEmpty(nodes);
            }
        }
コード例 #3
0
ファイル: RoutingTest.cs プロジェクト: 03July/osrmnet
 public void InitEngine_ShouldThrowOsrmnetException()
 {
     var ex = Assert.Throws <OsrmException>(() =>
     {
         using (var sut = new Osrm(_invalidEngine.EngineConfig))
         {
         }
     });
 }
コード例 #4
0
ファイル: RoutingTest.cs プロジェクト: 03July/osrmnet
 public void RoutingWithInvalidCoordinate_ShouldReturnStatusError()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
     {
         RouteResult routeResults;
         // No coordinate specified
         var result = sut.Route(new RouteParameters(), out routeResults);
         Assert.Equal(result, Status.Error);
     }
 }
コード例 #5
0
ファイル: RoutingTest.cs プロジェクト: tstaa/osrmnet
 public void RoutingWithValidStartEndCoordinate_ShouldReturnStatusOk()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
     {
         IEnumerable <RouteResult> routeResults;
         var result = sut.Route(new RouteParameters()
         {
             Coordinates = new List <Coordinate>()
             {
                 new Coordinate(28.479065, -81.463945),
                 new Coordinate(28.598181, -81.207633)
             },
         }, out routeResults);
         Assert.Equal(result, Status.Ok);
     }
 }
コード例 #6
0
 public void RoutingWithValidStartEndCoordinate_ShouldReturnStatusOk()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfigMld.EngineConfig))
     {
         RouteResult routeResult;
         var         result = sut.Route(new RouteParameters()
         {
             Coordinates = new List <Coordinate>()
             {
                 new Coordinate(28.479065, -81.463945),
                 new Coordinate(28.598181, -81.207633)
             },
         }, out routeResult);
         Assert.Equal(Status.Ok, result);
         OsrmTestAssert.AssertValidRoute(routeResult);
     }
 }
コード例 #7
0
 public void TableWithDefaultConfig_ShouldReturnGoodResultWithDurationAsDefault()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfigMld.EngineConfig))
     {
         var result = sut.Table(new TableParameters()
         {
             Coordinates = new List <Coordinate>()
             {
                 new Coordinate(28.551750, -81.450598),
                 new Coordinate(28.774844, -81.242909),
                 new Coordinate(28.636579, -81.427413)
             },
         }, out TableResult tableResult);
         Assert.Equal(Status.Ok, result);
         Assert.NotEmpty(tableResult.Durations);
     }
 }
コード例 #8
0
 //[Fact]
 public void RoutingWithValidStartEndCoordinate_ShouldReturnStatusOk()
 {
     using (var sut = new Osrm(_config.EngineConfig))
     {
         RouteResult routeResult;
         var         result = sut.Route(new RouteParameters
         {
             Coordinates = new List <Coordinate>
             {
                 new Coordinate(48.829717, 2.349566),
                 new Coordinate(48.629575, 2.472986)
             }
         }, out routeResult);
         Assert.Equal(Status.Ok, result);
         OsrmTestAssert.AssertValidRoute(routeResult);
     }
 }
コード例 #9
0
 public void TableWithAnnotationDistance_ShouldReturnDistanceOnly()
 {
     using (Osrm sut = new Osrm(_orlandoEngineConfigMld.EngineConfig))
     {
         var result = sut.Table(new TableParameters()
         {
             Coordinates = new List <Coordinate>()
             {
                 new Coordinate(28.551750, -81.450598),
                 new Coordinate(28.774844, -81.242909),
                 new Coordinate(28.636579, -81.427413)
             },
             Annotations = Osrmnet.TableService.AnnotationsType.Distance
         }, out TableResult tableResult);
         Assert.NotEmpty(tableResult.Distances);
         Assert.Empty(tableResult.Durations);
     }
 }
コード例 #10
0
ファイル: RoutingTest.cs プロジェクト: tstaa/osrmnet
        public void RoutingWithStepsTrue_ShouldReturnValidSteps()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
            {
                IEnumerable <RouteResult> routeResults;
                var result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633)
                    },
                    Steps = true,
                }, out routeResults);

                var steps = routeResults.SelectMany(x => x.Legs).Select(x => x.Steps);
                Assert.NotEmpty(steps);
            }
        }
コード例 #11
0
ファイル: RoutingTest.cs プロジェクト: 03July/osrmnet
        public void RoutingWithStepsTrue_ShouldReturnEmpty()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
            {
                RouteResult routeResult;
                var         result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633)
                    },
                    Steps = false,
                }, out routeResult);

                Assert.Equal(result, Status.Ok);
                AssertValidRoute(routeResult);
                var steps = routeResult.Routes.SelectMany(x => x.Legs).SelectMany(x => x.Steps);
                Assert.Empty(steps);
            }
        }
コード例 #12
0
ファイル: RoutingTest.cs プロジェクト: tstaa/osrmnet
        public void RoutingWithAnnotationFalse_ShouldReturnStatusOkWithEmptyAnnotations()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfig.EngineConfig))
            {
                IEnumerable <RouteResult> routeResults;
                var result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633)
                    },
                    Annotations = true,
                }, out routeResults);

                var annotations = routeResults.SelectMany(x => x.Legs).Select(y => y.Annotation).Where(x => x != null);

                Assert.Equal(result, Status.Ok);
                Assert.NotEmpty(annotations);
            }
        }
コード例 #13
0
        public void RoutingWithAnnotationFalse_ShouldReturnStatusOkWithEmptyAnnotations()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfigMld.EngineConfig))
            {
                RouteResult routeResult;
                var         result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633)
                    },
                    Annotations = AnnotationsType.All,
                }, out routeResult);

                var annotations = routeResult.Routes.SelectMany(x => x.Legs).Select(y => y.Annotation).Where(x => x != null);

                Assert.Equal(Status.Ok, result);
                OsrmTestAssert.AssertValidRoute(routeResult);
                Assert.NotEmpty(annotations);
            }
        }
コード例 #14
0
        public void RoutingWithMoreAlternateAllowed_ShouldFailWithTooBigCode()
        {
            using (Osrm sut = new Osrm(_orlandoEngineConfigMld.EngineConfig))
            {
                RouteResult routeResult;
                var         result = sut.Route(new RouteParameters()
                {
                    Coordinates = new List <Coordinate>()
                    {
                        new Coordinate(28.479065, -81.463945),
                        new Coordinate(28.598181, -81.207633),
                        new Coordinate(28.598181, -81.207633),
                        new Coordinate(28.598181, -81.207633),
                    },
                    Steps = false,
                    NumberOfAlternatives = 4
                }, out routeResult);

                Assert.Equal(Status.Error, result);
                Assert.Equal("TooBig", routeResult.Code);
            }
        }
コード例 #15
0
ファイル: Problem.cs プロジェクト: FoundOPS/TaskOptimizer
        /// <summary>
        /// Calculate the problem for a set of tasks
        /// </summary>
        /// <param name="tasksToCalculate">The tasks to calculate</param>
        /// <param name="trucks">The number of trucks</param>
        public String[] Calculate(IEnumerable<Task> tasksToCalculate, int trucks)
        {
            var tasks = tasksToCalculate.ToList();

            SendLogMessage("Problem.Calculate", "Starting calculation: Task Count = {0}; Truck Count = {1}; Iterations = {2}",
                tasks.Count, trucks, _numberIterationsWithoutImprovement);

            Osrm = new Osrm();

            SendLogMessage("Problem.Calculate", "Resolving input to OSRM nodes");
            //resolve each point on the map
            foreach (var t in tasks)
            {
                var r = Osrm.FindNearest(t.Coordinate);
                t.Coordinate = r;
            }

            SendLogMessage("Problem.Calculate", "Coordinate resolution complete!");

            if (Osrm == null) Osrm = new Osrm();

            _mCachedCosts = new int[tasks.Count(), tasks.Count()];
            var optConf = new Optimizer.Configuration { Tasks = tasks };

            var truck = new Worker();
            optConf.Workers = new List<Worker>();
            for (int t = 0; t < trucks; t++)
                optConf.Workers.Add(truck);

            optConf.RandomSeed = 777777;
            optConf.NumberDistributors = Environment.ProcessorCount * 3;

            SendLogMessage("Problem.Calculate", "Starting to create Optimizer instance..");
            var optimizer = new Optimizer(this, optConf);
            SendLogMessage("Problem.Calculate", "Finished creating Optimizer instnce!");
            Int32 i = 0;

            Int32 prevFitness = Int32.MaxValue; // Fitness of the previous iteration
            Int32 noImprovementCount = 0; // Number of iterations without fitness improvement

            //while (_optimizer.MinDistributor.NbIterationsWithoutImprovements < _numberIterationsWithoutImprovement)
            while (noImprovementCount < _numberIterationsWithoutImprovement)
            {
                optimizer.Compute();
                optimizer.RecomputeFitness();

                if (optimizer.Fitness >= prevFitness)
                    noImprovementCount++;
                else
                {
                    prevFitness = optimizer.Fitness;
                    noImprovementCount = 0;
                }

                SendLogMessage("FitnessImprovement", "Iteration = {0}; Fitness = {1}", i++, optimizer.Fitness);
            }

            optimizer.Stop();

            // Write the message to console and logs
            SendLogMessage("TaskOptimizer", "Total Fitness = {0}", optimizer.Fitness);

            string response = "{";
            int cont = 0;
            for (int r = 0; r < optimizer.MinSequences.Count; r++)
            {
                if (optimizer.MinSequences[r] == null)
                {
                    cont++;
                    continue;
                }
                SendLogMessage("TaskOptimizer", "MinSequence[r].Tasks.Count = {0}", optimizer.MinSequences[r].Tasks.Count);
                SendLogMessage("TaskOptimizer", "MinSequence[r].Fitness = {0}", optimizer.MinSequences[r].Fitness);
                response += "\"" + ((r + 1) - cont) + "\"" + ": ";

                var routeList = optimizer.MinSequences[r].Tasks.Select(t => t.Coordinate).ToList();

                if (routeList.Count > 1)
                {
                    var rawRoute = Osrm.CalculateRouteRaw(routeList);
                    Trace.WriteLine(rawRoute);
                    response += rawRoute + ",";
                }
                else
                {
                    //TODO (single stop routes cannot be calculated with OSRM)
                }
            }

            Osrm.Dispose();
            Osrm = null;

            response = response.Substring(0, response.Length - 1) + response + "}";

            return new[] { response, optimizer.Fitness.ToString() };
        }