Пример #1
0
 public GaSerializer(PcbProblem problem)
 {
     _history  = new LinkedList <object>();
     _tasks    = new LinkedList <Task>();
     _problem  = problem;
     FilePaths = new List <string>();
 }
Пример #2
0
        internal static void Main()
        {
            CreateDirectories();

            Console.Write("Seed: ");
            var input  = Console.ReadLine();
            var seed   = string.IsNullOrEmpty(input) ? new Random().Next() : int.Parse(input);
            var random = new Random(seed);

            Console.Write("Enter path to problem file: ");
            var path    = Console.ReadLine();
            var problem = PcbProblem.LoadProblemFromFile(path);

            Console.Write("Enter population size (>1, default: 250): ");
            input = Console.ReadLine();
            var popSize = string.IsNullOrEmpty(input) ? 250 : int.Parse(input);

            Console.Write("Enter generation limit (default: 1000): ");
            input = Console.ReadLine();
            var genLimit = string.IsNullOrEmpty(input) ? 1000 : int.Parse(input);

            Console.Write("Enter mutation probability ([0.0-1.0], default: 0.1): ");
            input = Console.ReadLine();
            var mutProb = string.IsNullOrEmpty(input) ? 0.1 : double.Parse(input);

            Console.Write("Enter crossover probability ([0.0-1.0], default: 0.8): ");
            input = Console.ReadLine();
            var crossProb = string.IsNullOrEmpty(input) ? 0.8 : double.Parse(input);

            Console.Write("Enter number of passes (default: 1): ");
            input = Console.ReadLine();
            var passes  = string.IsNullOrEmpty(input) ? 1 : int.Parse(input);
            var results = new ((Solution bestSolution, double fitness, int gen)result, long time)[passes];
Пример #3
0
 public MutationTest()
 {
     _problem  = PcbProblem.LoadProblemFromFile("zad2.txt");
     _solution = new Solution(_problem, new RandomInitializer {
         RandomGenerator = new Random(1), InitialHeadToTargetProbability = 1, MaxLength = 20
     });
 }
Пример #4
0
        public static (int[] board, int[][] points) SerializeProblem(PcbProblem problem)
        {
            var board  = new[] { problem.BoardWidth, problem.BoardHeight };
            var points = problem.PointPairs
                         .SelectMany(pair => new[] { pair.startPoint, pair.endPoint })
                         .Select(p => new[] { p.X, p.Y }).ToArray();

            return(board, points);
        }
Пример #5
0
        public SolutionTest()
        {
            var points = new List <(Point startPoint, Point endPoint)>
            {
                (new Point(1, 3), new Point(5, 3)),
                (new Point(3, 1), new Point(3, 3))
            };

            _problem = new PcbProblem(6, 6, points);
        }