Mercurial > defical
comparison defical-sharp/defical-cli/main.cs @ 0:ebed2bd0d300
Initial import from svn. History be damned.
author | Edho P. Arief <me@myconan.net> |
---|---|
date | Fri, 02 Apr 2010 23:11:57 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ebed2bd0d300 |
---|---|
1 using System; | |
2 using System.Threading; | |
3 using libbacktrack; | |
4 using System.IO; | |
5 | |
6 namespace defical_cli | |
7 { | |
8 partial class Program | |
9 { | |
10 private partial class main | |
11 { | |
12 public main() { throw new NotImplementedException(); } | |
13 public main(params string[] args) | |
14 { | |
15 this.numThreads = Environment.ProcessorCount + 1; | |
16 { | |
17 if (args.Length != 0 && !getArguments(args)) | |
18 { | |
19 Console.WriteLine("Failed"); | |
20 return; | |
21 } | |
22 printWelcome(); | |
23 getInput(); | |
24 printPreSummary(); | |
25 Console.WriteLine("Started: {0}", DateTime.Now.ToString()); | |
26 Console.WriteLine(separator); | |
27 go(); | |
28 Console.WriteLine(separator); | |
29 Console.WriteLine("Finished: {0}", DateTime.Now.ToString()); | |
30 //Console.ReadLine(); | |
31 } | |
32 } | |
33 private void printPreSummary() | |
34 { | |
35 Console.WriteLine(separator); | |
36 Console.WriteLine("Graph type: {0}", this.graphType); | |
37 Console.WriteLine("Number of vertices: {0}", this.numVer); | |
38 Console.WriteLine("Number of deficiencies: {0}", this.numDef); | |
39 Console.WriteLine("Algorithm: {0}", this.algorithm); | |
40 if (this.algorithm == "backtrack") | |
41 { | |
42 Console.WriteLine("Number of threads: {0}", this.numThreads); | |
43 } | |
44 Console.WriteLine(separator); | |
45 } | |
46 private void printWelcome() | |
47 { | |
48 Console.WriteLine("Defical_CLI v{0}", this.version); | |
49 Console.WriteLine("Super magic deficiency calculator"); | |
50 Console.WriteLine("By Edho <me@myconan.net>"); | |
51 Console.WriteLine(separator); | |
52 } | |
53 private bool parseNum(string input, int min, int def, out int ret) | |
54 { | |
55 if (input == "") | |
56 { | |
57 ret = def; | |
58 return true; | |
59 } | |
60 try { Convert.ToInt32(input); } | |
61 catch | |
62 { | |
63 ret = -1; | |
64 return false; | |
65 } | |
66 if (Convert.ToInt32(input) < min) | |
67 { | |
68 ret = -1; | |
69 return false; | |
70 } | |
71 else | |
72 { | |
73 ret = Convert.ToInt32(input); | |
74 return true; | |
75 } | |
76 } | |
77 private bool parseGraphType(char i) | |
78 { | |
79 switch (i) | |
80 { | |
81 case '1': | |
82 case '\r': | |
83 { | |
84 this.graphType = "wheel"; | |
85 return true; | |
86 } | |
87 case '2': | |
88 { | |
89 this.graphType = "fan"; | |
90 return true; | |
91 } | |
92 case '3': | |
93 { | |
94 this.graphType = "doublefan"; | |
95 return true; | |
96 } | |
97 default: | |
98 { return false; } | |
99 | |
100 } | |
101 } | |
102 private bool parseAlgo(char i) | |
103 { | |
104 switch (i) | |
105 { | |
106 case '1': | |
107 case '\r': | |
108 { | |
109 this.algorithm = "backtrack"; | |
110 return true; | |
111 } | |
112 default: | |
113 { return false; } | |
114 } | |
115 } | |
116 private void WriteToFile(string filePath, string line) | |
117 { | |
118 if (filePath == null || filePath.Length == 0) | |
119 return; | |
120 if (line == null || line.Length == 0) | |
121 return; | |
122 | |
123 StreamWriter fileWriter = null; | |
124 try | |
125 { | |
126 if (File.Exists(filePath)) | |
127 fileWriter = File.AppendText(filePath); | |
128 else | |
129 fileWriter = File.CreateText(filePath); | |
130 fileWriter.Write(line); | |
131 } | |
132 finally | |
133 { | |
134 if (fileWriter != null) | |
135 fileWriter.Close(); | |
136 } | |
137 } | |
138 private string getHomeDir() | |
139 { | |
140 if (Environment.OSVersion.Platform == PlatformID.Unix || | |
141 Environment.OSVersion.Platform == PlatformID.MacOSX) | |
142 { return Environment.GetEnvironmentVariable("HOME") + "/"; } | |
143 else | |
144 { | |
145 return Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") + "\\"; | |
146 } | |
147 } | |
148 } | |
149 } | |
150 } |