コード例 #1
0
        static void Main(string[] args)
        {
            Instance  Instance = new Instance(Path);
            Weighting weighter = new Weighting(Instance);

            // empty population --- Population size = boxes*containers --- Chromosome size = boxes
            int PopulationSize = Instance.NumBoxes * Instance.NumContainers;
            int ChromosomeSize = Instance.NumBoxes;
            var Population     = new Population();

            for (var p = 0; p < PopulationSize; p++)
            {
                var Chromosome = new Chromosome();

                WeightedBox[] WeightingArray = new WeightedBox[ChromosomeSize];
                WeightingArray = weighter.InitilizeWeightingArray();

                foreach (var box in WeightingArray)
                {
                    Chromosome.Genes.Add(new Gene(box));
                }
                Chromosome.Genes.ShuffleFast();

                double test = EvaluateFitness(Chromosome);

                Population.Solutions.Add(Chromosome);
            }


            Console.ReadKey();
        }
コード例 #2
0
        public static double EvaluateFitness(Chromosome chromosome)
        {
            Instance  instance = new Instance(Path);
            Weighting weighter = new Weighting(instance);

            Dictionary <int, WeightedBox> InputToPack = new Dictionary <int, WeightedBox>();


            int i = 0;

            foreach (Gene Gene in chromosome.Genes)
            {
                //save Gene in WeightedBox instance
                var box = new WeightedBox();
                box = (WeightedBox)Gene.ObjectValue;

                //update Weight and orientaton with absolute Ratio and dimension
                box.Weight += weighter.Ratio[i];

                int[] Dimension = new int[3];
                for (int j = 0; j < 3; j++)
                {
                    Dimension[j] = instance.Boxes[i, j + 1];
                }
                box.Orientation = ConvertDimension(box.Orientation, Dimension);

                //Add to dictionary
                InputToPack.Add(i, box);
                i++;
            }

            InputToPack = InputToPack.OrderByDescending(x => x.Value.Weight).ToDictionary(x => x.Key, x => x.Value);

            return(0);
        }
コード例 #3
0
        public WeightedBox[] InitilizeWeightingArray()
        {
            WeightedBox[] WeightingArray = new WeightedBox[Instance.NumBoxes];
            Random        R     = new Random();
            double        Range = BiasingStrength * MeanOfRatio;

            for (int i = 0; i < Instance.NumBoxes; i++)
            {
                WeightingArray[i]        = new WeightedBox();
                WeightingArray[i].Weight = (R.NextDouble() * 2 * Range) - Range;
                int[] s = new int[3] {
                    1, 2, 3
                };
                WeightingArray[i].Orientation = s.OrderBy(x => R.Next()).ToArray();
            }
            return(WeightingArray);
        }