|
@@ -1,4 +1,5 @@
|
1
|
1
|
using System;
|
|
2
|
+using uqac_ia_sudoku_csp.Interfaces;
|
2
|
3
|
using uqac_ia_sudoku_csp.Solver;
|
3
|
4
|
using uqac_ia_sudoku_csp.Solver.Generators;
|
4
|
5
|
using uqac_ia_sudoku_csp.Solver.NextValueChoosers;
|
|
@@ -9,20 +10,65 @@ namespace uqac_ia_sudoku_csp
|
9
|
10
|
{
|
10
|
11
|
public static void Main(string[] args)
|
11
|
12
|
{
|
|
13
|
+ var generatorType = "-";
|
|
14
|
+ if (args.Length > 0)
|
|
15
|
+ {
|
|
16
|
+ generatorType = args[0];
|
|
17
|
+ }
|
|
18
|
+ var valueChooser = "mrv";
|
|
19
|
+ if (args.Length > 1)
|
|
20
|
+ {
|
|
21
|
+ valueChooser = args[1];
|
|
22
|
+ }
|
|
23
|
+ var emptyCharacters = "0 .";
|
|
24
|
+ if (args.Length > 2)
|
|
25
|
+ {
|
|
26
|
+ emptyCharacters = args[2];
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ object data;
|
|
30
|
+ IGenerator generator;
|
12
|
31
|
var board = new Board("123456789");
|
13
|
32
|
|
14
|
|
- var generator = new FileGenerator();
|
15
|
|
- generator.Generate(board, new FileGeneratorDbo
|
|
33
|
+ if (generatorType == "-")
|
|
34
|
+ {
|
|
35
|
+ generator = new StdInGenerator();
|
|
36
|
+ data = emptyCharacters;
|
|
37
|
+ }
|
|
38
|
+ else if (generatorType == "0")
|
16
|
39
|
{
|
17
|
|
- EmptyCharacters = "0 .",
|
18
|
|
- FilePath = "../sample/04.txt"
|
19
|
|
- });
|
|
40
|
+ generator = new EmptyGenerator();
|
|
41
|
+ data = null;
|
|
42
|
+ }
|
|
43
|
+ else
|
|
44
|
+ {
|
|
45
|
+ generator = new FileGenerator();
|
|
46
|
+ data = new FileGeneratorDbo
|
|
47
|
+ {
|
|
48
|
+ EmptyCharacters = emptyCharacters,
|
|
49
|
+ FilePath = generatorType
|
|
50
|
+ };
|
|
51
|
+ }
|
|
52
|
+ generator.Generate(board, data);
|
20
|
53
|
board.Print(Console.Out);
|
21
|
54
|
|
22
|
|
- var solver = new BacktrackSearch(new MRVNextValueChooser());
|
23
|
|
- var start = DateTime.Now;
|
|
55
|
+ INextValueChooser nextValueChooser = null;
|
|
56
|
+ if (valueChooser == "mrv")
|
|
57
|
+ {
|
|
58
|
+ nextValueChooser = new MRVNextValueChooser();
|
|
59
|
+ }
|
|
60
|
+ else if (valueChooser == "basic")
|
|
61
|
+ {
|
|
62
|
+ nextValueChooser = new BasicNextValueChooser();
|
|
63
|
+ }
|
|
64
|
+ else
|
|
65
|
+ {
|
|
66
|
+ Console.Error.WriteLine("Invalid next value chooser");
|
|
67
|
+ Environment.Exit(64);
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ var solver = new BacktrackSearch(nextValueChooser);
|
24
|
71
|
var resolved = solver.Resolve(board);
|
25
|
|
- var end = DateTime.Now;
|
26
|
72
|
|
27
|
73
|
if (resolved.Success)
|
28
|
74
|
{
|
|
@@ -34,7 +80,8 @@ namespace uqac_ia_sudoku_csp
|
34
|
80
|
Console.WriteLine("Not resolved");
|
35
|
81
|
}
|
36
|
82
|
Console.WriteLine($"{resolved.TryCount} tries");
|
37
|
|
- Console.WriteLine($"{(end - start).TotalMilliseconds} ms");
|
|
83
|
+ Console.WriteLine($"{resolved.ConsistentTryCount} consistent tries");
|
|
84
|
+ Console.WriteLine($"{resolved.Elapsed.TotalMilliseconds} ms");
|
38
|
85
|
}
|
39
|
86
|
}
|
40
|
87
|
}
|