Esempio n. 1
0
            /// <summary>
            /// Creates a new BusStation and returns it.
            /// </summary>
            /// <param name="connector">The assoziated StreetConnector</param>
            /// <returns>A new instance of a BusStation</returns>
            public static BusStation NewBusStation(StreetConnector connector)
            {
                BusStation station = new BusStation(connector);

                stations.Add(station.ID, station);
                return(station);
            }
Esempio n. 2
0
            /// <summary>
            /// Creates a new Building and returns it.
            /// </summary>
            /// <param name="connector">The assoziated StreetConnector</param>
            /// <returns>A new instance of a Building</returns>
            public static Building NewBuilding(StreetConnector connector)
            {
                Building building = new Building(connector);

                buildings.Add(building.ID, building);
                return(building);
            }
Esempio n. 3
0
            /// <summary>
            /// Creates a new TramStation and returns it.
            /// </summary>
            /// <param name="connector">The assoziated StreetConnector</param>
            /// <returns>A new instance of a TramStation</returns>
            public static TramStation NewTramStation(StreetConnector connector)
            {
                TramStation station = new TramStation(connector);

                stations.Add(station.ID, station);
                return(station);
            }
Esempio n. 4
0
            /// <summary>
            /// Creates a new StreetSegment and returns it.
            /// </summary>
            /// <param name="c1">The first StreetConnector</param>
            /// <param name="c2">The second StreetConnector</param>
            /// <returns>A new instance of a StreetSegment</returns>
            public static StreetSegment NewStreetSegment(StreetConnector c1, StreetConnector c2)
            {
                StreetSegment segment = new StreetSegment(c1, c2);

                segments.Add(segment.ID, segment);
                return(segment);
            }
Esempio n. 5
0
            /// <summary>
            /// Creates a new StreetConnector and returns it.
            /// </summary>
            /// <param name="coordinate">The coordinate of the StreetConnector</param>
            /// <returns>A new instance of a StreetConnector</returns>
            public static StreetConnector NewStreetConnector(Coordinate coordinate)
            {
                StreetConnector connector = new StreetConnector(coordinate);

                connectors.Add(connector.ID, connector);
                return(connector);
            }
        /// <summary>
        /// Creates a new PublicTransportStation and connects it to a specific StreetConnector.
        /// </summary>
        /// <param name="connector">The StreetConnector to where connect to</param>
        protected PublicTransportStation(StreetConnector connector)
        {
            id = NextID;

            if (!Connect(connector))
            {
                throw new StreetMapException("Could not connect this PublicTransportStation to the StreetConnector");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new Building and connects it to a specific StreetConnector.
        /// </summary>
        /// <param name="connector">The StreetConnector to connects this Building to</param>
        public Building(StreetConnector connector)
        {
            id = NextID;

            if (!Connect(connector))
            {
                throw new StreetMapException("Could not connect this Building to the StreetConnector");
            }
        }
Esempio n. 8
0
 private StreetEndpoint FindEndpoint(StreetConnector connector)
 {
     foreach (StreetEndpoint ep in connections)
     {
         if (ep.Connector == connector)
         {
             return(ep);
         }
     }
     return(null);
 }
        /// <summary>
        /// Creates a new StreetSegment between two StreetConnectors.
        /// </summary>
        /// <param name="c1">The first StreetConnector</param>
        /// <param name="c2">The second StreetConnector</param>
        public StreetSegment(StreetConnector c1, StreetConnector c2)
        {
            id  = NextID;
            ep1 = new StreetEndpoint(this);
            ep2 = new StreetEndpoint(this);

            if (!ep1.Connect(c1) || !ep2.Connect(c2))
            {
                throw new StreetMapException("Could not connect this StreetSegment with all StreetConnectors");
            }

            length     = CalcLength();
            speedLimit = DEFAULT_SPEED_LIMIT;
            UpdateMinDriveTime();
            lanes = DEFAULT_LANES_COUNT;
            UpdateSpace();
        }
        /// <summary>
        /// Disconnects from the connected StreetConnector.
        /// </summary>
        /// <returns>True if the connection could be broken, false otherwise</returns>
        public bool Disconnect()
        {
            if (!IsConnected)
            {
                return(true);
            }

            StreetConnector.DisconnectResult result = connector.Disconnect(this);
            switch (result)
            {
            case StreetConnector.DisconnectResult.Disconnected: connector = null; return(true);

            case StreetConnector.DisconnectResult.NotConnected: return(true);
            }

            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// Disconnects from the connected StreetConnector.
        /// </summary>
        /// <returns>True if the connection could be broken, false otherwise</returns>
        public bool Disconnect(StreetConnector connector)
        {
            StreetEndpoint ep = FindEndpoint(connector);

            if (ep == null)
            {
                return(true);
            }

            if (!ep.Disconnect())
            {
                throw new StreetMapException("Could not disconnect this StreetHub from the StreetConnector");
            }
            connections.Remove(ep);
            isGreenList.Remove(connector.ID);

            return(true);
        }
        /// <summary>
        /// Connects to the given StreetConnector.
        /// </summary>
        /// <param name="connector">The StreetConnector to connect to</param>
        /// <returns>True if a connection could be established, false otherwise</returns>
        public bool Connect(StreetConnector connector)
        {
            if (IsConnected)
            {
                return(false);
            }

            StreetConnector.ConnectResult result = connector.Connect(this);
            switch (result)
            {
            case StreetConnector.ConnectResult.Connected: this.connector = connector; return(true);

            case StreetConnector.ConnectResult.AlreadyConnected: return(true);

            case StreetConnector.ConnectResult.NoFreeSlot: return(false);
            }

            return(false);
        }
Esempio n. 13
0
        /// <summary>
        /// Connects to the given StreetConnector.
        /// </summary>
        /// <param name="connector">The StreetConnector to connect to</param>
        /// <returns>True if a connection could be established, false otherwise</returns>
        public bool Connect(StreetConnector connector)
        {
            if (FindEndpoint(connector) != null)
            {
                return(true);
            }

            StreetEndpoint ep = new StreetEndpoint(this);

            if (!ep.Connect(connector))
            {
                throw new StreetMapException("Could not connect this StreetHub to the StreetConnector");
            }
            connections.Add(ep);
            isGreenList.Add(connector.ID, true);
            UpdateSpace();

            return(true);
        }
Esempio n. 14
0
        private static void InitSmallStaticMap()
        {
            StreetConnector c1, c2, c3, c4;
            StreetHub       h1;

            // # StreetConnector
            // - StreetSegment
            // ~ StreetHub
            // ^ Building

            /*   ^   ^         ^
             *   #---#~~~~~#---#
             *   -      ~      -
             *   -   ^  ~      -
             *	 #---#~~~~~#---#^
             */

            Save(c1 = new StreetConnector(0, 0));
            Save(c2 = new StreetConnector(400, 0));
            Save(c3 = new StreetConnector(0, 300));
            Save(c4 = new StreetConnector(400, 300));
            Save(new Building(c1));
            Save(new Building(c2));
            Save(new Building(c4));
            Save(new StreetSegment(c1, c2));
            Save(new StreetSegment(c1, c3));
            Save(new StreetSegment(c3, c4));
            Save(c1 = new StreetConnector(1000, 0));
            Save(c3 = new StreetConnector(1000, 300));
            Save(h1 = new StreetHub());
            h1.Connect(c1);
            h1.Connect(c2);
            h1.Connect(c3);
            h1.Connect(c4);
            Save(c2 = new StreetConnector(1400, 0));
            Save(c4 = new StreetConnector(1400, 300));
            Save(new Building(c2));
            Save(new Building(c4));
            Save(new StreetSegment(c1, c2));
            Save(new StreetSegment(c2, c4));
            Save(new StreetSegment(c3, c4));
        }
Esempio n. 15
0
 public TramStation(StreetConnector connector) : base(connector)
 {
 }
Esempio n. 16
0
 private static void Save(StreetConnector connector)
 {
     connectors.Add(connector.ID, connector);
 }
Esempio n. 17
0
 public BusStation(StreetConnector connector) : base(connector)
 {
 }
Esempio n. 18
0
        private static void InitStaticCityMap()
        {
            // see excel file (table 1) for graphical representation

            StreetConnector c1, c2, c3, c4, c5, c6, c7, c8;
            StreetHub       h1, h2, h3, h4;

            // residential area 1 (left upper)
            Save(c1 = new StreetConnector(20, 20));
            Save(new Building(c1));
            Save(h1 = new StreetHub());
            h1.Connect(c1);
            Save(c2 = new StreetConnector(60, 20));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(100, 20));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(140, 20));
            Save(new Building(c4));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(180, 20));
            Save(new Building(c5));
            Save(new StreetSegment(c4, c5));
            Save(h2 = new StreetHub());
            h2.Connect(c5);

            // residential area 2 (left upper)
            Save(c1 = new StreetConnector(20, 60));
            Save(new Building(c1));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(60, 60));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(100, 60));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(140, 60));
            Save(new Building(c4));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(180, 60));
            Save(new Building(c5));
            Save(new StreetSegment(c4, c5));
            h2.Connect(c5);

            // residential area 3 (left upper)
            Save(c1 = new StreetConnector(20, 100));
            Save(new Building(c1));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(60, 100));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(100, 100));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(140, 100));
            Save(new Building(c4));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(180, 100));
            Save(new Building(c5));
            Save(new StreetSegment(c4, c5));
            h2.Connect(c5);

            // point below residential area in mid
            Save(c1 = new StreetConnector(200, 120));
            h2.Connect(c1);
            Save(h1 = new StreetHub());
            h1.Connect(c1);

            // long streets on top with triangle at right
            Save(c1 = new StreetConnector(210, 20));
            h2.Connect(c1);
            Save(c2 = new StreetConnector(270, 20));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(330, 20));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(h2 = new StreetHub());
            h2.Connect(c3);
            Save(c4 = new StreetConnector(370, 20));
            h2.Connect(c4);
            Save(c5 = new StreetConnector(420, 20));
            Save(new Building(c5));
            Save(new StreetSegment(c4, c5));
            Save(h3 = new StreetHub());
            h3.Connect(c5);
            Save(c6 = new StreetConnector(400, 50));
            Save(new Building(c6));
            h3.Connect(c6);
            Save(c7 = new StreetConnector(420, 50));
            Save(new Building(c7));
            Save(new StreetSegment(c6, c7));
            h3.Connect(c7);

            // street down left at upper right
            Save(c1 = new StreetConnector(350, 30));
            h2.Connect(c1);
            Save(c2 = new StreetConnector(350, 80));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(350, 130));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(340, 150));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(310, 150));
            Save(new StreetSegment(c4, c5));
            Save(h2 = new StreetHub());
            h2.Connect(c5);

            // umbrella like construct upper right
            Save(c1 = new StreetConnector(290, 140));
            h2.Connect(c1);
            Save(c2 = new StreetConnector(290, 100));
            Save(new StreetSegment(c1, c2));
            Save(h3 = new StreetHub());
            h3.Connect(c2);
            Save(c3 = new StreetConnector(270, 90));
            Save(new Building(c3));
            h3.Connect(c3);
            Save(c4 = new StreetConnector(240, 90));
            Save(new Building(c4));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(260, 60));
            Save(new StreetSegment(c4, c5));
            Save(c6 = new StreetConnector(310, 60));
            Save(new Building(c6));
            Save(new StreetSegment(c5, c6));
            Save(c7 = new StreetConnector(330, 90));
            Save(new Building(c7));
            Save(new StreetSegment(c6, c7));
            Save(c8 = new StreetConnector(310, 90));
            Save(new Building(c8));
            Save(new StreetSegment(c7, c8));
            h3.Connect(c8);

            // long street mid left from mid hub
            Save(c1 = new StreetConnector(170, 150));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(120, 150));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(50, 170));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(20, 200));
            Save(new Building(c4));
            Save(new StreetSegment(c3, c4));
            Save(c5 = new StreetConnector(20, 230));
            Save(new StreetSegment(c4, c5));
            Save(c6 = new StreetConnector(110, 230));
            Save(new StreetSegment(c5, c6));
            Save(h3 = new StreetHub());
            h3.Connect(c6);

            // circle bottom left
            Save(c1 = new StreetConnector(50, 260));
            Save(new Building(c1));
            Save(h4 = new StreetHub());
            h4.Connect(c1);
            Save(c2 = new StreetConnector(10, 270));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(50, 290));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(60, 270));
            Save(new StreetSegment(c3, c4));
            h4.Connect(c4);

            // short street from circle to next hub
            Save(c1 = new StreetConnector(90, 260));
            h4.Connect(c1);
            Save(c2 = new StreetConnector(120, 270));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(130, 240));
            Save(new StreetSegment(c2, c3));
            h3.Connect(c3);

            // continue street from above down at the bottom
            Save(c1 = new StreetConnector(150, 230));
            Save(new Building(c1));
            h3.Connect(c1);
            Save(c2 = new StreetConnector(190, 280));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(250, 280));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(h3 = new StreetHub());
            h3.Connect(c3);

            // single segment to the lower left from the umbrella like construct
            Save(c1 = new StreetConnector(230, 150));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(270, 150));
            Save(new StreetSegment(c1, c2));
            h2.Connect(c2);

            // two L-like segments at lower mid
            Save(c1 = new StreetConnector(200, 180));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(200, 250));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(240, 250));
            Save(new StreetSegment(c2, c3));
            h3.Connect(c3);

            // hub connect below umbrella like construct
            Save(c1 = new StreetConnector(290, 180));
            h2.Connect(c1);
            Save(h1 = new StreetHub());
            h1.Connect(c1);

            // lower left segment to above section
            Save(c1 = new StreetConnector(270, 200));
            Save(new Building(c1));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(260, 240));
            Save(new StreetSegment(c1, c2));
            h3.Connect(c2);

            // lower right segment to above section
            Save(c1 = new StreetConnector(320, 200));
            Save(new Building(c1));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(330, 240));
            Save(new StreetSegment(c1, c2));
            Save(h1 = new StreetHub());
            h1.Connect(c2);

            // connection segment to both above sections
            Save(c1 = new StreetConnector(280, 250));
            h3.Connect(c1);
            Save(c2 = new StreetConnector(310, 250));
            Save(new StreetSegment(c1, c2));
            h1.Connect(c2);

            // segment below above section
            Save(c1 = new StreetConnector(270, 280));
            h3.Connect(c1);
            Save(c2 = new StreetConnector(330, 270));
            Save(new StreetSegment(c1, c2));
            h1.Connect(c2);

            // little segment between hub and bottom right circle
            Save(c1 = new StreetConnector(350, 250));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(370, 250));
            Save(new StreetSegment(c1, c2));
            Save(h1 = new StreetHub());
            h1.Connect(c2);

            // bottom right circle
            Save(c1 = new StreetConnector(380, 240));
            Save(new Building(c1));
            h1.Connect(c1);
            Save(c2 = new StreetConnector(420, 220));
            Save(new Building(c2));
            Save(new StreetSegment(c1, c2));
            Save(c3 = new StreetConnector(420, 260));
            Save(new Building(c3));
            Save(new StreetSegment(c2, c3));
            Save(c4 = new StreetConnector(380, 260));
            Save(new StreetSegment(c3, c4));
            h1.Connect(c4);
        }