// Starts the evaluation by first creating new agents from the current population and then restarting the track manager. private void StartEvaluation(IEnumerable <Genotype> currentPopulation) { //Create new agents from currentPopulation agents.Clear(); AgentsAliveCount = 0; //Update timer to current system time this.geneticAlgorithm.time = TimeUtilities.CurrentTimeMillis(); foreach (Genotype genotype in currentPopulation) { agents.Add(new Agent(genotype, MathHelper.SoftSignFunction, FNNTopology)); } TrackManager.Instance.SetCarAmount(agents.Count); IEnumerator <CarController> carsEnum = TrackManager.Instance.GetCarEnumerator(); for (int i = 0; i < agents.Count; i++) { if (!carsEnum.MoveNext()) { Debug.LogError("Cars enum ended before agents."); break; } carsEnum.Current.Agent = agents[i]; AgentsAliveCount++; agents[i].AgentDied += OnAgentDied; } TrackManager.Instance.Restart(); }
private static Thread InitializeMessageSyncing() { var messageSyncing = new Thread(() => { while (Syncing) { try { Requests .RequestConversationList() ?.Result ?.Conversations .SelectMany(it1 => it1.Messages) .Where(it2 => it2.TimeStamp >= TimeUtilities.CurrentTimeMillis() - 2000) .ToList() .ForEach(m => Console.WriteLine($"{Requests.RequestUserInfoOwn()?.Result.Name} => Y: {m.Value}")); Thread.Sleep(2000); } catch (ThreadAbortException) { Console.WriteLine("Stopping the syncing thread..."); break; } } }); messageSyncing.Start(); return(messageSyncing); }
private void InitTimer() { long tiempoActivo = TimeUtilities.CurrentTimeMillis(); long totalTiempo = tiempoActivo - this.time; string datos = "Generacion: " + this.GenerationCount + Environment.NewLine + "Tiempo: " + totalTiempo + Environment.NewLine; print(datos); }
public IActionResult Post() { Program.Logger.LogDebug("Handling conversation/send request"); var invalidResult = this.ProcessRequest <ConversationSendRequest>(out var request, out var apiKey); Program.Logger.LogDebug($"Parsed the request. Request: {request}"); if (invalidResult != null) { return(invalidResult); } Debug.Assert(request != null, nameof(request) + " != null"); var sender = Program.GetUserByApiKey(apiKey); var receiverName = request.Receiver; var receiver = Program.GetUserByName(receiverName); if (receiver == null) { return(BadRequest($"User {receiverName} can't be found")); } Debug.Assert(Program.DataStorage != null, "Program.DataStorage != null"); var conversation = Program.DataStorage.Conversations.Find(it => { Debug.Assert(sender != null, nameof(sender) + " != null"); return(it.ContainsUser(sender) && it.ContainsUser(receiver)); }); if (conversation == null) { Debug.Assert(sender != null, nameof(sender) + " != null"); conversation = new Conversation(sender.Name, receiver.Name, new List <Message>()); Program.DataStorage.Conversations.Add(conversation); } Debug.Assert(sender != null, nameof(sender) + " != null"); conversation.Messages.Add(new Message(sender.Name, TimeUtilities.CurrentTimeMillis(), request.Message)); Program.SaveData(); return(Ok()); }
// Appends the current generation count and the evaluation of the best genotype to the statistics file. private void WriteStatisticsToFile(IEnumerable <Genotype> currentPopulation) { foreach (Genotype genotype in currentPopulation) { string data = geneticAlgorithm.GenerationCount + "\t" + genotype.Evaluation + "\t" + (TimeUtilities.CurrentTimeMillis() - this.geneticAlgorithm.time) + "\t" + genotype.Fitness + Environment.NewLine; File.AppendAllText(statisticsFileName + ".txt", data); break; //Only write first } }