예제 #1
0
        public void SnapshotRestoredSolutionIdenticalToOriginal()
        {
            var file         = Properties.Resources.week_DS_D_DH_inst;
            var deserializer = new InstanceJsonSerializer
            {
                Reader = new StreamReader(new MemoryStream(file), Encoding.UTF8)
            };
            Instance instance = deserializer.DeserializeInstance();

            deserializer.Reader = new StreamReader(new MemoryStream(Properties.Resources.week_DS_D_DH_sol), Encoding.UTF8);
            Solution solution = deserializer.DeserializeSolution(instance);

            solution.GradingFunction = new Scorer();
            solution.GradingFunction.AssesSolution(solution);
            string path1 = @"results\hourSolScored.json";
            string path2 = @"results\hourSolScored2.json";
            InstanceJsonSerializer serializer = new InstanceJsonSerializer()
            {
                Path = path1,
            };

            serializer.SerializeSolution(solution, SolutionSerializationMode.DebugFull);
            Solution solution2 = solution.TakeSnapshot();

            solution2.RestoreStructures();
            solution2.GradingFunction.AssesSolution(solution2);
            serializer.Path = path2;
            serializer.SerializeSolution(solution2, SolutionSerializationMode.DebugFull);
            Assert.AreEqual(GetFileHash(path1), GetFileHash(path2));
        }
예제 #2
0
        private List <Solution> LoadStartingSolutions(string solutionsDirectory, string currentInstance, Instance instance, int amount, ISolver solver)
        {
            string instancePath         = currentInstance.Replace(InstanceDirectory + Path.DirectorySeparatorChar, "");
            string nameToSearch         = Path.GetFileNameWithoutExtension(instancePath);
            string relativePathToSearch = instancePath.Replace(Path.GetFileName(instancePath), "");
            string dirToSearch          = Path.Combine(StartingSolutionsDirectory, relativePathToSearch);

            string[] filePaths = FindFilesUsingWildcardPath(Path.Combine(dirToSearch, $"*{nameToSearch}*.json"));

            var solutionList = new List <Solution>();

            int amountToRead;

            if (PickOnlyBestStartingSolutions)
            {
                amountToRead = filePaths.Count();
            }
            else
            {
                solutionList.Shuffle(Random);
                amountToRead = Math.Min(amount, filePaths.Count());
            }

            for (int i = 0; i < amountToRead; ++i)
            {
                var deserializer = new InstanceJsonSerializer
                {
                    Reader = new StreamReader(filePaths[i]),
                };
                Solution solution = deserializer.DeserializeSolution(instance);
                solution.Description     = Path.GetFileNameWithoutExtension(filePaths[i]);
                solution.GradingFunction = solver.ScoringFunction.GetAnotherOne();
                solution.GradingFunction.AssesSolution(solution);
                solution.WeightedLossBefore       = solution.WeightedLoss;
                solution.IntegrityLossScoreBefore = solution.IntegrityLossScore;
                solutionList.Add(solution);
            }
            if (PickOnlyBestStartingSolutions)
            {
                solutionList = solutionList.OrderBy(s => s.WeightedLoss).OrderBy(s => s.IntegrityLossScore).Take(amount).ToList();
            }
            return(solutionList);
        }
        private void GradeSolution(string instancePath, string solutionPath, string pathOut)
        {
            var deserializer = new InstanceJsonSerializer
            {
                Path = instancePath,
            };
            Instance instance = deserializer.DeserializeInstance();

            deserializer.Path   = solutionPath;
            deserializer.Reader = null;
            Solution solution = deserializer.DeserializeSolution(instance);

            solution.GradingFunction = new Scorer();
            solution.GradingFunction.AssesSolution(solution);
            InstanceJsonSerializer serializer = new InstanceJsonSerializer()
            {
                Path = pathOut,
            };

            serializer.SerializeSolution(solution, SolutionSerializationMode.DebugTaskData);
        }
예제 #4
0
        public void GradeWeek3ChannelSolutionFromSavedFiles()
        {
            var file         = Properties.Resources.week_DS_D_DH_inst;
            var deserializer = new InstanceJsonSerializer
            {
                Reader = new StreamReader(new MemoryStream(file), Encoding.UTF8)
            };
            Instance instance = deserializer.DeserializeInstance();

            deserializer.Reader = new StreamReader(new MemoryStream(Properties.Resources.week_DS_D_DH_sol), Encoding.UTF8);
            Solution solution = deserializer.DeserializeSolution(instance);

            solution.GradingFunction = new Scorer();
            solution.GradingFunction.AssesSolution(solution);
            InstanceJsonSerializer serializer = new InstanceJsonSerializer()
            {
                Path = @"results\week_DS_D_DH_sol_scored.json"
            };

            serializer.SerializeSolution(solution, SolutionSerializationMode.DebugTaskData);

            Assert.IsNotNull(instance);
            Assert.IsNotNull(solution);
        }