Example #1
0
        public void Refresh()
        {
            ++counter_0;

            if (counter_0 == (1000 / Properties.Settings.Default.Simulation_ComputeInterval))
            {
                counter_0 = 0;

                for (int i = 0; i < Roads.Count; ++i)
                {
                    MySerial.Write("#VC" + i.ToString() + "<" + Roads.ElementAt(i).Refresh().ToString() + ">");
                }

                MySerial.Write(";");
            }
            else
            {
                Parallel.For(0, Roads.Count, i =>
                {
                    Roads.ElementAt(i).Refresh();
                });
            }

            UpdateSerialRead();

            for (int i = 0; i < 4; ++i)
            {
                AverageWaitTime += Roads.ElementAt(i).AverageWaitTime;
                Roads.ElementAt(i).AverageWaitTime.Reset();
                log.Add("avgwt= " + AverageWaitTime.AverageValue + "s");
            }
        }
Example #2
0
 public void AddVehicleManual(Driver driver, VehicleSpecs vehicleSpecs)
 {
     if (IsFreeToSpawn())
     {
         Vehicles.Add(new Vehicle(driver, vehicleSpecs, SpawnBound, StopBound, new Rectangle2D(LaneBound), new Point2D(RandomDirectionLanePoint())));
     }
     else
     {
         errorLog.Add("VEHICLE SPAWN FAILED [EntryPointFullException]");
     }
 }
Example #3
0
        public Road(string roadID, Rectangle2D roadBound, Rectangle2D ExitLeftLaneBound, Rectangle2D ExitRightLaneBound)
        {
            RoadID    = roadID;
            RoadBound = roadBound;

            LeftLane  = new Lane(roadID + "\\LEFT", new Rectangle2D(RoadBound.Length, RoadBound.Breadth / 2, Point2D.MidPoint(RoadBound.OD, RoadBound.Midpoint), RoadBound.Inclination), new Point2D(ExitLeftLaneBound.OC));
            RightLane = new Lane(roadID + "\\RIGHT", new Rectangle2D(RoadBound.Length, RoadBound.Breadth / 2, Point2D.MidPoint(new Point2D(RoadBound.OB).Move(1, RoadBound.Inclination + Angle.A90), RoadBound.Midpoint), RoadBound.Inclination), new Point2D(ExitRightLaneBound.OC));

            log = new LogModule(roadID);
            log.Add("");
        }
Example #4
0
        public ushort Refresh()
        {
            int x = (ushort)(LeftLane.Refresh(isOpen) + RightLane.Refresh(isOpen));

            AverageWaitTime += LeftLane.AverageWaitTime + RightLane.AverageWaitTime;

            LeftLane.AverageWaitTime.Reset();
            RightLane.AverageWaitTime.Reset();

            log.Add("avgwt= " + AverageWaitTime.AverageValue + "s");

            return((ushort)x);
        }
 public void OpenRoad(string roadID, bool isEmergency = false)
 {
     log.Add("CHANGES: OPEN_ROAD (roadID = " + roadID + " isEmergency = " + isEmergency);
     Parallel.ForEach(RoadList, (r) =>
     {
         if (r.RoadID == roadID)
         {
             r.Open(isEmergency);
             TimeLeftForNextActivity = r.Settings.MaxOpenTime;
         }
         else
         {
             r.Close();
         }
     });
 }
        //--
        public Junction(string jncID, IEnumerable <Road> roadList, JunctionModes junctionMode, bool overrideCtrlOnEmergency, byte maxOpenTime, byte roadTurnOverDelay)
        {
            JunctionID = jncID;

            RoadList.Clear(); // create a reset all function
            CREM.Clear();

            foreach (Road r in roadList)
            {
                RoadList.Add(r);
            }

            JunctionMode            = junctionMode;
            OverrideCtrlOnEmergency = overrideCtrlOnEmergency;
            MaxOpenTime             = maxOpenTime;
            RoadTurnOverDelay       = roadTurnOverDelay;

            ResetCycle();
            TimeLeftForNextActivity = 1;



            log = new LogModule("CORE\\" + jncID);

            log.Add(new string[]
            {
                "<INIT_CONFIG>",
                "\tjnc_id = " + jncID,
                "\tjncMode = " + junctionMode,
                "\toverride_ctrl_on_emergency = " + overrideCtrlOnEmergency,
                "\tmax_open_time = " + maxOpenTime,
                "\troad_turn_over_delay = " + roadTurnOverDelay,
                "</INIT_CONFIG>"
            });

            log.FlushBuffer();
        }