Ejemplo n.º 1
0
        public Vehicle(int ID, int weight, Road startRoad)
        {
            //picturebox setting
            this.BackColor = System.Drawing.Color.Transparent;
            this.Image = global::SmartTrafficSimulator.Properties.Resources.vehicle0;
            this.Size = new System.Drawing.Size(vehicle_GraphicLength, vehicle_GraphicWidth);
            this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

            createdTime = Simulator.getCurrentTime();
            vehicle_ID = ID;
            vehicle_weight = weight;
            locatedRoad = startRoad;

            this.vehicle_length = System.Convert.ToInt16(Simulator.VehicleManager.vehicleLength);
            this.safeDistance = this.vehicle_length*3;
            this.vehicle_GraphicLength = Simulator.VehicleManager.vehicleGraphicSize * 2;
            this.vehicle_GraphicWidth = Simulator.VehicleManager.vehicleGraphicSize;

            this.SetDrivingPath(Simulator.VehicleManager.GetRoadomDrivingPath(startRoad.roadID));

            this.roadPoints = startRoad.GetRoadPointList();

            this.setLocation(roadPoints[0]);
            this.locatedRoad.VehicleEnterRoad(this);
        }
Ejemplo n.º 2
0
 public Road CreateNewRoad()
 {
     int newRoadID = roadList.Count;
     Road newRoad = new Road(newRoadID);
     this.roadList.Add(newRoad);
     return newRoad;
 }
Ejemplo n.º 3
0
        public VehicleConfig()
        {
            InitializeComponent();
            if(Simulator.RoadManager.GetGenerateVehicleRoadList().Count > 0)
                selectedGenerateRoad = Simulator.RoadManager.GetGenerateVehicleRoadList()[0];

            LoadGenerateRoads();

            this.numericUpDown_vehicleSize.Value = Simulator.VehicleManager.vehicleGraphicSize;
            this.numericUpDown_vehicleMaxSpeed.Value = (decimal)Simulator.VehicleManager.vehicleMaxSpeed_KMH;
            this.numericUpDown_accelerationFactor.Value = (decimal)Simulator.VehicleManager.vehicleAccelerationFactor_KMH;
            this.numericUpDown_brakeFactor.Value = (decimal)Simulator.VehicleManager.vehicleBrakeFactor_KMH;
        }
Ejemplo n.º 4
0
 private void comboBox_generateRoad_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedGenerateRoad = Simulator.RoadManager.GetGenerateVehicleRoadList()[this.comboBox_generateRoads.SelectedIndex];
     LoadVehicleGenerateSetting();
     LoadGenerateSchedule();
     LoadDrivingPath();
     DrivingPathEditorInitial();
 }
Ejemplo n.º 5
0
        //計算所有相連道路間路徑
        public void GenerateIntermediateRoad()
        {
            for (int i = 0; i < connectedRoadIDList.Count; i++)
            {
                Road newIntermediateRoad = new Road(i);
                Road connectRoad = Simulator.RoadManager.GetRoadByID(connectedRoadIDList[i]);

                int goalRoadID = connectedRoadIDList[i];

                newIntermediateRoad.connectRoad = connectRoad;
                newIntermediateRoad.roadType = 2;

                string name = this.roadName + " -> " + Simulator.RoadManager.GetRoadList()[goalRoadID].roadName;
                newIntermediateRoad.SetRoadName(name);

                List<Point> connectRoadNode = new List<Point>();
                connectRoadNode.Add(roadNodeList[roadNodeList.Count - 1]);
                connectRoadNode.Add(connectRoad.roadNodeList[0]);
                newIntermediateRoad.SetRoadNode(connectRoadNode);

                newIntermediateRoad.GenerateCompleteRoad();

                intermediateRoadList.Add(newIntermediateRoad);
            }
        }
        public Vehicle CreateVehicle(Road startRoad,int Weight)
        {
            //if (startRoad.getRoadLength() - ((startRoad.WaittingVehicles()-1) * SimulatorConfiguration.vehicleLength) > SimulatorConfiguration.vehicleLength) //不超出道路
               // {
                Vehicle newVehicle = new Vehicle(vehicleGenerateSerialID, Weight, startRoad);

                vehicleGenerateSerialID++;

                Simulator.UI.AddVehicle(newVehicle);

                vehicleList.Add(newVehicle.vehicle_ID,newVehicle);

                return newVehicle;
            //}
        }
 public void CreateVehicle(Road startRoad, int Weight,DrivingPath dp)
 {
     CreateVehicle(startRoad,Weight).SetDrivingPath(dp);
 }
Ejemplo n.º 8
0
        public void ToNextRoad(int remainRunPixel)
        {
            UploadVehicleWaittingTime();
            travelDistace_pixel += locatedRoad.GetRoadLength();
            locatedRoad.VehicleExitRoad(this);
            if (locatedRoad.roadType == 0 || locatedRoad.roadType == 1) //目前的為一般道路
            {
                passingRoadIndex++;
                if (passingRoadIndex >= passingRoads.Count)
                {
                    travelTime_total = Simulator.getCurrentTime() - createdTime;
                    Simulator.VehicleManager.DestoryVehicle(vehicle_ID);
                }
                else
                {
                    for (int x = 0; x < locatedRoad.intermediateRoadList.Count; x++) //尋找連接到下一條路的連接路段
                    {
                        if (locatedRoad.intermediateRoadList[x].connectRoad.roadID == passingRoads[passingRoadIndex].roadID)
                        {
                            locatedRoad = locatedRoad.intermediateRoadList[x];
                            location = 0;
                            roadPoints = locatedRoad.GetRoadPointList();
                            locatedRoad.VehicleEnterRoad(this);
                            VehicleMove(remainRunPixel);
                        }
                    }
                }
            }

            else if (locatedRoad.roadType == 2)//目前的為連接道路
            {
                locatedRoad = passingRoads[passingRoadIndex];
                location = 0;
                roadPoints = locatedRoad.GetRoadPointList();
                locatedRoad.VehicleEnterRoad(this);
                VehicleMove(remainRunPixel);
            }
        }
        public Boolean SimulationFileRead_GenerateSchedule(Road generateRoad, XmlNode generateSchedules)
        {
            XmlNodeList generateScheduleList = generateSchedules.ChildNodes;

            foreach (XmlNode generateSchedule in generateScheduleList)
            {
                string time = generateSchedule.Attributes["Time"].Value;
                int level = System.Convert.ToInt16(generateSchedule.Attributes["Level"].Value);
                generateRoad.AddGenerateSchedule(time, level);
            }
            return true;
        }
        public Boolean SimulationFileRead_DrivingPath(Road road, XmlNode drivingPaths)
        {
            XmlNodeList drivingPathList = drivingPaths.ChildNodes;

            foreach (XmlNode drivingPath in drivingPathList)
            {
                int startRoadID = System.Convert.ToInt16(drivingPath.Attributes["Start"].Value);
                int goalRoadID = System.Convert.ToInt16(drivingPath.Attributes["Goal"].Value);
                int Probability = System.Convert.ToInt16(drivingPath.Attributes["Probability"].Value);

                string passingRoad = drivingPath.Attributes["Passing"].Value;

                Simulator.VehicleManager.AddDrivingPath(new DrivingPath(startRoadID,goalRoadID,Probability,passingRoad));
            }
            return true;
        }