public void MultiRouteTestThreeRoutes()
        {
            //multiroute from="39 leonis" route="hip 41181,vamm,tocorii" route="bd+34 1378,hip 11693" route="lugh,brohman" jump=30
            DataSetup();
            var mr = new MultiRouteFinder();

            mr.JumpRange = 30.0F;

            var start  = EDSystemManager.Instance.Find("39 leonis");
            var routes = new List <Queue <EDSystem> >();

            var routeA = new Queue <EDSystem>();

            routeA.Enqueue(EDSystemManager.Instance.Find("hip 41181"));
            routeA.Enqueue(EDSystemManager.Instance.Find("vamm"));
            routeA.Enqueue(EDSystemManager.Instance.Find("tocorii"));
            routes.Add(routeA);

            var routeB = new Queue <EDSystem>();

            routeB.Enqueue(EDSystemManager.Instance.Find("bd+34 1378"));
            routeB.Enqueue(EDSystemManager.Instance.Find("hip 11693"));
            routes.Add(routeB);

            var routeC = new Queue <EDSystem>();

            routeC.Enqueue(EDSystemManager.Instance.Find("lugh"));
            routeC.Enqueue(EDSystemManager.Instance.Find("brohman"));
            routes.Add(routeC);

            var finalRoute = mr.Route(start, routes);

            Assert.AreEqual(9, finalRoute.Count());

            int         i    = 0;
            EDSystem    prev = null;
            RouteFinder r    = new RouteFinder();

            r.JumpRange = 30;

            while (finalRoute.Count() > 0)
            {
                var dest = finalRoute.Dequeue();
                Console.Write($"{i} {dest.name}");
                if (prev != null)
                {
                    var distance = Astrogation.Distance(prev, dest);
                    var jumps    = r.Route(prev, dest).Count();
                    Console.Write($" ({distance:n1} LY, {jumps:n0} jumps)");
                }
                Console.WriteLine();

                prev = dest;
                i++;
            }
        }
        public void MultiRouteTest()
        {
            DataSetup();
            var mr = new MultiRouteFinder();

            mr.JumpRange = 30.0F;

            var start  = EDSystemManager.Instance.Find("Olgrea");
            var routes = new List <Queue <EDSystem> >();

            var routeA = new Queue <EDSystem>();

            routeA.Enqueue(EDSystemManager.Instance.Find("Te Kaha"));
            routeA.Enqueue(EDSystemManager.Instance.Find("Cao Junga"));
            routes.Add(routeA);

            var routeB = new Queue <EDSystem>();

            routeB.Enqueue(EDSystemManager.Instance.Find("Carnsan"));
            routeB.Enqueue(EDSystemManager.Instance.Find("HIP 13179"));
            routes.Add(routeB);

            var finalRoute = mr.Route(start, routes);

            Assert.AreEqual(6, finalRoute.Count());

            int         i    = 0;
            EDSystem    prev = null;
            RouteFinder r    = new RouteFinder();

            r.JumpRange = 30;

            while (finalRoute.Count() > 0)
            {
                var dest = finalRoute.Dequeue();
                Console.Write($"{i} {dest.name}");
                if (prev != null)
                {
                    var distance = Astrogation.Distance(prev, dest);
                    var jumps    = r.Route(prev, dest).Count();
                    Console.Write($" ({distance:n1} LY, {jumps:n0} jumps)");
                }
                Console.WriteLine();

                prev = dest;
                i++;
            }
        }
Exemplo n.º 3
0
        public int Execute()
        {
            if (string.IsNullOrEmpty(_start))
            {
                throw new InvalidOperationException("_start has not been set");
            }
            if (_routes.Count() == 0)
            {
                throw new InvalidOperationException("No routes have been set");
            }
            if (_range <= 0)
            {
                throw new InvalidOperationException("No jump-range has been set");
            }

            // Build a list of routes with actual systems in them.
            var sw = new Stopwatch();

            sw.Start();
            var routes = new List <Queue <EDSystem> >();

            foreach (var route in _routes)
            {
                var r = new Queue <EDSystem>();
                foreach (var sys in route)
                {
                    r.Enqueue(EDSystemManager.Instance.Find(sys));
                }
                routes.Add(r);
            }

            var mrf = new MultiRouteFinder();

            mrf.JumpRange = _range;
            var start      = EDSystemManager.Instance.Find(_start);
            var finalRoute = mrf.Route(start, routes);

            // var finalRoute = ClosestNeighbourRoute(routes);
            sw.Stop();

            Console.WriteLine($"Path found jumps. Took {sw.Elapsed.ToString()}");
            var      i = 0;
            EDSystem previousSystem = null;

            while (finalRoute.Count() > 0)
            {
                var   system       = finalRoute.Dequeue();
                float jumpDistance = -1;

                if (previousSystem != null)
                {
                    jumpDistance = Astrogation.Distance(previousSystem, system);
                }

                Console.Write($"{i:n0} {system.name}");
                if (jumpDistance >= 0)
                {
                    Console.Write($" ({jumpDistance:n1} LY)");
                }
                Console.WriteLine();

                i++;
                previousSystem = system;
            }


            //// Pick the starting route based on closest-first-stop
            //var router = new RouteFinder();
            //router.JumpRange = _range;

            //Queue<EDSystem> first;
            //int distance = int.MaxValue;
            //foreach(var route in routes)
            //{
            //    var p = router.Route(start, route.Peek());
            //    if(p.Count() < distance)
            //    {
            //        distance = p.Count();
            //        first = route;
            //    }
            //}

            //throw new NotImplementedException();
            return(0);
        }