Mercurial > defical
comparison defical-sharp/defical-cli/threader-backtrack.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 System.IO; | |
4 using libbacktrack; | |
5 | |
6 namespace defical_cli | |
7 { | |
8 public partial class Program | |
9 { | |
10 private partial class main | |
11 { | |
12 private void goBT() | |
13 { | |
14 this.isProcessing = true; | |
15 this.result = ""; | |
16 Thread[] threads = new Thread[this.numThreads]; | |
17 int start; | |
18 int end = 0; | |
19 for (int i = 0; i < this.numThreads; i++) | |
20 { | |
21 threads[i] = new Thread(goThreadBT); | |
22 threads[i].IsBackground = true; | |
23 threads[i].Priority = ThreadPriority.Lowest; | |
24 start = end + 1; | |
25 end = start + ((this.numVer + this.numDef + 1) / 2) / this.numThreads; | |
26 if (i == this.numThreads - 1) | |
27 end = (this.numVer + this.numDef + 1) / 2; | |
28 threads[i].Start(new int[] { start, end, i }); | |
29 } | |
30 while (this.isProcessing) | |
31 { | |
32 Thread.Sleep(100); | |
33 bool threadsIsProcessing = false; | |
34 for (int i = 0; i < this.numThreads; i++) | |
35 { | |
36 if (threads[i].IsAlive) | |
37 { | |
38 threadsIsProcessing = true; | |
39 } | |
40 } | |
41 this.isProcessing = threadsIsProcessing; | |
42 } | |
43 if (this.result == "") { this.result = "SEMT labeling can't be constructed."; } | |
44 Console.WriteLine(this.result); | |
45 this.isProcessing = false; | |
46 for (int i = 0; i < this.numThreads; i++) | |
47 { | |
48 if (threads[i].IsAlive) | |
49 { | |
50 threads[i].Abort(); | |
51 } | |
52 } | |
53 | |
54 } | |
55 private void goThreadBT(object o) | |
56 { | |
57 int[] args = o as int[]; | |
58 int start = args[0]; | |
59 int end = args[1]; | |
60 int threadID = args[2]; | |
61 for (int i = start; i <= end; i++) | |
62 { | |
63 //if (this.isProcessing) | |
64 { | |
65 Backtrack todo = new Backtrack(this.graphType, this.numVer, this.numDef, i, true); | |
66 todo.Walk(); | |
67 if (this.isProcessing) | |
68 { | |
69 if (todo.IsSemt) | |
70 { | |
71 //this.isProcessing = false; | |
72 Console.Write("{0}",todo.Result); | |
73 this.result = todo.Result; | |
74 /*string filename = "log-" + | |
75 this.graphType + "-" + | |
76 "numver=" + this.numVer.ToString() + "-" + | |
77 "numdef=" + this.numDef.ToString() + "-" + | |
78 DateTime.UtcNow.ToString("yyyyMMdd_hhmmss"); | |
79 string filepath = getHomeDir() + filename; | |
80 int n = 1; | |
81 while (File.Exists(filepath + ".txt")) | |
82 { | |
83 if (!File.Exists(filepath + "-" + n.ToString() + ".txt")) | |
84 { | |
85 filepath += "-" + n.ToString(); | |
86 break; | |
87 } | |
88 n++; | |
89 } | |
90 WriteToFile(filepath + ".txt", this.result);*/ | |
91 //break; | |
92 } | |
93 else | |
94 { | |
95 Console.WriteLine("[404] SEMT labeling not found for first label of {0}", i); | |
96 } | |
97 } | |
98 } | |
99 } | |
100 } | |
101 } | |
102 } | |
103 } |