-
Notifications
You must be signed in to change notification settings - Fork 3
/
UltraSolver.cs
57 lines (50 loc) · 2.06 KB
/
UltraSolver.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
using System;
using lib.Api;
using lib.ProjectionSolver;
namespace lib
{
public class UltraSolver
{
public static SolutionSpec AutoSolve(ProblemSpec problemSpec)
{
return Solve(problemSpec, 0.3);
}
public static void SolveAndShow(int taskNumber)
{
var problemSpec = new ProblemsRepo().Get(taskNumber);
var solver = Solve2(problemSpec, 0);
if (solver != null)
SolverMaker.Visualize(solver);
}
public static void SolveAndSend(int taskNumber, bool wait = true, double originality = 0.3)
{
var solveAndSendResult = SolveAndSendInternal(taskNumber, originality);
Console.WriteLine(taskNumber + ":" + " " + solveAndSendResult);
if (wait)
Console.ReadKey();
}
private static double SolveAndSendInternal(int taskNumber, double originality)
{
var problemSpec = new ProblemsRepo().Get(taskNumber);
var solutionSpec = Solve(problemSpec, originality);
if (solutionSpec == null)
return 0;
return ProblemsSender.Post(solutionSpec, taskNumber);
}
private static SolutionSpec Solve(ProblemSpec problemSpec, double originality)
{
var solver = SolverMaker.CreateSolver(problemSpec);
var ribbonWidth = RibbonIndicator.GetRibbonWidth(problemSpec);
var simpleSolver = SolverMaker.Solve(solver, ribbonWidth.HasValue ? ribbonWidth.Value : 1, originality);
if (simpleSolver != null)
return SolutionSpecBuilder.BuildSolutionByRibbonGraph(simpleSolver.Projection);
return null;
}
private static PointProjectionSolver Solve2(ProblemSpec problemSpec, double originality)
{
var solver = SolverMaker.CreateSolver(problemSpec);
var ribbonWidth = RibbonIndicator.GetRibbonWidth(problemSpec);
return SolverMaker.Solve(solver, ribbonWidth.HasValue ? ribbonWidth.Value : 1, originality);
}
}
}