public void METHOD()
        {
            var state = ProblemReader.Read(2).ToState();
            var clusterSourceLines = ClustersStateReader.Read(2);
            var clustersState      = new ClustersState(clusterSourceLines, state);

            clustersState.RootLevel.Should().Be(3);
            clustersState.RootIds.Should().Equal(0, 1);
        }
示例#2
0
        public int SolveOneProblemWithCluster(ISolver solver, int id)
        {
            var state = ReadFromFile(id);

            state.ClustersState = new ClustersState(ClustersStateReader.Read(id), state);

            var pathFileName = Path.Combine(FileHelper.PatchDirectoryName("clusters.v2"), $"prob-{id:000}.path");

            if (File.Exists(pathFileName))
            {
                state.ClustersState.Path = File.ReadAllLines(pathFileName).Select(int.Parse).ToList();
            }

            var result = solver.Solve(state);

            Save(result, id);
            Console.WriteLine($"Solved {id} problem in {result.CalculateTime()} steps.");
            return(result.CalculateTime());
        }
示例#3
0
        public static SolutionMeta Solve(ISolver solver, ProblemMeta problemMeta)
        {
            var stopwatch = Stopwatch.StartNew();

            var problem = problemMeta.Problem;

            problem.ProblemId = problemMeta.ProblemId;
            var state = problem.ToState();

            state.ClustersState = new ClustersState(ClustersStateReader.Read(problemMeta.ProblemId), state);

            var pathFileName = Path.Combine(FileHelper.PatchDirectoryName("clusters.v2"), $"prob-{problemMeta.ProblemId:000}.path");

            state.ClustersState.Path = File.ReadAllLines(pathFileName).Select(int.Parse).ToList();

            var solved = solver.Solve(state);

            state = problem.ToState();
            Emulator.Emulate(state, solved);
            if (state.UnwrappedLeft > 0)
            {
                throw new InvalidOperationException("Bad mother f****r!");
            }

            var solutionBlob = solved.FormatSolution();
            var buyBlob      = solved.FormatBuy();
            var moneyCost    = solved.BuyCost();

            stopwatch.Stop();
            var calculationTime = stopwatch.ElapsedMilliseconds;

            return(new SolutionMeta(
                       problemMeta.ProblemId,
                       solutionBlob,
                       solved.CalculateTime(),
                       solver.GetName(),
                       solver.GetVersion(),
                       calculationTime,
                       buyBlob,
                       moneyCost
                       ));
        }
 public void ReadFromFile([Range(1, 300)] int problem)
 {
     var state = ProblemReader.Read(problem).ToState();
     var clusterSourceLines = ClustersStateReader.Read(problem);
     var clustersState      = new ClustersState(clusterSourceLines, state);
 }