Ejemplo n.º 1
0
        public void LoadConfiguration(string path)
        {
            FileInfo newConfigurationFile = new FileInfo(path);
            StreamReader sr = newConfigurationFile.OpenText();
            _newConfig.ConfigName = sr.ReadLine();
            _newConfig.CountOfReplays = Convert.ToInt16(sr.ReadLine());
            _newConfig.AlgMode = (Configuration.AlgorithmMode)Convert.ToInt16(sr.ReadLine());
            sr.ReadLine();
            int countOfRibs = Convert.ToInt16(sr.ReadLine());
            int countOfNode = Convert.ToInt16(sr.ReadLine());

            double[] weight = new double[countOfRibs];
            for (int i = 0; i < countOfRibs; i++)
            {
                weight[i] = Convert.ToDouble(sr.ReadLine());
            }
            int k = 0;
            List<Rib> ribs = new List<Rib>();
            for (int i = 0; i < countOfNode; i++)
            {
                for (int j = i + 1; j < countOfNode; j++)
                {
                    ribs.Add(new Rib(i, j, weight[k]));
                    k++;
                }
            }
            _newConfig.Graph = new UndirectedConnectedGraph(ribs.ToArray());
            sr.ReadLine();
            int countOfTracks = Convert.ToInt16(sr.ReadLine());
            List<int[]> tracks = new List<int[]>();
            char[] separator = { ' ' };
            for (int i = 0; i < countOfTracks; i++)
            {
                string[] person = sr.ReadLine().ToString().Trim().Split(separator);
                int[] track = new int[person.Length];
                for (int j = 0; j < person.Length; j++)
                {
                    track[j] = Convert.ToInt16(person[j]);
                }
                tracks.Add(track);
            }
            _newConfig.Tracks = new AbstractTrack[tracks.Count];
            for (int i = 0; i < _newConfig.Tracks.Length; i++)
            {
                _newConfig.Tracks[i] = new ClosedTrack(tracks[i], _newConfig.Graph);
            }
            sr.ReadLine();
            string nameOfFitnessFunction = sr.ReadLine();
            double paramOfFitness = Convert.ToDouble(sr.ReadLine());
            _newConfig.FitnessParam = paramOfFitness;
            FitnessFunctionFactory fitnessFunctionFactory = new FitnessFunctionFactory();
            _newConfig.FitnessFunction = fitnessFunctionFactory.CreateFitnessFunction(nameOfFitnessFunction, paramOfFitness);
            sr.ReadLine();
            if (_newConfig.AlgMode == Configuration.AlgorithmMode.Singl)
            {
                _newConfig.Mutation = _mutationFactory.CreateMutation(sr.ReadLine());
                _newConfig.Selection = _selectionFactory.CreateSelection(sr.ReadLine());
                _newConfig.Crossingover = _crossingoverFactory.CreateCrossingover(sr.ReadLine());
            }
            else
            {
                List<string> aliasMutations = GetAliasForAlgorithms(sr);
                CreateMutation(_newConfig.AlgMode, aliasMutations);
                List<string> aliasSelection = GetAliasForAlgorithms(sr);
                CreateSelection(_newConfig.AlgMode, aliasSelection);
                List<string> aliasCrossingover = GetAliasForAlgorithms(sr);
                CreateCrossingover(_newConfig.AlgMode, aliasCrossingover);
            }
            sr.ReadLine();
            _newConfig.ProbOfMutation = Convert.ToInt16(sr.ReadLine());
            _newConfig.ProbOfCrossingover = Convert.ToInt16(sr.ReadLine());
            sr.Close();
        }
Ejemplo n.º 2
0
 public void CreateFitnessFunction(string fitnessName, double param)
 {
     _newConfig.FitnessParam = param;
     FitnessFunctionFactory fitnessFunctionFactory = new FitnessFunctionFactory();
     _newConfig.FitnessFunction = fitnessFunctionFactory.CreateFitnessFunction(fitnessName, param);
 }