internal bool WriteScenario(Scenario scn)
 {
     if (!string.IsNullOrEmpty(_path))
     {
         using (StreamWriter writer = new StreamWriter(_path + "scenario.scn", false))
         {
             writer.WriteLine(1);
         }
         //Пишем карту
         if (!string.IsNullOrEmpty(scn.StringMap))
         {
             using (StreamWriter writer = new System.IO.StreamWriter(_path + "map.svg", false))
             {
                 writer.Write(scn.StringMap);
             }
         }
         //Пишем группы агентов
         if (scn.agentGroups != null && scn.agentGroups.Count > 0)
         {
             try
             {
                 using (StreamWriter writer = new System.IO.StreamWriter(_path + "AgentGroups.xml", false))
                 {
                     XmlSerializer sw = new XmlSerializer(typeof(AgentsGroup[]));
                     sw.Serialize(writer, scn.agentGroups.ToArray());
                 }
             }
             catch (NotSupportedException) { return false; }
         }
         //Пишем дорожную сеть
         if (scn.RoadGraph.Nodes != null)
         {
             try
             {
                 using (StreamWriter writer = new System.IO.StreamWriter(_path + "RoadGraph.xml", false))
                 {
                     XmlSerializer sw = new XmlSerializer(typeof(GraphContainer));
                     sw.Serialize(writer, new GraphContainer(scn.RoadGraph));
                 }
             }
             catch (NotSupportedException) { return false; }
         }
         //Пишем сервисы
         if (scn.ServicesList != null && scn.ServicesList.Count > 0)
         {
             try
             {
                 ServiceBase[] sb = scn.ServicesList.ToArray();
                 using (StreamWriter writer = new System.IO.StreamWriter(_path + "Services.xml", false))
                 {
                     XmlSerializer sw = new XmlSerializer(typeof(ServiceBase[]), new Type[] { typeof(StopService), typeof(TurnstileService), typeof(QueueService), typeof(System.Windows.Media.LineSegment), typeof(System.Windows.Media.PolyLineSegment), typeof(System.Windows.Media.BezierSegment) });
                     sw.Serialize(writer, sb);
                 }
             }
             catch (NotSupportedException) { return false; }
         }
         return true;
     }
     return false;
 }
        public wndWayPointsConfig(List<WayPoint> wayPointList)
        {
            WayPointVisualList = new List<WayPointVisual>();
            WayPointsList = new List<WayPoint>();
            InitializeComponent();
            if ((Application.Current.MainWindow as MainWindow).Scena == null)
            {
                MessageBox.Show("нет карты");
                return;
            }
            scena = (Application.Current.MainWindow as MainWindow).Scena;
            for (int i = 0; i < scena.ServicesList.Count; i++)
            {
                cbSevice.Items.Add(scena.ServicesList[i]);
            }
            Zoom = 4.0;
            PaintMap(scena.paintObjectList);
            lblMapSize.Content = string.Format("{0} x {1}", Math.Round(pnlMap.Width / Zoom), Math.Round(pnlMap.Height / Zoom));

            for (int i = 0; i < wayPointList.Count; i++)
            {
                WayPointVisual w = new WayPointVisual()
                {
                    Zoom = Zoom,
                    Number = (i + 1).ToString(),
                    SourcePoint = wayPointList[i]
                };
                WayPointVisualList.Add(w);
                pnlMap.Children.Add(w);
            }
        }
        public VehicleWayPointsConfigWindow(Graph<WayPoint, PathFigure> roadGraph)
        {
            VertexVisualsList = new List<VertexVisual>();
            EdgeVisualsList = new List<EdgeVisual>();
            RoadGraph = roadGraph;
            InitializeComponent();

            scena = (Application.Current.MainWindow as MainWindow).Scena;
            Zoom = 4.0;
            PaintMap();
            lblMapSize.Content = string.Format("{0} x {1}", Math.Round(pnlMap.Width / Zoom), Math.Round(pnlMap.Height / Zoom));

            foreach (var edge in RoadGraph.Edges)
            {
                EdgeVisual ev = new EdgeVisual(edge.Data)
                {
                    NodeFrom = edge.Start,
                    NodeTo = edge.End,
                    Zoom = Zoom
                };
                EdgeVisualsList.Add(ev);
                pnlMap.Children.Add(ev);
            }

            foreach (var node in RoadGraph.Nodes)
            {
                int in_count = 0, out_count = 0;
                foreach (var edge in RoadGraph.GetEdgesTo(node))
                {
                    in_count++;
                }
                foreach (var edge in RoadGraph.GetEdgesFrom(node))
                {
                    out_count++;
                }

                VertexVisual vv = new VertexVisual(node)
                {
                    Number = (VertexVisualsList.Count + 1).ToString(),
                    InCount = in_count,
                    OutCount = out_count,
                    Zoom = Zoom
                };
                vv.Node.Number = int.Parse(vv.Number);
                if (in_count != 0)
                {
                    cbTo.Items.Add(vv.Node);
                }
                if (out_count != 0)
                {
                    cbFrom.Items.Add(vv.Node);
                }
                VertexVisualsList.Add(vv);
                pnlMap.Children.Add(vv);
            }
        }
Exemplo n.º 4
0
 public AgentBase(int id, Scenario scenario, int group, int speed)
 {
     this._id = id;
     this.scenario = scenario;
     this._group = group;
     this._maxspeed = speed;
     this.WayPointsList = new List<WayPoint>();
     SpeedRatio = 1.0;
     cell = new Point(-1, -1);
     position = new System.Windows.Point(-1, -1);
     lifeThread = new Thread(Life);
 }
        public wndRoadGraphConfig(Graph<WayPoint, PathFigure> roadGraph)
        {
            VertexVisualsList = new List<VertexVisual>();
            EdgeVisualsList = new List<EdgeVisual>();
            RoadGraph = roadGraph;
            InitializeComponent();

            scena = (Application.Current.MainWindow as MainWindow).Scena;
            for (int i = 0; i < scena.ServicesList.Count; i++)
            {
                cbSevice.Items.Add(scena.ServicesList[i]);
            }
            Zoom = 4.0;
            PaintMap();

            foreach (var edge in RoadGraph.Edges)
            {
                EdgeVisual ev = new EdgeVisual(edge.Data)
                {
                    NodeFrom = edge.Start,
                    NodeTo = edge.End,
                    Zoom = Zoom
                };
                EdgeVisualsList.Add(ev);
                pnlMap.Children.Add(ev);
            }

            foreach (var node in RoadGraph.Nodes)
            {
                int in_count = 0, out_count = 0;
                foreach (var edge in RoadGraph.GetEdgesTo(node))
                {
                    in_count++;
                }
                foreach (var edge in RoadGraph.GetEdgesFrom(node))
                {
                    out_count++;
                }

                VertexVisual vv = new VertexVisual(node)
                {
                    Number = (VertexVisualsList.Count + 1).ToString(),
                    InCount = in_count,
                    OutCount = out_count,
                    Zoom = Zoom
                };
                VertexVisualsList.Add(vv);
                pnlMap.Children.Add(vv);
            }
        }
Exemplo n.º 6
0
 public TrainAgent(int id, Scenario scenario, int group, int speed, int number_of_carriges)
     : base(id, scenario, group, speed)
 {
     this.number_of_carriges = number_of_carriges;
     positions = new Point[number_of_carriges];
     for (int i = 0; i < number_of_carriges; i++)
     {
         positions[i] = new Point(-1, -1);
     }
     currentLength = new double[number_of_carriges];
     need_draw = new bool?[number_of_carriges];
     angles = new double[number_of_carriges];
     CheckPointsList = new List<WayPoint>();
 }
        public wndRoadGraphConfig()
        {
            VertexVisualsList = new List<VertexVisual>();
            EdgeVisualsList = new List<EdgeVisual>();
            //RoadGraph = new Graph<WayPoint,PathFigure>();
            InitializeComponent();

            scena = (Application.Current.MainWindow as MainWindow).Scena;
            for (int i = 0; i < scena.ServicesList.Count; i++)
            {
                cbSevice.Items.Add(scena.ServicesList[i]);
            }
            Zoom = 4.0;
            PaintMap();
        }
 public ServiceConfigWindow(Scenario scenario, bool config)
 {
     this.scenario = scenario;
     this.serviceList = scenario.ServicesList;
     InitializeComponent();
     if (config)
     {
         for (int i = 0; i < serviceList.Count; i++)
         {
             cbServiseSelector.Items.Add(serviceList[i]);
         }
         cbServiceType.IsEnabled = false;
     }
     else
     {
         cbGridRow.Height = new GridLength(0);
     }
 }
Exemplo n.º 9
0
 public BusAgent(int id, Scenario scenario, int group, int speed)
     : base(id, scenario, group, speed)
 {
     CheckPointsList = new List<WayPoint>();
     currentLength = 0.0D;
 }
Exemplo n.º 10
0
 public static AgentBase GetRandomAgentTemplateFromGroup(List<AgentTemplate> atmass, int group_id, Scenario scenario)
 {
     int j = 0;
     Random rand = new Random();
     double value = rand.Next(1, 101);
     while (value > 0 && j < atmass.Count)
     {
         value -= atmass[j].Persent;
         j++;
     }
     j--;
     int AgentSpeedms = Convert.ToInt32(MapOld.CellSize * 3600 * 1000 / (rand.Next(Convert.ToInt32(atmass[j].MinSpeed * 1000), Convert.ToInt32(atmass[j].MaxSpeed * 1000))));
     AgentBase agent = null;
     if (atmass[j].Type == typeof(HumanAgent).Name)
     {
         agent = new HumanAgent(AgentIDEnumerator.GetNextID(), scenario, group_id, AgentSpeedms);
     }
     else if (atmass[j].Type == typeof(BusAgent).Name)
     {
         agent = new BusAgent(AgentIDEnumerator.GetNextID(), scenario, group_id, AgentSpeedms)
         {
             RoadGraph = scenario.RoadGraph,
             Size = new System.Windows.Media.Media3D.Size3D(atmass[j].Length / MapOld.CellSize, atmass[j].Width / MapOld.CellSize, atmass[j].Height / MapOld.CellSize),
             MaxCapasity = atmass[j].Capasity,
             InputFactor = atmass[j].InputFactor,
             OutputFactor = atmass[j].OutputFactor
         };
     }
     else if (atmass[j].Type == typeof(TrainAgent).Name)
     {
         agent = new TrainAgent(AgentIDEnumerator.GetNextID(), scenario, group_id, AgentSpeedms, atmass[j].NumberOfCarriges)
         {
             RoadGraph = scenario.RoadGraph,
             Size = new System.Windows.Media.Media3D.Size3D(atmass[j].Length / MapOld.CellSize, atmass[j].Width / MapOld.CellSize, atmass[j].Height / MapOld.CellSize),
             MaxCapasity = atmass[j].Capasity,
             InputFactor = atmass[j].InputFactor,
             OutputFactor = atmass[j].OutputFactor
         };
     }
     if (agent != null)
     {
         agent.WayPointsList = new List<WayPoint>();
         foreach (var wp in atmass[j].WayPointsList)
         {
             agent.WayPointsList.Add((WayPoint)wp.Clone());
         }
     }
     return agent;
 }
Exemplo n.º 11
0
 public HumanAgent(int id, Scenario scenario, int group, int speed)
     : base(id, scenario, group, speed)
 {
 }