Example #1
0
        /// <summary>
        /// Split genotype into separate routes
        /// </summary>
        /// <param name="genotype"></param>
        /// <returns></returns>
        private List <Genotype>[] SplitGenotyp(Genotype genotype)
        {
            var ret = new List <Genotype> [input.Days.Length];

            {
                for (int i = 0; i < ret.Length; i++)
                {
                    ret[i] = new List <Genotype>();
                }

                var routesPerDay = genotype.CountRoutes() / input.Days.Length;
                int day          = 0;
                int santa        = 0;
                for (int i = 0; i <= genotype.Count; i++)
                {
                    // add Genotype in any case
                    ret[day].Add(new Genotype());
                    while (i < genotype.Count && !PopulationGenerator.IsSeparator(genotype[i]))
                    {
                        ret[day][santa].Add(genotype[i]);
                        i++;
                    }
                    if (i < genotype.Count)
                    {
                        // Add separator
                        ret[day][santa].Add(genotype[i]);
                    }

                    santa++;
                    if (santa >= routesPerDay)
                    {
                        santa = 0;
                        day++;
                    }
                }
            }
            return(ret);
        }
Example #2
0
        public Route[] Decode(Genotype genotype)
        {
            // preparation
            var routesPerDay = genotype.CountRoutes() / input.Days.Length;

            GenerateSantaIdList(routesPerDay);

            var routes        = new List <Route>();
            int currentGenPos = 0;

            foreach (var(from, _) in input.Days)
            {
                var routePerDayCounter = 0;
                while (routePerDayCounter < routesPerDay)
                {
                    var r = GetRoute(genotype, ref currentGenPos, from);
                    r.SantaId = santaIds[routePerDayCounter];
                    routes.Add(r);
                    routePerDayCounter++;
                }
            }
            return(routes.ToArray());
        }