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); }
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(); }