Exemplo n.º 1
0
        //Runs the algoritm for number of iterations
        public override void Run(Configuration config)
        {
            log = new RandomLogSpecification(data.DataFileName, config.RandomSeed, config.NumberOfRuns, config.PenaltyCoefficient);
            solution = new SolutionSpecification();

            BitArray routerswitches = new BitArray((int)data.RouterCount);
            double highestfitness = 0.0;
            BitArray best = new BitArray((int)data.RouterCount);
            for(int i = 0; i < config.NumberOfRuns; i++)
            {
                routerswitches = new BitArray((int)data.RouterCount);
                int numbertoswitch = randomgenerator.Next((int)data.RouterCount);
                for(int j = 0; j < numbertoswitch; j++)
                {
                    int switching;
                    while(routerswitches.Get(switching = randomgenerator.Next((int)data.RouterCount)) == true);
                    routerswitches.Set(switching, true);
                }

                double fitness = FitnessEvaluation(data.NetworkPaths, routerswitches, numbertoswitch, config.PenaltyCoefficient);

                if(fitness > highestfitness)
                {
                    ((RandomLogSpecification)log).AddEvaluation(i, fitness);
                    highestfitness = fitness;
                    best = (BitArray)routerswitches.Clone();
                }
            }

            solution.RoutersTurnedOff = ExtensionMethods.ConvertBitArrayToOffRouterNumbers(best, data.HostCount);
        }
Exemplo n.º 2
0
        //Runs the algoritm for number of iterations
        public override void Run(int iterations, int randseed)
        {
            log = new RandomLogSpecification(data.DataFileName, randseed, iterations);
            solution = new SolutionSpecification();

            BitArray routerswitches = new BitArray((int)data.RouterCount);
            double highestfitness = 0.0;
            BitArray best = new BitArray((int)data.RouterCount);
            for(int i = 0; i < iterations; i++)
            {
              //  Console.WriteLine("Run #" + i);
                routerswitches = new BitArray((int)data.RouterCount);
              //  Console.WriteLine("Router count: " + routerswitches.Count);
                int numbertoswitch = randomgenerator.Next((int)data.RouterCount);
              //  Console.WriteLine("Switching amount: " + numbertoswitch);
                for(int j = 0; j < numbertoswitch; j++)
                {
                    int switching;
                    while(routerswitches.Get(switching = randomgenerator.Next((int)data.RouterCount)) == true);
                //    Console.WriteLine("Switching: " + switching);
                    routerswitches.Set(switching, true);
                }

                double fitness = FitnessEvaluation(data.NetworkPaths, routerswitches, numbertoswitch);

               // Console.WriteLine("Fitness: " + fitness);
                if(fitness > highestfitness)
                {
                    ((RandomLogSpecification)log).AddEvaluation(i, fitness);
                    highestfitness = fitness;
                    best = (BitArray)routerswitches.Clone();
                }
            }

            solution.RoutersTurnedOff = ExtensionMethods.ConvertBitArrayToOffRouterNumbers(best, data.HostCount);
        }