Пример #1
0
        /// <summary>
        /// Run Algorithm
        /// </summary>
        /// <param name="NotVisited"></param>
        public void goAlgorithm(List <Scene> notVisited)
        {
            comp++;
            if (notVisited.Count == 0)
            {
                // Poda
                comp++;
                if (evaluation.isFactible(visited))
                {
                    memory += evaluation.memory;

                    evaluation.seeCombination(visited);

                    Console.WriteLine("Costo: " + evaluation.getCostCalendar(visited));

                    comp++;
                    if (evaluation.getCostCalendar(visited) <= bestCalendar.bestCost)   //Change best calendar
                    {
                        changeBestCalendar(visited);
                    }
                    memory += evaluation.memory;
                    asig   += evaluation.asig; comp += evaluation.comp;
                }
                else
                {
                    memory += evaluation.memory;
                }
                asig += evaluation.asig; comp += evaluation.comp;
            }
            else
            {
                asig++;
                memory += new Scene(0).valueMemory;
                foreach (Scene scene in notVisited)
                {
                    asig++;
                    // Combination
                    this.visited.Remove(scene); this.visited.Add(scene); asig += 2;

                    List <Scene> auxScene = evaluation.shallowClone(notVisited); asig++;
                    memory += auxScene.Count * new Scene(0).valueMemory;
                    auxScene.Remove(scene); asig++;


                    cantNodes++;
                    goAlgorithm(auxScene);
                }
            }
        }
        /************************************************ Evaluacion**************************************************/
        #region Evaluating
        /// <summary>
        /// Check if the calendar is factible or not factible and search the best cost
        /// </summary>
        public void evaluation()
        {
            int cost = evaluating.getCostCalendar(father);

            memoryOrder += evaluating.memory + 32;
            memoryCycle += evaluating.memory + 32;
            asig++;
            asig += evaluating.asig;
            comp += evaluating.comp;
            if (cost < bestOne.bestCost)
            {
                comp++;
                if (evaluating.isFactible(father))
                {
                    bestOne.listScenes = evaluating.shallowClone(father);
                    memoryOrder       += new Scene(0).valueMemory *father.Count;
                    memoryCycle       += new Scene(0).valueMemory *father.Count;
                    bestOne.bestCost   = cost;
                    asig += 2;
                }
                comp         = evaluating.comp;
                asig         = evaluating.asig;
                memoryOrder += evaluating.memory;
                memoryCycle += evaluating.memory;
            }
            comp++;
            /********************************************/
            cost         = evaluating.getCostCalendar(mother);
            memoryOrder += evaluating.memory;
            memoryCycle += evaluating.memory;
            asig++;
            asig += evaluating.asig;
            comp += evaluating.comp;
            if (cost < bestOne.bestCost)
            {
                if (evaluating.isFactible(mother))
                {
                    bestOne.listScenes = evaluating.shallowClone(mother);
                    bestOne.bestCost   = cost;
                    memoryOrder       += new Scene(0).valueMemory *mother.Count;
                    memoryCycle       += new Scene(0).valueMemory *mother.Count;
                    asig += 2;
                }
                comp = evaluating.comp;
                asig = evaluating.asig;
                comp++;
                memoryOrder += evaluating.memory;
                memoryCycle += evaluating.memory;
            }
            comp++;
            comp += 2;

            if (sonOne != null && sonTwo != null)
            {
                cost = evaluating.getCostCalendar(sonOne);
                asig++;
                asig        += evaluating.asig;
                comp        += evaluating.comp;
                memoryOrder += evaluating.memory;
                memoryCycle += evaluating.memory;
                if (cost < bestOne.bestCost)
                {
                    if (evaluating.isFactible(sonOne))
                    {
                        bestOne.listScenes = evaluating.shallowClone(sonOne);
                        bestOne.bestCost   = cost;
                        memoryOrder       += new Scene(0).valueMemory *sonOne.Count;
                        memoryCycle       += new Scene(0).valueMemory *sonOne.Count;
                        asig += 2;
                    }
                    comp = evaluating.comp;
                    asig = evaluating.asig;
                    comp++;
                    memoryOrder += evaluating.memory;
                    memoryCycle += evaluating.memory;
                }
                comp++;
                comp += 2;
                cost  = evaluating.getCostCalendar(sonTwo);
                asig++;
                asig        += evaluating.asig;
                comp        += evaluating.comp;
                memoryOrder += evaluating.memory;
                memoryCycle += evaluating.memory;
                if (cost < bestOne.bestCost)
                {
                    if (evaluating.isFactible(sonTwo))
                    {
                        bestOne.listScenes = evaluating.shallowClone(sonTwo);
                        bestOne.bestCost   = cost;
                        memoryOrder       += new Scene(0).valueMemory *sonTwo.Count;
                        memoryCycle       += new Scene(0).valueMemory *sonTwo.Count;
                        asig += 2;
                    }
                    comp = evaluating.comp;
                    asig = evaluating.asig;
                    comp++;
                    memoryOrder += evaluating.memory;
                    memoryCycle += evaluating.memory;
                }
                comp++;
                comp += 2;
            }

            if (runner != 10)
            {
                runner += 1;
                selection();
            }

            else
            {
                Console.Write("====================================" +
                              "\n| Mejor Combinacion: ");
                foreach (Scene item in bestOne.listScenes)
                {
                    Console.Write(item.id + "-");
                }
                Console.WriteLine("\n costo => " + bestOne.bestCost);
                Console.WriteLine("Asinaciones: " + asig);
                Console.WriteLine("Comparaciones: " + comp);
                Console.WriteLine("====================================\n");
            }
        }