Ejemplo n.º 1
0
        public double FitnessValue(Individual secondInd, KnapsackList knapsackList)
        {
            bool strategy1 = this.strategy;
            bool strategy2 = secondInd.strategy;

            if (strategy1)
            {
                if (strategy2)
                {
                    return(fitnessCooperativeCooperative(knapsackList));
                }
                else
                {
                    return(fitnessCooperativeDefector(knapsackList));
                }
            }
            else
            {
                if (strategy2)
                {
                    return(fitnessDefectorCooperative(knapsackList));
                }
                else
                {
                    return(fitnessDefectorDefector(knapsackList));
                }
            }
        }
Ejemplo n.º 2
0
        public double FitnessValue(KnapsackList knapsackList)
        {
            double sum = 0.0;

            if (this.isFeasible)
            {
                for (int i = 0; i < this.chromosome.Count; i++)
                {
                    sum += this.chromosome[i] ? knapsackList[0].GetValue(i) : 0.0;
                }

                return(sum / GA_GT.maxFitness);
            }

            else
            {
                double deltaV = GA_GT.cheatingDegree / 100.0;
                for (int i = 0; i < this.chromosome.Count; i++)
                {
                    sum += this.chromosome[i] ? knapsackList[0].GetValue(i) + deltaV : 0.0;
                }

                return((sum - NonFeasibleKnapsacks(knapsackList) * knapsackList[0].maxValue) / GA_GT.maxFitness);
            }
        }
Ejemplo n.º 3
0
        public int NonFeasibleKnapsacks(KnapsackList knapsackList)
        {
            int counter = 0;

            foreach (Knapsack k in knapsackList.knapsackList)
            {
                if (!this.chromosome.IsFeasible(k))
                {
                    counter++;
                }
            }

            return(counter);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string path = @"..\..\samples\MK250.txt";

            KnapsackList knapsackList = InputOutput.ReadInput(path);

            knapsackList.Show();
            init_static_GA_GT(knapsackList);

            TestPopulation t = new TestPopulation();

            GA_GT ga_gt = new GA_GT();

            ga_gt.RunGA_GT().Show();
            Console.WriteLine("End");
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void init_static_GA_GT(KnapsackList knapsackList)
        {
            GA_GT.gameModel = new PrisonersDilemma();
            GA_GT.knapsackList = knapsackList;
            GA_GT.weightGA = 0.8;
            GA_GT.weightGT = 1.0 - GA_GT.weightGA;
            GA_GT.cheatingDegree = 50;
            GA_GT.cheaterRate = 0.1;
            GA_GT.crossoverRate = 0.75;

            GA_GT.numberOfEpochs = 1000;

            GA_GT.chromosomeLength = InputOutput.objectsNumber;
            GA_GT.populationSize = 40;           // must be even number!!

            GA_GT.mutationRate = 1.0 / GA_GT.chromosomeLength;

            GA_GT.feasibleRate = 0.2;
        }
Ejemplo n.º 6
0
        static void init_static_GA_GT(KnapsackList knapsackList)
        {
            GA_GT.gameModel      = new PrisonersDilemma();
            GA_GT.knapsackList   = knapsackList;
            GA_GT.weightGA       = 0.8;
            GA_GT.weightGT       = 1.0 - GA_GT.weightGA;
            GA_GT.cheatingDegree = 50;
            GA_GT.cheaterRate    = 0.1;
            GA_GT.crossoverRate  = 0.75;

            GA_GT.numberOfEpochs = 1000;

            GA_GT.chromosomeLength = InputOutput.objectsNumber;
            GA_GT.populationSize   = 40;         // must be even number!!

            GA_GT.mutationRate = 1.0 / GA_GT.chromosomeLength;

            GA_GT.feasibleRate = 0.2;
        }
Ejemplo n.º 7
0
        private double fitnessCooperativeDefector(KnapsackList knapsackList)
        {
            Knapsack knapsack = knapsackList[0];
            double   sum      = 0.0;

            for (int i = 0; i < this.chromosome.Count; i++)
            {
                sum += this.chromosome[i] ? knapsack.GetValue(i) : 0.0;
            }

            if (this.isFeasible)
            {
                return(GA_GT.weightGA * sum / GA_GT.maxFitness
                       + GA_GT.weightGT * GA_GT.gameModel.cooperatorDefectorPayoff / GA_GT.maxPayoff);
            }

            else
            {
                return(GA_GT.weightGA * (sum - NonFeasibleKnapsacks(knapsackList) * knapsack.maxValue) / GA_GT.maxFitness
                       + GA_GT.weightGT * GA_GT.gameModel.cooperatorDefectorPayoff / GA_GT.maxPayoff);
            }
        }
Ejemplo n.º 8
0
        private double fitnessDefectorDefector(KnapsackList knapsackList)
        {
            Knapsack knapsack = knapsackList[0];
            double   deltaV   = GA_GT.cheatingDegree / 100.0;
            //double deltaW = GA_GT.cheatingDegree / 100.0;
            double sum = 0.0;

            for (int i = 0; i < this.chromosome.Count; i++)
            {
                sum += this.chromosome[i] ? knapsack.GetValue(i) + deltaV : 0.0;
            }

            if (this.isFeasible)
            {
                return(GA_GT.weightGA * sum / GA_GT.maxFitness
                       + GA_GT.weightGT * GA_GT.gameModel.defectorDefectorPayoff / GA_GT.maxPayoff);
            }

            else
            {
                return(GA_GT.weightGA * (sum - NonFeasibleKnapsacks(knapsackList) * knapsack.maxValue) / GA_GT.maxFitness
                       + GA_GT.weightGT * GA_GT.gameModel.defectorDefectorPayoff / GA_GT.maxPayoff);
            }
        }
Ejemplo n.º 9
0
 public void Update(KnapsackList knapsackList)
 {
     isFeasible = chromosome.IsFeasible();
     fitness    = FitnessValue(knapsackList);
 }
Ejemplo n.º 10
0
        public double FitnessValue(Individual secondInd, KnapsackList knapsackList)
        {
            bool strategy1 = this.strategy;
            bool strategy2 = secondInd.strategy;

            if (strategy1)
            {
                if (strategy2)
                {
                    return fitnessCooperativeCooperative(knapsackList);
                }
                else
                {
                    return fitnessCooperativeDefector(knapsackList);
                }
            }
            else
            {
                if (strategy2)
                {
                    return fitnessDefectorCooperative(knapsackList);
                }
                else
                {
                    return fitnessDefectorDefector(knapsackList);
                }
            }
        }
Ejemplo n.º 11
0
        private double fitnessDefectorDefector(KnapsackList knapsackList)
        {
            Knapsack knapsack = knapsackList[0];
            double deltaV = GA_GT.cheatingDegree / 100.0;
            //double deltaW = GA_GT.cheatingDegree / 100.0;
            double sum = 0.0;

            for (int i = 0; i < this.chromosome.Count; i++)
            {
                sum += this.chromosome[i] ? knapsack.GetValue(i) + deltaV : 0.0;
            }

            if (this.isFeasible)
            {
                return GA_GT.weightGA * sum / GA_GT.maxFitness
                     + GA_GT.weightGT * GA_GT.gameModel.defectorDefectorPayoff / GA_GT.maxPayoff;
            }

            else
            {
                return GA_GT.weightGA * (sum - NonFeasibleKnapsacks(knapsackList) * knapsack.maxValue) / GA_GT.maxFitness
                     + GA_GT.weightGT * GA_GT.gameModel.defectorDefectorPayoff / GA_GT.maxPayoff;
            }
        }
Ejemplo n.º 12
0
        private double fitnessCooperativeDefector(KnapsackList knapsackList)
        {
            Knapsack knapsack = knapsackList[0];
            double sum = 0.0;

            for (int i = 0; i < this.chromosome.Count; i++)
            {
                sum += this.chromosome[i] ? knapsack.GetValue(i) : 0.0;
            }

            if (this.isFeasible)
            {
                return GA_GT.weightGA * sum / GA_GT.maxFitness
                     + GA_GT.weightGT * GA_GT.gameModel.cooperatorDefectorPayoff / GA_GT.maxPayoff;
            }

            else
            {
                return GA_GT.weightGA * (sum - NonFeasibleKnapsacks(knapsackList) * knapsack.maxValue) / GA_GT.maxFitness
                     + GA_GT.weightGT * GA_GT.gameModel.cooperatorDefectorPayoff / GA_GT.maxPayoff;
            }
        }
Ejemplo n.º 13
0
 public void Update(KnapsackList knapsackList)
 {
     isFeasible = chromosome.IsFeasible();
     fitness = FitnessValue(knapsackList);
 }
Ejemplo n.º 14
0
        public int NonFeasibleKnapsacks(KnapsackList knapsackList)
        {
            int counter = 0;

            foreach (Knapsack k in knapsackList.knapsackList)
            {
                if (!this.chromosome.IsFeasible(k))
                    counter++;
            }

            return counter;
        }
Ejemplo n.º 15
0
        public double FitnessValue(KnapsackList knapsackList)
        {
            double sum = 0.0;

            if (this.isFeasible)
            {
                for (int i = 0; i < this.chromosome.Count; i++)
                {
                    sum += this.chromosome[i] ? knapsackList[0].GetValue(i) : 0.0;
                }

                return sum / GA_GT.maxFitness;
            }

            else
            {
                double deltaV = GA_GT.cheatingDegree / 100.0;
                for (int i = 0; i < this.chromosome.Count; i++)
                {
                    sum += this.chromosome[i] ? knapsackList[0].GetValue(i) + deltaV : 0.0;
                }

                return (sum - NonFeasibleKnapsacks(knapsackList) * knapsackList[0].maxValue) / GA_GT.maxFitness;
            }
        }