Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="partitionId"></param>
        public ArbiterLanePartition(ArbiterLanePartitionId partitionId,
                                    ArbiterWaypoint initial, ArbiterWaypoint final, ArbiterSegment segment)
            : base(false, null, true, segment, new List <IConnectAreaWaypoints>(), initial, final)
        {
            this.PartitionId               = partitionId;
            this.Initial                   = initial;
            this.Final                     = final;
            this.Length                    = this.Initial.Position.DistanceTo(this.Final.Position);
            this.UserWaypoints             = new List <ArbiterUserWaypoint>();
            this.NonLaneAdjacentPartitions = new List <ArbiterLanePartition>();

            // create a path of the partition and get the closest
            List <Coordinates> coords = new List <Coordinates>();

            coords.Add(initial.Position);
            coords.Add(final.Position);
            PartitionPath = new LinePath(coords);

            // nav edge stuff
            this.Contained.Add(this);
            this.blockage = new NavigationBlockage(0.0);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="initial"></param>
        /// <param name="final"></param>
        public ArbiterInterconnect(IArbiterWaypoint initial, IArbiterWaypoint final) :
            base(false, null, false, null, new List <IConnectAreaWaypoints>(), initial, final)
        {
            this.initialWaypoint = initial;
            this.finalWaypoint   = final;

            this.InterconnectId = new ArbiterInterconnectId(initialWaypoint.AreaSubtypeWaypointId, finalWaypoint.AreaSubtypeWaypointId);

            // create a path of the partition and get the closest
            List <Coordinates> ips = new List <Coordinates>();

            ips.Add(initial.Position);
            ips.Add(final.Position);
            this.InterconnectPath = new LinePath(ips);

            // nav edge stuff
            this.Contained.Add(this);
            this.blockage = new NavigationBlockage(0.0);

            this.TurnPolygon      = this.DefaultPoly();
            this.InnerCoordinates = new List <Coordinates>();
        }
        /// <summary>
        /// Get a road plan while setting partition costs very high
        /// </summary>
        /// <param name="partition"></param>
        /// <param name="goal"></param>
        /// <param name="blockAdjacent"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public RoadPlan PlanRoadOppositeWithoutPartition(ArbiterLanePartition partition, ArbiterLanePartition opposite, IArbiterWaypoint goal, bool blockAdjacent, Coordinates c, bool sameWay)
        {
            KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>> tmpCurrentTimes = currentTimes;
            this.currentTimes = new KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>>();
            RoadPlan rp = null;

            if (!blockAdjacent)
            {
                NavigationBlockage nb = partition.Blockage;
                NavigationBlockage tmp = new NavigationBlockage(double.MaxValue);
                partition.Blockage = tmp;
                rp = this.PlanNavigableArea(partition.Lane, c, goal, new List<ArbiterWaypoint>());
                partition.Blockage = nb;
            }
            else
            {
                // save
                List<KeyValuePair<ArbiterLanePartition, NavigationBlockage>> savedBlockages = new List<KeyValuePair<ArbiterLanePartition, NavigationBlockage>>();

                // set
                savedBlockages.Add(new KeyValuePair<ArbiterLanePartition,NavigationBlockage>(partition, partition.Blockage));
                // create new
                NavigationBlockage anewerBlockage = new NavigationBlockage(Double.MaxValue);
                anewerBlockage.BlockageExists = true;
                partition.Blockage = anewerBlockage;

                foreach (ArbiterLanePartition alp in partition.NonLaneAdjacentPartitions)
                {
                    if (alp.IsInside(c) && (!sameWay || (sameWay && partition.Lane.Way.Equals(alp.Lane.Way))))
                    {
                        savedBlockages.Add(new KeyValuePair<ArbiterLanePartition,NavigationBlockage>(alp, alp.Blockage));

                        // create new
                        NavigationBlockage newerBlockage = new NavigationBlockage(Double.MaxValue);
                        newerBlockage.BlockageExists = true;
                        alp.Blockage = newerBlockage;
                    }
                }

                // plan
                rp = this.PlanNavigableArea(opposite.Lane, c, goal, new List<ArbiterWaypoint>());

                // restore
                foreach (KeyValuePair<ArbiterLanePartition, NavigationBlockage> saved in savedBlockages)
                {
                    saved.Key.Blockage = saved.Value;
                }
            }

            // restore
            this.currentTimes = tmpCurrentTimes;

            // return
            return rp;
        }
        /// <summary>
        /// Try to plan the intersection heavily penalizing the interconnect
        /// </summary>
        /// <param name="iTraversableWaypoint"></param>
        /// <param name="iArbiterWaypoint"></param>
        /// <param name="arbiterInterconnect"></param>
        /// <returns></returns>
        public IntersectionPlan PlanIntersectionWithoutInterconnect(ITraversableWaypoint exit, IArbiterWaypoint goal, ArbiterInterconnect interconnect, bool blockAllRelated)
        {
            ITraversableWaypoint entry = (ITraversableWaypoint)interconnect.FinalGeneric;

            if (!blockAllRelated)
                return this.PlanIntersectionWithoutInterconnect(exit, goal, interconnect);
            else
            {
                Dictionary<IConnectAreaWaypoints, NavigationBlockage> saved = new Dictionary<IConnectAreaWaypoints, NavigationBlockage>();
                if (entry.IsEntry)
                {
                    foreach (ArbiterInterconnect ai in entry.Entries)
                    {
                        saved.Add(ai, ai.Blockage);

                        // create new
                        NavigationBlockage newerBlockage = new NavigationBlockage(Double.MaxValue);
                        newerBlockage.BlockageExists = true;
                        ai.Blockage = newerBlockage;
                    }
                }

                if (entry is ArbiterWaypoint && ((ArbiterWaypoint)entry).PreviousPartition != null)
                {
                    ArbiterLanePartition alp = ((ArbiterWaypoint)entry).PreviousPartition;
                    saved.Add(alp, alp.Blockage);

                    // create new
                    NavigationBlockage newerBlockage = new NavigationBlockage(Double.MaxValue);
                    newerBlockage.BlockageExists = true;
                    alp.Blockage = newerBlockage;
                }

                KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>> tmpCurrentTimes = currentTimes;
                this.currentTimes = new KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>>();

                // plan
                IntersectionPlan ip = this.PlanIntersection(exit, goal);

                this.currentTimes = tmpCurrentTimes;

                // reset the blockages
                foreach (KeyValuePair<IConnectAreaWaypoints, NavigationBlockage> savedPair in saved)
                    savedPair.Key.Blockage = savedPair.Value;

                // return plan
                return ip;
            }
        }
        /// <summary>
        /// Try to plan the intersection heavily penalizing the interconnect
        /// </summary>
        /// <param name="iTraversableWaypoint"></param>
        /// <param name="iArbiterWaypoint"></param>
        /// <param name="arbiterInterconnect"></param>
        /// <returns></returns>
        public IntersectionPlan PlanIntersectionWithoutInterconnect(ITraversableWaypoint exit, IArbiterWaypoint goal, ArbiterInterconnect interconnect)
        {
            // save old blockage
            NavigationBlockage tmpBlockage = interconnect.Blockage;

            // create new
            NavigationBlockage newerBlockage = new NavigationBlockage(Double.MaxValue);
            newerBlockage.BlockageExists = true;
            interconnect.Blockage = newerBlockage;

            KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>> tmpCurrentTimes = currentTimes;
            this.currentTimes = new KeyValuePair<int, Dictionary<ArbiterWaypointId, DownstreamPointOfInterest>>();

            // plan
            IntersectionPlan ip = this.PlanIntersection(exit, goal);

            this.currentTimes = tmpCurrentTimes;

            // reset interconnect blockage
            interconnect.Blockage = tmpBlockage;

            // return plan
            return ip;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="partitionId"></param>
        public ArbiterLanePartition(ArbiterLanePartitionId partitionId,
            ArbiterWaypoint initial, ArbiterWaypoint final, ArbiterSegment segment)
            : base(false, null, true, segment, new List<IConnectAreaWaypoints>(), initial, final)
        {
            this.PartitionId = partitionId;
            this.Initial = initial;
            this.Final = final;
            this.Length = this.Initial.Position.DistanceTo(this.Final.Position);
            this.UserWaypoints = new List<ArbiterUserWaypoint>();
            this.NonLaneAdjacentPartitions = new List<ArbiterLanePartition>();

            // create a path of the partition and get the closest
            List<Coordinates> coords = new List<Coordinates>();
            coords.Add(initial.Position);
            coords.Add(final.Position);
            PartitionPath = new LinePath(coords);

            // nav edge stuff
            this.Contained.Add(this);
            this.blockage = new NavigationBlockage(0.0);
        }