/// <summary>
        /// TEST Method
        /// </summary>
        public ScenarioModel CreateScenario()
        {
            ScenarioModel model = new ScenarioModel();
            using (StreamReader reader = new StreamReader(@"test.svg"))
            {
                List<string> mapSource = new List<string>();
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    mapSource.Add(line);
                }
            }
            //using (MapReader mreader = new MapReader(@"test.svg"))
            //{
            //    if (mreader.Read())
            //    {
            //        model.Map = mreader.GetMap(new Dictionary<string, byte>());
            //    }
            //}
            model.AgentGroups = new List<AgentsGroup>();
            model.StartTime = new DateTime(2013, 4, 15);
            model.EndTime = new DateTime(2013, 4, 16);
            var group = new AgentsGroup(0,"");
            group.AgentsDistibution.Add(DayOfWeek.Monday, new int[] { 200, 200, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
            //group.AgentTypes = new Dictionary<string, double>();
            //group.AgentTypes.Add("passenger", 1.0);
            var settings = new Dictionary<string, object>();
            settings.Add("startPosition", new Point());
            settings.Add("checkPoints", new List<WayPoint>() { new WayPoint(100, 100), new WayPoint(400, 100), new WayPoint(780, 580) });
            settings.Add("size", new Size3D(0.5, 1.8, 0.3));
            settings.Add("maxSpeed", 1);
            settings.Add("acceleration", 0);
            settings.Add("deceleration", 0);
            //group.AgentsConfig.Add("passenger", settings);
            group.Type = AgentGroupInitType.Distribution;
            group.Name = "Тестовая группа";
            group.SourcePoint = new Enviroment.WayPoint(0, 0, 0, 1, 8);
            model.AgentGroups = new List<AgentsGroup>();
            model.AgentGroups.Add(group);

            return model;
        }
 private void Add()
 {
     ulong id = _idGenerator.GetID();
     AgentsGroup ag = new AgentsGroup(id, "Новая группа " + id);
     var groupVM = new AgentGroupViewModel(ag, AgentTypes.FirstOrDefault());
     AgentGroups.Add(groupVM);
     SelectedGroup = groupVM;
 }
 public AgentGroupViewModel(AgentsGroup group, Contracts.Agents.Metadata.IAgentManagerMetadata selectedAgentType)
 {
     _group = group;
     _hasTargetPoint = group.TargetPoint != null;
     SelectedAgentType = selectedAgentType;
 }
Пример #4
0
        private IEnumerable<WayPoint> GetAgentRoute(AgentsGroup group)
        {
            if (_routesHash.ContainsKey(group.Id))
                return _routesHash[group.Id];

            WayPoint source = group.SourcePoint;
            WayPoint target = group.TargetPoint;

            if (_scenario.TransitionGraph == null || _scenario.TransitionGraph.Nodes.Count() == 0)
                return null;

            if (_transitionsGraph == null)
            {
                _transitionsGraph = new AdjacencyGraph<WayPoint, Edge<WayPoint>>();
                _transitionsGraph.AddVertexRange(_scenario.TransitionGraph.Nodes);
                _transitionsGraph.AddEdgeRange(from edge in _scenario.TransitionGraph.Edges select new Edge<WayPoint>(edge.Start, edge.End));
            }

            var route = new List<WayPoint>();
            route.Add(source);

            if (target != null)
            {
                IEnumerable<Edge<WayPoint>> result;
                if (_transitionsGraph.ShortestPathsDijkstra((e) => _scenario.TransitionGraph.GetEdgeData(e.Source, e.Target), source).Invoke(target, out result))
                {
                    route.AddRange(result.Select(e => e.Target));
                }
                else
                {
                    route = null;
                }
                _routesHash[group.Id] = route;
                return route;
            }
            //TODO допилить адекватное построение маршрута

            var curNode = source;

            int tryCount = _scenario.TransitionGraph.Nodes.Count();

            while (_scenario.TransitionGraph.HasChildNodes(curNode))
            {
                double rand_value = rand.NextDouble();
                var edges = _scenario.TransitionGraph.GetEdgesFrom(curNode).ToList();
                if (route.Count > 1)
                {
                    edges.RemoveAll(e => e.End == route[route.Count - 2] || e.End.LayerId > route.Last().LayerId);
                }
                foreach (var edge in edges)
                {
                    rand_value -= edge.Data / edges.Sum(e => e.Data);
                    if (rand_value <= 0)
                    {
                        route.Add(edge.End);
                        if (edge.End.IsOutput)
                        {
                            route.Remove(route.First());
                            return route;
                        }
                        curNode = edge.End;
                        break;
                    }
                }
                if (tryCount-- == 0) break;
            }
            route.Remove(route.First());
            return route;
        }