Beispiel #1
0
 /// <summary>
 /// Starts a new route to a given goal StreetConnector.
 /// </summary>
 /// <param name="goal">The goal StreetConnector</param>
 public void StartNewRoute(StreetConnector goal)
 {
     goalConnector = goal;
     if (goal == currentConnector)
     {
         currentRoutingState = RoutingState.Finished;
         return;
     }
     baseRoute = RouteManager.GetBestBaseRoute(currentConnector, goal);
     if (baseRoute == null)
     {
         specialRoute        = RouteManager.GetSpecialRoute(currentConnector, goal);
         currentRoutingState = RoutingState.SpecialStart2;
     }
     else
     {
         if (baseRoute.Start == currentConnector)
         {
             currentRoutingState = RoutingState.BaseStart;
         }
         else
         {
             specialRoute        = RouteManager.GetSpecialRoute(currentConnector, baseRoute.Start);
             currentRoutingState = RoutingState.SpecialStart1;
         }
     }
 }
        public void Test_SingleStreetHubDistance()
        {
            SpecialRoute           route;
            StreetConnector        connector1, connector2;
            StreetConnector        start, end;
            List <StreetConnector> waypoints = new List <StreetConnector>();

            connector1 = start = StreetMapManager.Data.StreetConnectors(0);
            connector2 = end = StreetMapManager.Data.StreetConnectors(5);

            route = new SpecialRoute(connector1, connector2);

            Assert.AreEqual(start, route.Start, "Start StreetConnector doesn't match");
            Assert.AreEqual(end, route.End, "End StreetConnector doesn't match");
            Assert.AreEqual(waypoints.Count, route.Waypoints.Count, "There shouldn't be any waypoints");
        }
        public void Test_SameStreetConnector()
        {
            SpecialRoute           route;
            StreetConnector        connector;
            StreetConnector        start, end;
            List <StreetConnector> waypoints = new List <StreetConnector>();

            for (int i = 0; i < StreetMapManager.Data.StreetConnectorsCount; i++)
            {
                connector = start = end = StreetMapManager.Data.StreetConnectors(i);

                route = new SpecialRoute(connector, connector);

                Assert.AreEqual(start, route.Start, "Start StreetConnector doesn't match");
                Assert.AreEqual(end, route.End, "End StreetConnector doesn't match");
                Assert.AreEqual(waypoints.Count, route.Waypoints.Count, "There shouldn't be any waypoints");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new Participant.
        /// </summary>
        /// <param name="position">The initial position of this participant</param>
        /// <param name="maxSpeed">The max speed of this participant</param>
        /// <param name="accidentRisk">The risk that this participant causes an accident</param>
        /// <param name="size">The amount of space this participant uses up</param>
        protected Participant(StreetConnector position, double maxSpeed, double accidentRisk, double size)
        {
            id = NextID;
            currentConnector  = position;
            this.position     = ParticipantPosition.FromCoordinate(position.Coordinate);
            this.maxSpeed     = maxSpeed;
            this.accidentRisk = accidentRisk;
            this.size         = size;

            baseRoute           = null;
            specialRoute        = null;
            currentRoutingState = RoutingState.Idle;
            lastConnector       = null;
            nextConnector       = null;
            goalConnector       = null;
            timeBonus           = TimeSpan.Zero;
            claimedSpace        = false;
            isFirstClaim        = true;
        }
        public void Test_StreetSegmentSequence()
        {
            SpecialRoute           route;
            StreetConnector        connector1, connector2;
            StreetConnector        start, end;
            List <StreetConnector> waypoints = new List <StreetConnector>();

            connector1 = start = StreetMapManager.Data.StreetConnectors(0);
            connector2 = end = StreetMapManager.Data.StreetConnectors(4);

            waypoints.Add(StreetMapManager.Data.StreetConnectors(1));
            waypoints.Add(StreetMapManager.Data.StreetConnectors(2));
            waypoints.Add(StreetMapManager.Data.StreetConnectors(3));

            route = new SpecialRoute(connector1, connector2);

            Assert.AreEqual(start, route.Start, "Start StreetConnector doesn't match");
            Assert.AreEqual(end, route.End, "End StreetConnector doesn't match");
            Assert.AreEqual(waypoints.Count, route.Waypoints.Count, "There shouldn't be any waypoints");
            for (int i = 0; i < waypoints.Count; i++)
            {
                Assert.AreEqual(waypoints.ElementAt(i), route.Waypoints.ElementAt(i), string.Format("Waypoint {0} doesn't match", i));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Follows the current route as long as the time suffice.
        /// </summary>
        public void ExecuteRouting()
        {
            bool executing = true;

            while (executing)
            {
                switch (currentRoutingState)
                {
                case RoutingState.Idle:
                case RoutingState.Starting: return;

                case RoutingState.SpecialStart1:
                    if (specialRoute.Waypoints.Count == 0)
                    {
                        currentRoutingState = RoutingState.SpecialEnd1;
                        continue;
                    }
                    nextConnector = specialRoute.Waypoints.First();
                    if (executing = AdvanceRoute())
                    {
                        currentRoutingState  = RoutingState.SpecialWayspoints1;
                        currentWaypointIndex = 1;
                    }
                    break;

                case RoutingState.SpecialWayspoints1:
                    if (specialRoute.Waypoints.Count == currentWaypointIndex)
                    {
                        currentRoutingState = RoutingState.SpecialEnd1;
                        continue;
                    }
                    nextConnector = specialRoute.Waypoints.ElementAt(currentWaypointIndex);
                    if (executing = AdvanceRoute())
                    {
                        currentWaypointIndex++;
                    }
                    break;

                case RoutingState.SpecialEnd1:
                    nextConnector = specialRoute.End;
                    if (executing = AdvanceRoute())
                    {
                        currentRoutingState = RoutingState.BaseStart;
                    }
                    break;

                case RoutingState.BaseStart:
                    if (baseRoute.Waypoints.Count == 0)
                    {
                        currentRoutingState = RoutingState.BaseEnd;
                        continue;
                    }
                    nextConnector = baseRoute.Waypoints.First();
                    if (executing = AdvanceRoute())
                    {
                        currentRoutingState  = RoutingState.BaseWaypoints;
                        currentWaypointIndex = 1;
                    }
                    break;

                case RoutingState.BaseWaypoints:
                    if (baseRoute.Waypoints.Count == currentWaypointIndex)
                    {
                        currentRoutingState = RoutingState.BaseEnd;
                        continue;
                    }
                    nextConnector = baseRoute.Waypoints.ElementAt(currentWaypointIndex);
                    if (executing = AdvanceRoute())
                    {
                        currentWaypointIndex++;
                    }
                    break;

                case RoutingState.BaseEnd:
                    nextConnector = baseRoute.End;
                    if (executing = AdvanceRoute())
                    {
                        if (currentConnector == goalConnector)
                        {
                            currentRoutingState = RoutingState.Finished;
                        }
                        else
                        {
                            specialRoute        = new SpecialRoute(currentConnector, goalConnector);
                            currentRoutingState = RoutingState.SpecialStart2;
                        }
                    }
                    break;

                case RoutingState.SpecialStart2:
                    if (specialRoute.Waypoints.Count == 0)
                    {
                        currentRoutingState = RoutingState.SpecialEnd2;
                        continue;
                    }
                    nextConnector = specialRoute.Waypoints.First();
                    if (executing = AdvanceRoute())
                    {
                        currentRoutingState  = RoutingState.SpecialWayspoints2;
                        currentWaypointIndex = 1;
                    }
                    break;

                case RoutingState.SpecialWayspoints2:
                    if (specialRoute.Waypoints.Count == currentWaypointIndex)
                    {
                        currentRoutingState = RoutingState.SpecialEnd2;
                        continue;
                    }
                    nextConnector = specialRoute.Waypoints.ElementAt(currentWaypointIndex);
                    if (executing = AdvanceRoute())
                    {
                        currentWaypointIndex++;
                    }
                    break;

                case RoutingState.SpecialEnd2:
                    nextConnector = specialRoute.End;
                    if (executing = AdvanceRoute())
                    {
                        currentRoutingState = RoutingState.Finished;
                    }
                    break;

                case RoutingState.Finished:
                    if (!isFirstClaim)
                    {
                        StreetType typeLast;
                        if (currentConnector.EP1.FindNeighbours().Contains(lastConnector))
                        {
                            typeLast = currentConnector.EP1.Self;
                        }
                        else
                        {
                            typeLast = currentConnector.EP2.Self;
                        }
                        FreeSpace(typeLast);
                    }
                    isFirstClaim = true;
                    return;

                default: throw new Exception("Unknown RoutingState");
                }
            }
        }