public wndAgentsGroupConfig() { InitializeComponent(); cbGridRow.Height = new GridLength(0); group = new AgentsGroup(); group.AgentTemplateList = new List <AgentTemplate>(); group.AgentDistribution = new List <int>(); }
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; }
private void createTestGroup() { npcGroup = new AgentsGroup(); if (npcs.Length > 0) { var leader = npcs[0]; npcGroup.setLeader(leader); npcGroup.addMembers(npcs); } }
/// <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); }
/// <summary> /// Join the conflicting groups into a single group /// </summary> /// <param name="conflict">An object that describes the conflict</param> /// <returns>The composite group of agents</returns> protected override AgentsGroup JoinGroups(Conflict conflict) { AgentsGroup answer = conflict.group1.Join(conflict.group2); // TODO: Currently storing the previous groups - this might lead to a memory problem when there are many agents // (if this happens then store only the costs) answer.instance.parameters[PARENT_GROUP1_KEY] = conflict.group1; answer.instance.parameters[PARENT_GROUP2_KEY] = conflict.group2; // Free memory of grandparents conflict.group1.instance.parameters.Remove(PARENT_GROUP1_KEY); conflict.group1.instance.parameters.Remove(PARENT_GROUP2_KEY); conflict.group2.instance.parameters.Remove(PARENT_GROUP1_KEY); conflict.group2.instance.parameters.Remove(PARENT_GROUP2_KEY); return(answer); }
public wndAgentsGroupConfig(AgentsGroup group) { InitializeComponent(); cbGridRow.Height = new GridLength(0); this.group = group; tbName.Text = group.Name; if (group.IsNetworkGroup) { rbNetwork.IsChecked = true; } else { rbTimer.IsChecked = true; } if (group.IsNetworkGroup) { tbAddress.Text = group.Address; tbPort.Text = group.Port.ToString(); } lvAgentsTemplate.ItemsSource = group.AgentTemplateList; }
private void cbGroup_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbGroup.SelectedIndex != -1) { group = (AgentsGroup)cbGroup.SelectedValue; tbName.Text = group.Name; if (group.IsNetworkGroup) { rbNetwork.IsChecked = true; } else { rbTimer.IsChecked = true; } if (group.IsNetworkGroup) { tbAddress.Text = group.Address; tbPort.Text = group.Port.ToString(); } lvAgentsTemplate.ItemsSource = group.AgentTemplateList; } }
private void ButtonGroupConfig_Click(object sender, RoutedEventArgs e) { wndAgentsGroupConfig wagc; if ((service as StopService).PassengersGroup == null) { wagc = new wndAgentsGroupConfig(); } else { wagc = new wndAgentsGroupConfig((service as StopService).PassengersGroup); } if (wagc.ShowDialog() == true) { AgentsGroup group = wagc.GetGroup(); group.IsServiceGroup = true; if (group.ID == -1) { group.ID = GroupIDEnumerator.GetNextID(); } (service as StopService).PassengersGroup = group; } }
public Conflict(AgentsGroup group1, AgentsGroup group2, int time) { this.group1 = group1; this.group2 = group2; timeOfConflict = time; }
public AgentGroupViewModel(AgentsGroup group, Contracts.Agents.Metadata.IAgentManagerMetadata selectedAgentType) { _group = group; _hasTargetPoint = group.TargetPoint != null; SelectedAgentType = selectedAgentType; }
void AcceptAgent_DoWork(object sender, DoWorkEventArgs e) { AgentsGroup group = e.Argument as AgentsGroup; TcpListener listener = GroupListeners[group.ID]; while (true) { bool pending = false; try { pending = listener.Pending(); } catch (InvalidOperationException) { listener = new TcpListener(System.Net.IPAddress.Parse(group.Address), group.Port); listener.Start(); pending = listener.Pending(); } if (pending) { Socket serverSocket = listener.AcceptSocket(); if (serverSocket.Connected) { NetworkStream networkStream = new NetworkStream(serverSocket); StreamReader streamReader = new StreamReader(networkStream); StreamWriter streamWriter = new StreamWriter(networkStream); Random rand = new Random(); while (true) { try { streamReader.ReadLine(); } catch (IOException) { break; } int j = 0; double value = rand.NextDouble(); while (value > 0 && j < group.AgentTemplateList.Count) { value -= group.AgentTemplateList[j].Persent; j++; } j--; int AgentSpeedms = Convert.ToInt32(MapOld.CellSize * 3600 * 1000 / (rand.Next(Convert.ToInt32(group.AgentTemplateList[j].MinSpeed * 1000), Convert.ToInt32(group.AgentTemplateList[j].MaxSpeed * 1000)))); AgentBase agent = null; if (group.AgentTemplateList[j].Type == typeof(HumanAgent).Name) { agent = new HumanAgent(AgentIDEnumerator.GetNextID(), this, group.ID, AgentSpeedms); } else if (group.AgentTemplateList[j].Type == typeof(BusAgent).Name) { agent = new BusAgent(AgentIDEnumerator.GetNextID(), this, group.ID, AgentSpeedms) { RoadGraph = this.RoadGraph, Size = new System.Windows.Media.Media3D.Size3D(group.AgentTemplateList[j].Length / MapOld.CellSize, group.AgentTemplateList[j].Width / MapOld.CellSize, group.AgentTemplateList[j].Height / MapOld.CellSize), MaxCapasity = group.AgentTemplateList[j].Capasity, InputFactor = group.AgentTemplateList[j].InputFactor, OutputFactor = group.AgentTemplateList[j].OutputFactor }; } else if (group.AgentTemplateList[j].Type == typeof(TrainAgent).Name) { agent = new TrainAgent(AgentIDEnumerator.GetNextID(), this, group.ID, AgentSpeedms, group.AgentTemplateList[j].NumberOfCarriges) { RoadGraph = this.RoadGraph, Size = new System.Windows.Media.Media3D.Size3D(group.AgentTemplateList[j].Length / MapOld.CellSize, group.AgentTemplateList[j].Width / MapOld.CellSize, group.AgentTemplateList[j].Height / MapOld.CellSize), MaxCapasity = group.AgentTemplateList[j].Capasity, InputFactor = group.AgentTemplateList[j].InputFactor, OutputFactor = group.AgentTemplateList[j].OutputFactor }; } if (agent != null) { agent.WayPointsList = new List <WayPoint>(); foreach (var point in group.AgentTemplateList[j].WayPointsList) { agent.WayPointsList.Add(point); } agentsList.Add(agent); } } } } Thread.Sleep(TimeSpan.FromMilliseconds(1000)); } }
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); }