-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunnableSolvers.cs
96 lines (83 loc) · 4.35 KB
/
RunnableSolvers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using lib.Models;
using lib.Solvers.Postprocess;
using lib.Solvers.RandomWalk;
namespace lib.Solvers
{
public static class RunnableSolvers
{
public static List<Func<ISolver>> PuzzleSolvers()
{
var result = new List<Func<ISolver>>
{
() => new StupidSolver(false),
() => new StupidSolver(true),
() => new ParallelDeepWalkSolver(2, new Estimator(false, false, false), usePalka: false, useWheels: false, useDrill: false, new BoosterType[0]),
() => new ParallelDeepWalkSolver(2, new Estimator(false, false, false), usePalka: false, useWheels: false, useDrill: false, new BoosterType[0]),
//() => new ParallelDeepWalkSolver(2, new Estimator(false, true), usePalka: false, useWheels: false, new BoosterType[0]),
//() => new PalkaSolver()
//() => new RandomWalkSolver(depth: 2, new Estimator(), new Random(Guid.NewGuid().GetHashCode()), 100, usePalka: true),
//() => new DeepWalkSolver(depth: 2, new Estimator()),
};
//result.Add(() => new MiningSolver(false, -1));
//result.Add(() => new MiningSolver(true, -1));
foreach (var limit in new[] { 5, 10, 15, 20, 25, 30 })
{
foreach (var use in new [] {true, false})
{
result.Add(() => new MiningSolver(use, limit));
}
}
return result;
}
// This and only this solvers would be periodically re-run
public static List<Func<ISolver>> Enumerate()
{
return new List<Func<ISolver>>
{
//() => new RandomWalkSolver(depth: 2, new Estimator(true), new Random(Guid.NewGuid().GetHashCode()), 100, usePalka: true, true),
() => new DeepWalkSolver(2, new Estimator(collectFastWheels: true, zakoulochki: true, collectDrill: true), usePalka: true, useWheels: true, useDrill: true),
//() => new StupidSolver(),
//() => new RandomWalkSolver(depth: 2, new Estimator(), new Random(Guid.NewGuid().GetHashCode()), 100, usePalka: true),
//() => new DeepWalkSolver(depth: 2, new Estimator()),
//() => new ParallelDeepWalkSolver(2, new Estimator(collectFastWheels: false), usePalka: false, useWheels: false, new[]{BoosterType.Cloning, }),
//() => new ParallelDeepWalkSolver(2, new Estimator(true, zakoulochki: true, false), usePalka: false, useWheels: true, useDrill: false, new BoosterType[0]),
() => new ParallelDeepWalkSolver(2, new Estimator(collectFastWheels: true, zakoulochki: true, false), usePalka: false, useWheels: true, useDrill: false, new BoosterType[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 fucker!");
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
);
}
}
}