コード例 #1
0
        public List <InputData> GetAllComptitiors(string path, string filename)
        {
            try
            {
                string pathToUse = path;
                if (string.IsNullOrEmpty(path))
                {
                    pathToUse = m_inputPath;
                }

                string filenameToUse = filename;
                if (string.IsNullOrEmpty(filenameToUse))
                {
                    filenameToUse = "INPUT.TXT";
                }


                var input = InputFileParser.ParseFile(pathToUse, filenameToUse);
                return(input);
            }
            catch (Exception e)
            {
                Log.Error(e, "GetAllComptitiors");
                throw;
            }
        }
コード例 #2
0
        public void BrokenFileFormatMissingQuantity()
        {
            string sample = @"
                    # Test comment
                    Test material 1;TST001;W01
                ";

            InputFileParser parser = new InputFileParser(GenerateStreamFromString(sample));

            parser.ParseFile();
            Assert.True(parser.HasErrors);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var parser = new InputFileParser();

            // get input network from user
            Console.WriteLine("Please specify network topology which you want to solve.");

            Console.Write("How many nodes are in the network? ");
            var nodesCountInput = Console.ReadLine();

            if (nodesCountInput is null)
            {
                Console.WriteLine("Invalid input.");
                return;
            }

            var nodesCount      = int.Parse(nodesCountInput);
            var nodeConnections = new List <string>(nodesCount);

            for (var i = 1; i <= nodesCount; i++)
            {
                Console.WriteLine($"Enter nodes reachable from node {i} separated by comma: ");
                var currentNodeConnectionsInput = Console.ReadLine();

                nodeConnections.Add($"{i}:{currentNodeConnectionsInput}");
            }

            var inputNetwork = parser.ReadNetworkFromInput(nodeConnections);

            // find all node pairs
            PathFinder pathFinder = new PathFinder();

            for (int i = 1; i < inputNetwork.Nodes.Count; i++)
            {
                for (int j = i + 1; j < inputNetwork.Nodes.Count + 1; j++)
                {
                    pathFinder.FindAllPaths(i, j, inputNetwork);
                }
            }

            // all paths generated. Finding perfect combination.
            GeneticAlgorithmParameters parameters = new GeneticAlgorithmParameters
            {
                InitialPopulationSize = 100,
                CrossoverProbability  = (float)0.2,
                MutationProbability   = (float)0.1,
                RandomSeed            = 4253,
                LimitValue            = 30,
                StoppingCriteria      = StoppingCriteria.NoImprovement
            };

            new GeneticService(parameters, inputNetwork, pathFinder).Solve();
        }
コード例 #4
0
        public void Load()
        {
            var parser  = new InputFileParser(logger);
            var results = parser.parse(fileName, MandatoryFields);

            //Add participants
            foreach (var line in results)
            {
                var name   = line.items.FirstOrDefault(i => i.Key == ColNames.Name).Value;
                var gender = GenderUtils.Parse(line.items.FirstOrDefault(i => i.Key == ColNames.Gender).Value);
                if (gender == null)
                {
                    throw new ParsingException($"No gender found for participant {name}");
                }

                this.addParticipantCB(new Participant(name, (Gender)gender));
                logger.Log($"Adding participant {name}");
            }

            //Add constraints
            foreach (var line in results)
            {
                var name = line.items.FirstOrDefault(i => i.Key == ColNames.Name).Value;

                //Add Gender constraints
                if (BlockPhrases.Contains(line.items.FirstOrDefault(i => i.Key == ColNames.DatingMales).Value))
                {
                    addConstraintToParticipantCB(name, new GenderBlockConstraint(Gender.Male));
                }
                if (BlockPhrases.Contains(line.items.FirstOrDefault(i => i.Key == ColNames.DatingFemales).Value))
                {
                    addConstraintToParticipantCB(name, new GenderBlockConstraint(Gender.Female));
                }

                //Add participant constraints
                foreach (var i in line.items.Where(i2 => !MandatoryFields.Contains(i2.Key)))
                {
                    if (BlockPhrases.Contains(i.Value))
                    {
                        //this means we have a column with participant name and its value is some block phrase (eg - block)
                        //so we take the column name (key) and add it as a constraint
                        addConstraintToParticipantCB(name, new ParticipantBlockConstraint(i.Key));
                    }
                }
            }
            logger.Log("Loading complete");
            LoadCompleteCB();
        }
コード例 #5
0
        public void SimpleScenario()
        {
            string sample = @"
                    # Test comment
                    Test material 1;TST001;W01,10|W02,25|W03,99
                ";

            InputFileParser parser = new InputFileParser(GenerateStreamFromString(sample));

            parser.ParseFile();
            Assert.False(parser.HasErrors);

            Assert.Collection <Warehouse>(parser.Inventory, item => Assert.Equal(10, item.Total),
                                          item => Assert.Equal(25, item.Total),
                                          item => Assert.Equal(99, item.Total));
        }
コード例 #6
0
        public void DifferentLengths()
        {
            string sample = @"
                    # Test comment
                    Test material 1;TST001;W01,10
                    Test material 2;TST001;W02,50|W03,198
                ";

            InputFileParser parser = new InputFileParser(GenerateStreamFromString(sample));

            parser.ParseFile();
            Assert.False(parser.HasErrors);

            Assert.Collection <Warehouse>(parser.Inventory, item => Assert.Equal(10, item.Total),
                                          item => Assert.Equal(50, item.Total),
                                          item => Assert.Equal(198, item.Total));
        }
コード例 #7
0
        public void ManyLines()
        {
            string sample = @"
                    # Test comment
                    Test material 1;TST001;W01,10|W02,25|W03,99
                    Test material 2;TST001;W01,20|W02,50|W03,198
                ";

            InputFileParser parser = new InputFileParser(GenerateStreamFromString(sample));

            parser.ParseFile();
            Assert.False(parser.HasErrors);

            Assert.Collection <Warehouse>(parser.Inventory, item => Assert.Equal(30, item.Total),
                                          item => Assert.Equal(75, item.Total),
                                          item => Assert.Equal(297, item.Total));
        }
コード例 #8
0
        static void Main(string[] args)
        {
            InputFileParser parser = new InputFileParser();

            Console.WriteLine("Choose network to optimize:");
            Console.WriteLine("1: Network_1.txt");
            Console.WriteLine("2: Network_2.txt");
            string  choice       = Console.ReadLine();
            Network inputNetwork = new Network();

            if (choice.Equals("1") || choice.Equals("2"))
            {
                inputNetwork = parser.ReadNetwork("Network_" + choice + ".txt");
            }
            else
            {
                return;
            }

            //Find all node pairs
            AllPathFinder pathFinder = new AllPathFinder();

            for (int i = 1; i < inputNetwork.Nodes.Count; i++)
            {
                for (int j = i + 1; j < inputNetwork.Nodes.Count + 1; j++)
                {
                    pathFinder.FindAllPaths(i, j, inputNetwork);
                }
            }

            // all paths generated. Finding perfect combination.
            GeneticAlgorithmParameters parameters = new GeneticAlgorithmParameters();

            parameters.InitialPopulationSize = 100;
            parameters.CrossoverProbability  = (float)0.2;
            parameters.MutationProbability   = (float)0.1;
            parameters.RandomSeed            = 4253;
            parameters.LimitValue            = 30;
            parameters.StoppingCriteria      = StoppingCriteria.NoImprovement;

            string         fileName       = "Network_" + choice;
            GeneticService geneticService = new GeneticService(parameters, inputNetwork, pathFinder, fileName);

            geneticService.Solve();
        }
コード例 #9
0
        private static int ParseFile()
        {
            var output = Console.OpenStandardOutput();
            var input  = Console.OpenStandardInput();

            InputFileParser parser = new InputFileParser(input);

            parser.ParseFile();
            if (parser.HasErrors)
            {
                using (StreamWriter sw = new StreamWriter(output))
                {
                    parser.ParseErrors.ForEach((err) => sw.WriteLine(err));
                }
                return(1);
            }

            ReportGenerator reporter = new ReportGenerator(parser);

            reporter.SampleReport(output);
            return(0);
        }
コード例 #10
0
 public ReportGenerator(InputFileParser parser)
 {
     _parser = parser;
 }