Пример #1
0
 //Speech interrupted state
 private void ReceiveStop(string message)
 {
     if (OnStop != null)
     {
         OnStop.Invoke(message);
     }
 }
Пример #2
0
        private bool recurringConverse(ConverseResponse prevResponse)
        {
            bool doOneMoreStep = false;
            T    tempContext   = default(T);

            switch (prevResponse.typeCode)
            {
            case ConverseResponse.Types.merge:
                tempContext   = _merge.Invoke(conversationId, context, prevResponse.entities, prevResponse.confidence);
                doOneMoreStep = true;
                break;

            case ConverseResponse.Types.msg:
                _say.Invoke(conversationId, context, prevResponse.msg, prevResponse.confidence);
                doOneMoreStep = true;
                break;

            case ConverseResponse.Types.action:
                tempContext   = _action.Invoke(conversationId, context, prevResponse.action, prevResponse.entities, prevResponse.confidence);
                doOneMoreStep = true;
                break;

            case ConverseResponse.Types.stop:
                tempContext   = _stop.Invoke(conversationId, context);
                doOneMoreStep = false;
                break;

            default:
                break;
            }

            if (tempContext != null)
            {
                context = tempContext;
            }

            if (doOneMoreStep)
            {
                ConverseResponse response = client.Converse(conversationId, null, context);
                return(recurringConverse(response));
            }

            return(true);
        }
Пример #3
0
 /// <summary>
 /// Closes all the handlers for the imageServer (invoked when service is terminated)..
 /// </summary>
 public void CloseImageServer()
 {
     StopHandler.Invoke(this, new DirectoryCloseEventArgs("*", null));
 }
Пример #4
0
        /// <summary>
        /// Method responsible for the optimization.
        /// </summary>
        /// <returns>An object containing the optimized values of the parameters as well as other characteristics of the optimization process.</returns>
        public Result Optimize(ArrayList ElementsTrans)
        {
            bool genRand = ElementsTrans == null;

            // Create a list object for elementes.
            Elements = new ArrayList();
            if (!genRand)
            {
                // Transfer elements importing
                foreach (BaseElement Element in ElementsTrans)
                {
                    Elements.Add(GetNewElement(FitnessFunction, Element.Position));
                }
            }
            // Create a random number generator object.
            RNG = new Random();
            // The ordinal number of the actual generation.
            Generation = 1;
            // Define a logical variable that keeps track of the current state.
            Stop = false;
            // Start execturion timer
            var timer = new System.Diagnostics.Stopwatch();

            timer.Reset();
            timer.Start();
            if (genRand)
            {
                // Put the first element into the pool.
                Elements.Add(GetNewElement(FitnessFunction, InitialParameters));
            }
            // Initializing the first element takes an evaluation, so we initialize to one
            Evaluation = 1;
            // Check if the stopping condition was met
            if (StopHandler != null)
            {
                Stop = StopHandler.Invoke(this, Elements);
            }
            else
            {
                CheckStop();
            }
            // Create an object for the returned information.
            Info = new Dictionary <InfoTypes, object>();
            // Add the affinity (performance) corresponding to the initial parameter values.
            Info.Add(InfoTypes.InitialFitness, ((BaseElement)Elements[0]).Fitness);
            if (genRand)
            {
                // Create the rest of the initial pool (first generation) of elementes creating elementes at random positions.
                CreateRandomElements(NumberOfElements - 1);
            }
            // Raise GenerationCreated event if there are any subscribers.
            GenerationCreated?.Invoke(this, Elements, GetFitnesses());
            ArrayList BestAffinities = new ArrayList();

            BestAffinities.Add(((BaseElement)Elements[0]).Fitness);
            if (StopHandler != null)
            {
                Stop = StopHandler.Invoke(this, Elements);
            }
            else
            {
                CheckStop();
            }

            //Begin the optimization process
            while (!Stop)
            {
                if (Slow)
                {
                    System.Threading.Thread.Sleep(100);
                }
                Generation++;
                // Create next generation.
                CreateNextGeneration();
                BestAffinities.Add(((BaseElement)Elements[0]).Fitness);
                // Raise GenerationCreated event if there are any subscribers.
                GenerationCreated?.Invoke(this, Elements, GetFitnesses());
                // Stop if the stopping criteria is the number of generations and the number of allowed generations is reached
                if (StopHandler != null)
                {
                    Stop = StopHandler.Invoke(this, Elements);
                }
                else
                {
                    CheckStop();
                }
            }
            // Stop timer
            timer.Stop();
            // Create an array for the parameters (position) of the best antibody.
            var Best = new ArrayList();

            for (int dim = 0; dim < InitialParameters.Count; dim++)
            {
                Best.Add(((BaseElement)Elements[0])[dim]);
            }
            // Add the affinity (performance) value of the best antibody to the returned information.
            Info.Add(InfoTypes.FinalFitness, ((BaseElement)Elements[0]).Fitness);
            // Add munber of generations.
            Info.Add(InfoTypes.Generations, Generation);
            // Add number of affinity evaluations.
            Info.Add(InfoTypes.Evaluations, Evaluation);
            // Define returned values.
            Info.Add(InfoTypes.Affinities, BestAffinities);
            // Add execution time to result info
            Info.Add(InfoTypes.ExecutionTime, timer.ElapsedMilliseconds);
            var res = new Result(Best, Info);

            return(res);
        }