Exemplo n.º 1
0
        private void Set_Value_Click(object sender, EventArgs e)
        {
            int Sum  = 0;
            int Sum2 = 0;

            for (int i = 0; i < 4; i++)
            {
                Sum += (int)chart2.Series[0].Points[i].YValues[0];
            }
            for (int i = 0; i < 24; i++)
            {
                Sum2 += (int)chart1.Series[0].Points[i].YValues[0];
            }

            if (Sum != 100 && Sum2 != 100)
            {
                WarningWindow WW = new WarningWindow("The quadrant and hourly distribution graphs need to add up to 100. Both graphs are incorrect.");
                WW.Show();
            }
            else if (Sum != 100)
            {
                WarningWindow WW = new WarningWindow("The quadrant distribution graph needs to add up to 100.");
                WW.Show();
            }
            else if (Sum2 != 100)
            {
                WarningWindow WW = new WarningWindow("The hourly distribution graph needs to add up to 100.");
                WW.Show();
            }
            else
            {
                this.Close();
            }
        }
Exemplo n.º 2
0
 public void CheckForCompletion(object sender, DataReceivedEventArgs e)
 {
     if (e.Data == "Success.")
     {
         this.BeginInvoke(new MethodInvoker(delegate()
         {
             WarningWindow ww = new WarningWindow("Success. You may now Load the config File in Sumo.");
             ww.Show();
         }));
     }
 }
        public static bool WriteTrip(string FileName)
        {
            //default is test.xml
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent          = true,
                IndentChars     = "  ",
                NewLineChars    = "\r\n",
                NewLineHandling = NewLineHandling.Replace
            };

            XmlWriter _Writer = XmlWriter.Create(FileName, settings);

            _Writer.WriteStartDocument();
            _Writer.WriteStartElement("trips");
            _Writer.WriteStartElement("vType");
            _Writer.WriteAttributeString("id", "ElectricCar");
            _Writer.WriteAttributeString("accel", "1.0");
            _Writer.WriteAttributeString("decel", "1.0");
            _Writer.WriteAttributeString("length", "4");
            _Writer.WriteAttributeString("maxSpeed", "100");
            _Writer.WriteAttributeString("sigma", "0.0");
            _Writer.WriteAttributeString("minGap", "2.5");
            _Writer.WriteAttributeString("color", "1,0,0");
            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "MaxBatKap");
            _Writer.WriteAttributeString("value", "85");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "actualBatteryCapacity");
            _Writer.WriteAttributeString("value", "2000");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "vehicleMass");
            _Writer.WriteAttributeString("value", "216");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "frontSurfaceArea");
            _Writer.WriteAttributeString("value", "4");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "airDragCoefficient");
            _Writer.WriteAttributeString("value", "0.6");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "internalMomentOfInertia");
            _Writer.WriteAttributeString("value", "0.01");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "radialDragCoefficient");
            _Writer.WriteAttributeString("value", "0.5");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "constantPowerIntake");
            _Writer.WriteAttributeString("value", "0.00327");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "propulsionEfficiency");
            _Writer.WriteAttributeString("value", "0.9");
            _Writer.WriteEndElement();

            _Writer.WriteStartElement("param");
            _Writer.WriteAttributeString("key", "recuperationEfficiency");
            _Writer.WriteAttributeString("value", "0.9");
            _Writer.WriteEndElement();

            _Writer.WriteEndElement();
            for (int j = 0; j < 24; j++)
            {
                if (tripID < j * NumOfSecondsInHour)
                {
                    tripID = j * NumOfSecondsInHour;
                }
                int TripIncrement = (int)(CARS_IN_SIMULATION * ((quad1Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f)));
                TripIncrement += (int)(CARS_IN_SIMULATION * ((quad2Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f)));
                TripIncrement += (int)(CARS_IN_SIMULATION * ((quad3Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f)));
                TripIncrement += (int)(CARS_IN_SIMULATION * ((quad4Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f)));
                if (TripIncrement != 0)
                {
                    TripIncrement = (NumOfSecondsInHour / TripIncrement);
                    if (TripIncrement == 0)
                    {
                        WarningWindow WW = new WarningWindow("At Hour: " + j.ToString() + "Vehicle limit is exceeded(3600 per hour).");
                        WW.Show();
                        return(false);
                    }
                }
                for (int i = 0; i < (int)(CARS_IN_SIMULATION * ((quad1Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f))); i++)
                {
                    if (random.Next(1, 101) <= UtilityHelper.GasElectricRatio)
                    {
                        VehicleType.Add(tripID);
                    }
                    _Writer.WriteStartElement("trip");
                    _Writer.WriteAttributeString("id", tripID.ToString());
                    _Writer.WriteAttributeString("depart", (tripID.ToString() + ".00"));
                    _Writer.WriteAttributeString("from", quad1[random.Next(0, quad1.Count)].edgeID.ToString());
                    switch (random.Next(0, 3))
                    {
                    case 0:
                        _Writer.WriteAttributeString("to", quad1[random.Next(0, quad1.Count)].edgeID.ToString());
                        break;

                    case 1:
                        _Writer.WriteAttributeString("to", quad2[random.Next(0, quad2.Count)].edgeID.ToString());
                        break;

                    case 2:
                        _Writer.WriteAttributeString("to", quad3[random.Next(0, quad3.Count)].edgeID.ToString());
                        break;

                    case 3:
                        _Writer.WriteAttributeString("to", quad4[random.Next(0, quad4.Count)].edgeID.ToString());
                        break;

                    default:
                        break;
                    }
                    _Writer.WriteStartElement("param");
                    _Writer.WriteAttributeString("key", "ActBatKap");
                    _Writer.WriteAttributeString("value", "85");
                    _Writer.WriteEndElement();
                    _Writer.WriteEndElement();
                    tripID++;
                }
                for (int i = 0; i < (int)(CARS_IN_SIMULATION * ((quad2Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f))); i++)
                {
                    if (random.Next(1, 101) <= UtilityHelper.GasElectricRatio)
                    {
                        VehicleType.Add(tripID);
                    }
                    _Writer.WriteStartElement("trip");
                    _Writer.WriteAttributeString("id", tripID.ToString());
                    _Writer.WriteAttributeString("depart", (tripID.ToString() + ".00"));
                    _Writer.WriteAttributeString("from", quad2[random.Next(0, quad2.Count)].edgeID.ToString());
                    switch (random.Next(0, 3))
                    {
                    case 0:
                        _Writer.WriteAttributeString("to", quad1[random.Next(0, quad1.Count)].edgeID.ToString());
                        break;

                    case 1:
                        _Writer.WriteAttributeString("to", quad2[random.Next(0, quad2.Count)].edgeID.ToString());
                        break;

                    case 2:
                        _Writer.WriteAttributeString("to", quad3[random.Next(0, quad3.Count)].edgeID.ToString());
                        break;

                    case 3:
                        _Writer.WriteAttributeString("to", quad4[random.Next(0, quad4.Count)].edgeID.ToString());
                        break;

                    default:
                        break;
                    }
                    _Writer.WriteStartElement("param");
                    _Writer.WriteAttributeString("key", "ActBatKap");
                    _Writer.WriteAttributeString("value", "85");
                    _Writer.WriteEndElement();
                    _Writer.WriteEndElement();
                    tripID++;
                }
                for (int i = 0; i < (int)(CARS_IN_SIMULATION * ((quad3Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f))); i++)
                {
                    if (random.Next(1, 101) <= UtilityHelper.GasElectricRatio)
                    {
                        VehicleType.Add(tripID);
                    }
                    _Writer.WriteStartElement("trip");
                    _Writer.WriteAttributeString("id", tripID.ToString());
                    _Writer.WriteAttributeString("depart", (tripID.ToString() + ".00"));
                    _Writer.WriteAttributeString("from", quad3[random.Next(0, quad3.Count)].edgeID.ToString());
                    switch (random.Next(0, 3))
                    {
                    case 0:
                        _Writer.WriteAttributeString("to", quad1[random.Next(0, quad1.Count)].edgeID.ToString());
                        break;

                    case 1:
                        _Writer.WriteAttributeString("to", quad2[random.Next(0, quad2.Count)].edgeID.ToString());
                        break;

                    case 2:
                        _Writer.WriteAttributeString("to", quad3[random.Next(0, quad3.Count)].edgeID.ToString());
                        break;

                    case 3:
                        _Writer.WriteAttributeString("to", quad4[random.Next(0, quad4.Count)].edgeID.ToString());
                        break;

                    default:
                        break;
                    }
                    _Writer.WriteStartElement("param");
                    _Writer.WriteAttributeString("key", "ActBatKap");
                    _Writer.WriteAttributeString("value", "85");
                    _Writer.WriteEndElement();
                    _Writer.WriteEndElement();
                    tripID++;
                }
                for (int i = 0; i < (int)(CARS_IN_SIMULATION * ((quad4Percent / 100f) * ((double)HourlyCarDistribution[j] / 100f))); i++)
                {
                    if (random.Next(1, 101) <= UtilityHelper.GasElectricRatio)
                    {
                        VehicleType.Add(tripID);
                    }
                    _Writer.WriteStartElement("trip");
                    _Writer.WriteAttributeString("id", tripID.ToString());
                    _Writer.WriteAttributeString("depart", (tripID.ToString() + ".00"));
                    _Writer.WriteAttributeString("from", quad4[random.Next(0, quad4.Count)].edgeID.ToString());
                    switch (random.Next(0, 3))
                    {
                    case 0:
                        _Writer.WriteAttributeString("to", quad1[random.Next(0, quad1.Count)].edgeID.ToString());
                        break;

                    case 1:
                        _Writer.WriteAttributeString("to", quad2[random.Next(0, quad2.Count)].edgeID.ToString());
                        break;

                    case 2:
                        _Writer.WriteAttributeString("to", quad3[random.Next(0, quad3.Count)].edgeID.ToString());
                        break;

                    case 3:
                        _Writer.WriteAttributeString("to", quad4[random.Next(0, quad4.Count)].edgeID.ToString());
                        break;

                    default:
                        break;
                    }
                    _Writer.WriteStartElement("param");
                    _Writer.WriteAttributeString("key", "ActBatKap");
                    _Writer.WriteAttributeString("value", "85");
                    _Writer.WriteEndElement();
                    _Writer.WriteEndElement();
                    tripID++;
                }
            }

            _Writer.WriteEndDocument();
            _Writer.Close();
            return(true);
        }