public GraphNavigationState(DirectedGraph graph, Point start, Point end)
 {
     Graph = graph;
     Start = start;
     End = end;
     Visited = new List<Point>();
 }
        public void FindNearestPoint()
        {
            var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
            var nav = new GraphNavigator(graph, PointMother.ChannelSt, PointMother.ChannelSt, new RoadPathService(GetEmptyRouteCache(), new Mock<ILogService>().Object));

            var nearest = nav.FindNearestPoint(PointMother.ChannelSt);
            Assert.AreEqual(PointMother.EthelSt, nearest);
        }
 public IEnumerable<Edge> Edges(DirectedGraph graph)
 {
     return Routes.Select(r =>
         {
             return (r.From.Equals(r.To))
                 ? new Edge(new[] { r.From, r.To }, 0, 0)
                 : graph.GetEdge(r);
         });
 }
        public void GetCycles_RealRoadService()
        {
            var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
            var nav = new GraphNavigator(graph, PointMother.ChannelSt, PointMother.ChannelSt, new RoadPathService(GetEmptyRouteCache(), new Mock<ILogService>().Object));

            var cycles = nav.GetCycles();
            Assert.AreEqual(2, cycles.Count);
            AssertChannelEthelChannelCycle(cycles[0]);
            AssertBurchellBurchellCycle(cycles[1]);
        }
        public void GetCycles_FakeRoadService()
        {
            var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
            var nav = new GraphNavigator(graph, PointMother.ChannelSt, PointMother.ChannelSt, new ChannelEthelBurchellRoadService());

            var cycles = nav.GetCycles();
            Assert.AreEqual(2, cycles.Count);
            AssertChannelChannelCycle(cycles[0]);
            AssertBurchellBurchellCycle(cycles[1]);
        }
        public void DistanceBetweenTwoEdges_DelanceyBeckwith_ChannelThornlands()
        {
            var graph = new DirectedGraph(new[]
                                      {
                                          PointMother.DelanceySt, PointMother.ThornlandsRd, PointMother.BeckwithSt,
                                          PointMother.ChannelSt
                                      });
            var delanceyBeckwith = graph.GetEdge(new[] {PointMother.DelanceySt, PointMother.BeckwithSt});
            var channelThornlands = graph.GetEdge(new[] {PointMother.ChannelSt, PointMother.ThornlandsRd});

            var result = graph.DistanceBetweenTwoEdges(delanceyBeckwith, channelThornlands);
            Assert.AreEqual(4.0, result, 0.1);
        }
        public void GetCycles_FakeRoadService_NonCyclic()
        {
            var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
            var nav = new GraphNavigator(graph, PointMother.ChannelSt, PointMother.BurchellSt, new ChannelEthelBurchellRoadService());

            var cycles = nav.GetCycles();
            Assert.AreEqual(2, cycles.Count);
            Assert.AreEqual(1, cycles[0].Routes.Count);

            Assert.AreEqual(PointMother.ChannelSt, cycles[0].Routes[0].From);
            Assert.AreEqual(PointMother.BurchellSt, cycles[0].Routes[0].To);
            Assert.AreEqual(PointMother.EthelSt, cycles[1].Routes[0].From);
            Assert.AreEqual(PointMother.EthelSt, cycles[1].Routes[0].To);
        }
        public Directions Optimize(Point[] points)
        {
            DBC.Assert(points.Length > 1, "Unable to optimize a route with less than 2 points.");

            Log(points);

            if (IsSingleRouteDirections(points)) return BuildSingleRouteDirections(points);

            var graph = new DirectedGraph(points);
            var graphNavigator = new GraphNavigator(graph, points.First(), points.Last(), roadPathService);
            IList<Directions> cycles = graphNavigator.GetCycles();
            stitchingService = new StitchingService(cycles, graph);
            var stitched = stitchingService.Stitch();
            stitched.Order(points.First(), points.Last());
            return stitched;
        }
 public GraphNavigator(DirectedGraph graph, Point start, Point end, IRoadPathService roadPathService)
 {
     State = new GraphNavigationState(graph, start, end);
     this.roadPathService = roadPathService;
 }
 protected override void Do()
 {
     result = new DirectedGraph(points);
 }
 public StitchingService(IList<Directions> cycles, DirectedGraph graph)
 {
     this.cycles = cycles;
     this.graph = graph;
 }
 protected override void Given()
 {
     var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
     nav = new GraphNavigator(graph, PointMother.ChannelSt, PointMother.BurchellSt, new ChannelEthelBurchellRoadService());
 }
 protected override void Given()
 {
     var graph = new DirectedGraph(new[] { PointMother.ChannelSt, PointMother.BurchellSt, PointMother.EthelSt });
     state = new GraphNavigationState(graph, PointMother.ChannelSt, PointMother.ChannelSt);
 }