Esempio n. 1
0
 private bool CheckIfUserExists(string userName)
 {
     if (ActiveUsersList <NeatGenome> .ContainsUser(userName))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
 static void TryLaunchEvolution(Action <string> launchDelegate, string userName)
 {
     if (!ActiveUsersList <NeatGenome> .ContainsUser(userName) ||
         !ActiveUsersList <NeatGenome> .IsUserRunning(userName))
     {
         LaunchActionInThread(launchDelegate, userName);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Evolution is already running: skipping start.");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Evolution algorithm is not a static class. This means we cannot subscribe it to the
        /// event handler at the constructor. We cannot do it either right after raising the "start evolution"
        /// event, since it takes a while to take effect. This method is used before trying to raise
        /// the "next generation" event. If the evolution algorithm is foundm, it is subscribed.
        /// </summary>
        private static void LookForEvolutionAlgorithm(string userName)
        {
            if (!startedUsers.Contains(userName))
            {
                //ActiveUsersList<NeatGenome>.ListUsers();
                if (ActiveUsersList <NeatGenome> .ContainsUser(userName))
                {
                    var evolutionAlgorithm = ActiveUsersList <NeatGenome> .EvolutionAlgorithmForUser(userName);

                    startedUsers.Add(userName);
                    NextGenerationEvent += new EventHandler <EvolutionEventsArgs>(evolutionAlgorithm.ProceedNextGeneration);
                    SaveCandidate       += new EventHandler <EvolutionEventsArgs>(evolutionAlgorithm.SaveGenomeAndExit);
                    ResetEvolutionEvent += new EventHandler <EvolutionEventsArgs>(EvolutionCoordination.OnResetEvolution);
                    StopEvolutionEvent  += new EventHandler <EvolutionEventsArgs>(EvolutionCoordination.OnStopEvolution);
                    BranchEvent         += new EventHandler <EvolutionEventsArgs>(EvolutionCoordination.OnBranch);
                }
            }
        }
Esempio n. 4
0
        public static bool IsFreeEvolSlot(string userName)
        {
            // If the user is already active, it will use its own allocated spot
            if (ActiveUsersList <NeatGenome> .ContainsUser(userName))
            {
                return(true);
            }
            // If not already active, it will need a new spot:
            ActiveUsersList <NeatGenome> .RemoveInactiveUsers();

            // This wait is probably innecessary, but there have been errors where new users try to
            // take the place of others, causing trouble.
            System.Threading.Thread.Sleep(100);
            if (ActiveUsersList <NeatGenome> .Count() >= ActiveUsersList <NeatGenome> .MaxNumberOfUsers)
            {
                WriteLineForDebug("Requested a slot but the server was full.", userName);
                return(false);
            }
            return(true);
        }
Esempio n. 5
0
        private static void TryStopEvolution(string userName)
        {
            // We should not be able to ask to stop a process that has not started!
            // (And thus we ALWAYS expect this check to be true)
            if (ActiveUsersList <NeatGenome> .ContainsUser(userName))
            {
                if (ActiveUsersList <NeatGenome> .IsUserRunning(userName))
                {
                    System.Diagnostics.Debug.WriteLine("Stopping evolution process...");
                    ActiveUsersList <NeatGenome> .SetRunningStatus(userName, false);

                    ActiveUsersList <NeatGenome> .EvolutionAlgorithmForUser(userName).StopEvolution();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Evolution is already stopped: skipping stop.");
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Requested to stop " + userName + " but it was not found in the dictionary!");
            }
        }