// https://youtu.be/MjCjQCCtmcE static void Main(string[] args) { System.Collections.Queue miQueue = new System.Collections.Queue(); // Addicionamos objetos miQueue.Enqueue("Manzana"); miQueue.Enqueue("Freza"); miQueue.Enqueue("Pera"); // Interactuamos Show.Show(miQueue); // Obtener el primer objeto y sacarlo del Queue Console.WriteLine("DeQueue {0}", miQueue.Dequeue()); Console.WriteLine("DeQueue {0}", miQueue.Dequeue()); Show.Show(miQueue, "Despues DeQueue"); // Add Elementos miQueue.Enqueue("Limon"); miQueue.Enqueue("Mango"); miQueue.Enqueue("Ciruela"); // Obtener el primer objeto y sin sacarlo del Queue Console.WriteLine("Peek {0}", miQueue.Peek()); Show.Show(miQueue, "Despues Peek"); // Conteo de Objeto Console.WriteLine("Numero de Objetos {0}\n", miQueue.Count); // Verifica si existe un objeto Console.WriteLine("Hay Mango {0}", miQueue.Contains("Mango")); Console.WriteLine("Hay Manzana {0}", miQueue.Contains("Manzana")); System.Console.ReadKey(); }
static void Main(string[] args) { System.Collections.Queue queue = new System.Collections.Queue(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); Console.WriteLine("1 in Queue:{0}", queue.Contains(1)); Console.WriteLine("Remove 1:{0}", queue.Dequeue()); Console.WriteLine("Peek1:{0}", queue.Peek()); object[] numArray = queue.ToArray(); Console.WriteLine(string.Join(", ", numArray)); }
// ациклічність графа public bool NodeIsAcyclic(int currNode, int algorithm, bool is_mess_show) { int n = TopList.Count; int[] status = new int[n]; int[,] matrix = Matrix(algorithm); for (int i = 0; i < n; i++) { status[i] = 0; } int curr = currNode; System.Collections.Queue och = new System.Collections.Queue(); och.Enqueue(curr); all_neighbors_nodes.Clear(); while (och.Count != 0) { curr = Convert.ToInt32(och.Dequeue()); all_neighbors_nodes.Add(curr); for (int i = 0; i < n; i++) { if (matrix[curr, i] != 0 && status[i] == 0) { status[i] = 1; // відвідали вершину och.Enqueue(i); if (och.Contains(currNode)) { if (is_mess_show) { MessageBox.Show("Цикл в " + TopList[currNode].id + " вершині"); } return(false); } } } } return(true); }
public bool IsQueued(ProcessInfo Info) { return(processQueue.Contains(Info)); }
//--------------------------------------------------------------------- ///<summary> ///Spread from Epicenters to outbreak zone using either a fixed radius method ///or a percolation method with variable neighborhood sizes. ///</summary> //--------------------------------------------------------------------- private static void SpreadEpicenters(IAgent agent, List <Location> iSites, int BDAtimestep) { //PlugIn.ModelCore.Log.WriteLine("Spreading to New Epicenters. There are {0} initiation sites.", iSites.Count); if (iSites == null) { PlugIn.ModelCore.UI.WriteLine("ERROR: The newSiteList is empty."); } int dispersalDistance = agent.DispersalRate * BDAtimestep; foreach (Location siteLocation in iSites) { Site initiationSite = PlugIn.ModelCore.Landscape.GetSite(siteLocation); if (agent.DispersalTemp == DispersalTemplate.MaxRadius) { foreach (RelativeLocation relativeLoc in agent.DispersalNeighbors) { Site neighbor = initiationSite.GetNeighbor(relativeLoc); if (neighbor != null && neighbor.IsActive) { agent.OutbreakZone[neighbor] = Zone.Newzone; } } } if (agent.DispersalTemp != DispersalTemplate.MaxRadius) { //PlugIn.ModelCore.Log.WriteLine(" Begin Percolation Spread to Neighbors."); //Queue<Site> sitesToConsider = new Queue<Site>(); System.Collections.Queue sitesToConsider = new System.Collections.Queue(); sitesToConsider.Enqueue(initiationSite); while (sitesToConsider.Count > 0) { //PlugIn.ModelCore.Log.WriteLine(" There are {0} neighbors being processed.", sitesToConsider.Count); Site site = (Site)sitesToConsider.Dequeue(); agent.OutbreakZone[site] = Zone.Newzone; foreach (RelativeLocation relativeLoc in agent.DispersalNeighbors) { Site neighbor = site.GetNeighbor(relativeLoc); //Do not spread to inactive neighbors: if (neighbor == null || !neighbor.IsActive) { continue; } //Do NOT spread to neighbors that have already been targeted for //disturbance: if (agent.OutbreakZone[neighbor] == Zone.Newzone) { continue; } //Check for duplicates: if (sitesToConsider.Contains(neighbor)) { continue; } //PlugIn.ModelCore.Log.WriteLine("Distance between neighbor and center = {0}.", DistanceBetweenSites(neighbor, initiationSite)); //PlugIn.ModelCore.Log.WriteLine("SV={0:0.0}.", SiteVars.Vulnerability[neighbor]); //PlugIn.ModelCore.Log.WriteLine("Threshold={0:0.0}.", agent.EpidemicThresh); if (DistanceBetweenSites(neighbor, initiationSite) <= dispersalDistance && SiteVars.Vulnerability[neighbor] > agent.EpidemicThresh) { sitesToConsider.Enqueue(neighbor); } } } } } }
// ациклічність графа public bool NodeIsAcyclic(int currNode, int algorithm, bool is_mess_show) { int n = TopList.Count; int[] status = new int[n]; int[,] matrix = Matrix(algorithm); for (int i = 0; i < n; i++) status[i] = 0; int curr = currNode; System.Collections.Queue och = new System.Collections.Queue(); och.Enqueue(curr); all_neighbors_nodes.Clear(); while (och.Count != 0) { curr = Convert.ToInt32(och.Dequeue()); all_neighbors_nodes.Add(curr); for (int i = 0; i < n; i++) if (matrix[curr, i] != 0 && status[i] == 0) { status[i] = 1; // відвідали вершину och.Enqueue(i); if (och.Contains(currNode)) { if (is_mess_show) MessageBox.Show("Цикл в " + TopList[currNode].id + " вершині"); return false; } } } return true; }
private void Update(HttpListenerRequest request, UpdateType type) { if (!request.HasEntityBody) { throw new NoPostDataException("No post data"); } // Debug messages if (log.IsDebugEnabled) { log.Debug("Updating ids..."); log.Debug("Transforming the I/O stuff..."); } System.IO.Stream body = request.InputStream; System.Text.Encoding encoding = request.ContentEncoding; System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); string ids = reader.ReadToEnd(); // Debug messages if (log.IsDebugEnabled) { log.Debug("IO proccesing done!"); log.Debug("IDs to update: " + ids); log.Debug("Spliting ids..."); } string[] idList = ids.Split(' '); // The clients MUST send ids with a space separator // Debug messages if (log.IsDebugEnabled) { log.Debug("Ids splited!"); log.Debug("IDs to update: " + idList.Length); log.Debug("Locking 'updates' and adding ids..."); } System.Collections.Queue queue = null; EventWaitHandle ewh = null; switch (type) { case UpdateType.Tipologia: queue = this.updates.Tipologias; ewh = this.updates.WHTipologias; break; case UpdateType.Assunto: queue = this.updates.Assuntos; ewh = this.updates.WHAssuntos; break; case UpdateType.Produtor: queue = this.updates.Produtores; ewh = this.updates.WHProdutores; break; case UpdateType.NivelDocumental: queue = this.updates.NiveisDocumentais; ewh = this.updates.WHNiveisDocumentais; break; case UpdateType.NivelDocumentalInternet: queue = this.updates.NiveisDocumentaisInternet; ewh = this.updates.WHNiveisDocumentaisInternet; break; case UpdateType.NivelDocumentalComProdutores: queue = this.updates.NiveisDocumentaisComProdutores; ewh = this.updates.WHNiveisDocumentaisComProdutores; break; case UpdateType.UnidadeFisica: queue = this.updates.UnidadesFisicas; ewh = this.updates.WHUnidadesFisicas; break; } foreach (string idS in idList) { long id = -1; long.TryParse(idS, out id); if (id != -1 && !queue.Contains(id)) { queue.Enqueue(id); } } ewh.Set(); // Debug messages if (log.IsDebugEnabled) { log.Debug("IDs added!"); log.Debug("Thread sinalized!"); } }
//--------------------------------------------------------------------- ///<summary> ///Spread from Epicenters to outbreak zone using either a fixed radius method ///or a percolation method with variable neighborhood sizes. ///</summary> //--------------------------------------------------------------------- private static void SpreadEpicenters(IAgent agent, List<Location> iSites, int BDAtimestep) { //PlugIn.ModelCore.UI.WriteLine("Spreading to New Epicenters. There are {0} initiation sites.", iSites.Count); if(iSites == null) PlugIn.ModelCore.UI.WriteLine("ERROR: The newSiteList is empty."); int dispersalDistance = agent.DispersalRate * BDAtimestep; foreach(Location siteLocation in iSites) { Site initiationSite = PlugIn.ModelCore.Landscape.GetSite(siteLocation); if(agent.DispersalTemp == DispersalTemplate.MaxRadius) { foreach (RelativeLocation relativeLoc in agent.DispersalNeighbors) { Site neighbor = initiationSite.GetNeighbor(relativeLoc); if (neighbor != null && neighbor.IsActive) agent.OutbreakZone[neighbor] = Zone.Newzone; } } if(agent.DispersalTemp != DispersalTemplate.MaxRadius) { //PlugIn.ModelCore.UI.WriteLine(" Begin Percolation Spread to Neighbors."); //Queue<Site> sitesToConsider = new Queue<Site>(); System.Collections.Queue sitesToConsider = new System.Collections.Queue(); sitesToConsider.Enqueue(initiationSite); while (sitesToConsider.Count > 0 ) { //PlugIn.ModelCore.UI.WriteLine(" There are {0} neighbors being processed.", sitesToConsider.Count); Site site = (Site)sitesToConsider.Dequeue(); agent.OutbreakZone[site] = Zone.Newzone; foreach (RelativeLocation relativeLoc in agent.DispersalNeighbors) { Site neighbor = site.GetNeighbor(relativeLoc); //Do not spread to inactive neighbors: if(neighbor == null || !neighbor.IsActive) continue; //Do NOT spread to neighbors that have already been targeted for //disturbance: if (agent.OutbreakZone[neighbor] == Zone.Newzone) continue; //Check for duplicates: if (sitesToConsider.Contains(neighbor)) continue; //PlugIn.ModelCore.UI.WriteLine("Distance between neighbor and center = {0}.", DistanceBetweenSites(neighbor, initiationSite)); //PlugIn.ModelCore.UI.WriteLine("SV={0:0.0}.", SiteVars.Vulnerability[neighbor]); //PlugIn.ModelCore.UI.WriteLine("Threshold={0:0.0}.", agent.EpidemicThresh); if(DistanceBetweenSites(neighbor, initiationSite) <= dispersalDistance && SiteVars.Vulnerability[neighbor] > agent.EpidemicThresh) { sitesToConsider.Enqueue(neighbor); } } } } } }