예제 #1
0
        public Simulation(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            //System.Threading.Timer t = new System.Threading.Timer(new System.Threading.TimerCallback((o) => Step()), null, 0, (long)STEP_TIME_MS);

            _scenario = scenario;
            RoadGraph = new Graph<WayPoint, PathFigure>();
            if (_scenario.RoadGraph != null)
            {
                foreach (var node in _scenario.RoadGraph.Nodes)
                {
                    RoadGraph.Add(node);
                }
                foreach (var edge in _scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));
                    RoadGraph.AddEdge(edge.Start, edge.End, pathGeom.Figures.First());
                }
            }

            _analisisCollector = new Analisis.AnalisisCollector();
            _map = _scenario.Map;
            _start = _scenario.StartTime;
            _end = _scenario.EndTime;
            _simulationTime = _scenario.StartTime;
            Init(STEP_TIME_MS);
        }
예제 #2
0
        public wndDiagrammsConfig(AnalisisCollector analisis, ConfigWindows.ExperimentConfig cnfg, List <PaintObject> pol)
        {
            this.analisis        = analisis;
            this.cnfg            = cnfg;
            this.paintObjectList = pol;

            InitializeComponent();

            if (cnfg.AgentAverangeLenght)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_LENGHT_NAME);
            }
            if (cnfg.AgentAverangeLenghtByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_LENGHT_BY_GROUP_NAME);
            }
            if (cnfg.AgentAverangeSpeed)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_SPEED_NAME);
            }
            if (cnfg.AgentAverangeSpeedByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_SPEED_BY_GROUP_NAME);
            }
            if (cnfg.AgentAverangeTime)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_TIME_NAME);
            }
            if (cnfg.AgentAverangeTimeByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_TIME_BY_GROUP_NAME);
            }
            if (cnfg.AgentCountOnMap)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_COUNT_ON_MAP_NAME);
            }
            if (cnfg.AgentCountOnMapByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_COUNT_ON_MAP_BY_GROUP_NAME);
            }
            if (cnfg.AgentInputOutput)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_INPUT_OUTPUT_NAME);
            }
            if (cnfg.AgentInputOutputByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_INPUT_OUTPUT_BY_GROUP_NAME);
            }
            if (cnfg.SpectralDensity)
            {
                cbDataSource.Items.Add(AnalisisConstants.SPECTRAL_DENSITY_NAME);
            }
        }
        public wndDiagrammsConfig(AnalisisCollector analisis, ConfigWindows.ExperimentConfig cnfg, List<PaintObject> pol)
        {
            this.analisis = analisis;
            this.cnfg = cnfg;
            this.paintObjectList = pol;

            InitializeComponent();

            if (cnfg.AgentAverangeLenght)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_LENGHT_NAME);
            }
            if (cnfg.AgentAverangeLenghtByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_LENGHT_BY_GROUP_NAME);
            }
            if (cnfg.AgentAverangeSpeed)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_SPEED_NAME);
            }
            if (cnfg.AgentAverangeSpeedByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_SPEED_BY_GROUP_NAME);
            }
            if (cnfg.AgentAverangeTime)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_TIME_NAME);
            }
            if (cnfg.AgentAverangeTimeByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_AVERANGE_TIME_BY_GROUP_NAME);
            }
            if (cnfg.AgentCountOnMap)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_COUNT_ON_MAP_NAME);
            }
            if (cnfg.AgentCountOnMapByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_COUNT_ON_MAP_BY_GROUP_NAME);
            }
            if (cnfg.AgentInputOutput)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_INPUT_OUTPUT_NAME);
            }
            if (cnfg.AgentInputOutputByGroup)
            {
                cbDataSource.Items.Add(AnalisisConstants.AGENT_INPUT_OUTPUT_BY_GROUP_NAME);
            }
            if (cnfg.SpectralDensity)
            {
                cbDataSource.Items.Add(AnalisisConstants.SPECTRAL_DENSITY_NAME);
            }
        }
예제 #4
0
        public void InitializeStepScenario(ExperimentConfig cnfg)
        {
            _scenarioConfig = cnfg;
            currentTime = cnfg.StartTime;
            int groupCount = agentGroups.Count;
            for (int i = 0; i < ServicesList.Count; i++)
            {
                if (ServicesList[i] is StopService)
                {
                    if ((ServicesList[i] as StopService).PassengersGroup != null)
                    {
                        groupCount++;
                    }
                }
                if (ServicesList[i] is TurnstileService)
                {
                    if ((ServicesList[i] as TurnstileService).TurnstileGeometry != null)
                    {
                        PaintObject obj = new PaintObject(ServicesList[i].Name);

                    }
                }
                ServicesList[i].Initialize();
            }
            _analisisViewModel = new AnalisisViewModel();

            _analisis = new AnalisisCollector(map.GetMap().GetLength(0), map.GetMap().GetLength(1), groupCount);

            if (GroupListeners != null)
            {
                foreach (var listener in GroupListeners.Values)
                {
                    listener.Stop();
                }
            }
            GroupListeners = new Dictionary<int, TcpListener>();
            ServersSocketList = new Dictionary<int, Socket>();
            agentsList = new List<AgentBase>();
            AgentByStepCounter = new Dictionary<int, double>();
            for (int i = 0; i < agentGroups.Count;i++ )
            {
                if (agentGroups[i].IsNetworkGroup)
                {
                    TcpListener tcpListener = new TcpListener(System.Net.IPAddress.Parse(agentGroups[i].Address), agentGroups[i].Port);
                    tcpListener.Start();
                    GroupListeners.Add(agentGroups[i].ID, tcpListener);
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += new DoWorkEventHandler(AcceptAgent_DoWork);
                    worker.RunWorkerAsync(agentGroups[i]);
                }
                else
                {
                    AgentByStepCounter.Add(agentGroups[i].ID, 0);
                }
            }
        }
예제 #5
0
        public void InitializeScenario(ExperimentConfig cnfg)
        {
            currentTime = cnfg.StartTime;
            _analisis = new AnalisisCollector(map.GetMap().GetLength(0), map.GetMap().GetLength(1), agentGroups.Count);
            SocketWritersList = new Dictionary<int, StreamWriter>();
            IsStoped = false;

            _workersList.Clear();
            agentsList.Clear();

            foreach (var group in agentGroups.FindAll(delegate(AgentsGroup ag) { return !ag.IsServiceGroup; }))
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.WorkerSupportsCancellation = true;
                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                worker.RunWorkerAsync(group);
                _workersList.Add(worker);
                //if (group.ID == 1)
                //{
                //    try
                //    {
                //        TcpClient tcpClient;
                //        tcpClient = new TcpClient();
                //        tcpClient.NoDelay = true;
                //        tcpClient.Connect(System.Net.IPAddress.Loopback, 5554);
                //        Console.WriteLine("Соединение с 127.0.0.1:5554 установлено");
                //        NetworkStream networkStream = tcpClient.GetStream();
                //        StreamWriter streamWriter = new StreamWriter(networkStream);
                //        SocketWritersList.Add(1, streamWriter);
                //    }
                //    catch (SocketException ex)
                //    {
                //        Console.WriteLine(ex);
                //    }
                //}
            }
            _mainTimer.Interval = TimeSpan.FromMilliseconds(300);
            _mainTimer.Tick += new EventHandler(mainTimer_Tick);
            _mainTimer.Start();
            DispatcherTimer analisisTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };
            analisisTimer.Tick += analisisTimer_Tick;
            analisisTimer.Start();
        }