Example #1
0
        public static Graph Create()
        {
            var graph = new Graph();

            Func <int, int> hours   = (int h) => h * 3600;
            Func <int, int> minutes = (int m) => m * 60;
            Func <int, int> seconds = (int s) => s;

            Func <int, int, int> track2secs      = (int t, int s) => t * 60 + s * 30;
            Func <int, int>      turnaround2secs = (int c) => c * 30;

            Debug.Assert(track2secs(2, 1) == minutes(2) + seconds(30));
            Debug.Assert(turnaround2secs(4) == minutes(2));

            var ar1  = new ArrivalNode("(1,2)", 0);
            var ar2  = new ArrivalNode("(3)", minutes(2) + 30);
            var arm1 = new MovementNode("(1, 2) to T3", track2secs(2, 1));


            var split12 = new SplitNode("(1, 2) to (1), (2)", minutes(2));

            var m2 = new MovementNode("(2) to T2", track2secs(2, 1));
            var s1 = new ServiceNode("(2) on T2", minutes(34));


            var m3 = new MovementNode("(1) to T4", track2secs(2, 1));



            var p3a = new ParkingNode("(1) P3");
            var p3b = new ParkingNode("(2) P3");

            var arm2a = new MovementNode("(3) to T3", track2secs(2, 1));
            var arm2b = new TurnAroundNode(turnaround2secs(4));
            var arm2c = new MovementNode("(3) to T1", track2secs(2, 1));

            var m4 = new MovementNode("(2) to G", track2secs(3, 2));



            var m5a = new MovementNode("(1) to T3", track2secs(2, 1));
            var m5b = new TurnAroundNode(turnaround2secs(3));
            var m5c = new MovementNode("(1) to T2", track2secs(2, 1));


            var s2 = new ServiceNode("(1) on T2", minutes(34));

            var m6 = new MovementNode("(1) to T1", track2secs(3, 2));

            var m7 = new SplitNode("(3) (1) to (3, 1)", minutes(3));


            var m8a = new MovementNode("(3, 1) to T4", track2secs(3, 2));
            var m8b = new TurnAroundNode(turnaround2secs(7));
            var m8c = new MovementNode("(3, 1) to G", track2secs(3, 2));

            var dep1 = new DepartureNode("(2)", minutes(90));
            var dep2 = new DepartureNode("(3, 1)", hours(2));


            ar1.AddSuccessor(arm1);
            ar2.AddSuccessor(arm2a);
            split12.AddSuccessor(m2);
            split12.AddSuccessor(m3);

            split12.AddSuccessor(p3a);
            split12.AddSuccessor(p3b);


            p3a.AddSuccessor(m2);
            p3b.AddSuccessor(m3);
            m2.AddSuccessor(s1);
            m2.AddSuccessor(m3);
            arm1.AddSuccessor(split12);
            arm2a.AddSuccessor(arm2b);
            arm2b.AddSuccessor(arm2c);
            s1.AddSuccessor(m4);
            m4.AddSuccessor(dep1);
            m3.AddSuccessor(m5a);
            m5a.AddSuccessor(m5b);
            m5b.AddSuccessor(m5c);
            m5c.AddSuccessor(s2);
            s2.AddSuccessor(m6);
            m6.AddSuccessor(m7);
            arm2c.AddSuccessor(m7);
            m7.AddSuccessor(m8a);
            m8a.AddSuccessor(m8b);
            m8b.AddSuccessor(m8c);
            m8c.AddSuccessor(dep2);



            // Other
            graph.ArrivalNodes.Add(ar1);
            graph.ArrivalNodes.Add(ar2);
            graph.DepartureNodes.Add(dep1);
            graph.DepartureNodes.Add(dep2);

            graph.Propagate();
            return(graph);
        }
Example #2
0
        public override void Build(City c)
        {
            if (this.n1 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n1 = this.n1 as BuilderAllWayStopNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n1 = this.n1 as BuilderTrafficCircleNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n1 = this.n1 as BuilderDeadEndNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }


            if (this.n2 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n2 = this.n2 as BuilderAllWayStopNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n2 = this.n2 as BuilderTrafficCircleNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n2 = this.n2 as BuilderDeadEndNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }

            double dist      = Util.Distance(s1.x, s1.y, e2.x, e2.y);
            int    parkCount = (int)(dist / PARKING_LENGTH);
            double dir       = Util.GetLookatDir(s1.x, s1.y, e2.x, e2.y);

            CityNode last     = s1;
            CityNode lastPark = p11;

            for (int i = 1; i <= parkCount; i++)
            {
                int       x    = s1.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int       y    = s1.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                MergeNode exit = new MergeNode(x, y, new MergePoint());

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                CityPath priority = last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                (exit.intersection as MergePoint).priority = priority;

                last     = exit;
                lastPark = park;
            }
            last.Connect(e2, CityPathType.privates);
            lastPark.Connect(p22, CityPathType.pedestrians);
            p22.Connect(lastPark, CityPathType.pedestrians);


            dist      = Util.Distance(s2.x, s2.y, e1.x, e1.y);
            parkCount = (int)(dist / PARKING_LENGTH);
            dir       = Util.GetLookatDir(s2.x, s2.y, e1.x, e1.y);

            last     = s2;
            lastPark = p21;
            for (int i = 1; i <= parkCount; i++)
            {
                int      x    = s2.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int      y    = s2.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                CityNode exit = new CityNode(x, y);

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                last     = exit;
                lastPark = park;
            }
            last.Connect(e1, CityPathType.privates);
            lastPark.Connect(p12, CityPathType.pedestrians);
            p12.Connect(lastPark, CityPathType.pedestrians);
        }