comparison defical-sharp/libbacktrack/walk.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.Collections.Generic;
2
3 namespace libbacktrack
4 {
5 public partial class Backtrack
6 {
7 private void walk()
8 {
9 if (this.myGraph.MinDef() <= this.myGraph.NumVerDef)
10 {
11 this.isProcessing = true;
12 walk(1);
13 }
14 }
15 private void walk(int currentLevel)
16 {
17 if (this.isProcessing)
18 {
19 if (currentLevel >= this.myGraph.NumVerMain)
20 {
21 if (this.myGraph.IsSemt())
22 {
23 if (!this.isRecurseAll)
24 this.isProcessing = false;
25 this.result += this.myGraph.Print(0);
26 this.result += "\n" + this.myGraph.Print(1)+"\n";
27 this.isSemt = true;
28 }
29 removeLabel(currentLevel - 1);
30 }
31 else
32 {
33 List<int> availableLabels = new List<int>();
34 int start = 1, end = this.myGraph.NumVerTotal;
35 if (currentLevel == 1 && this.firstLabel != this.myGraph.NumVerTotal)
36 {
37 if (this.myGraph.GraphType == "wheel")
38 start = end; //optimization for wheel
39 else if (this.myGraph.GraphType == "doublefan")
40 start = this.firstLabel + 1; //optimization for doublefan
41 }
42 else if (this.pathStart != 0)
43 {
44 if (currentLevel == this.pathEnd)
45 start = this.pathLabel + 1; //remove possibility for reversed path labeling
46 else if (currentLevel == this.pathStart && start < end)
47 end = this.myGraph.NumVerTotal - 1; //no need to test last label as it'll be checked already on all previous cases
48 }
49 for (int i = start; i <= end; i++)
50 if (!this.labelVerUsed[i])
51 availableLabels.Add(i);
52 if (availableLabels.Count > 0)
53 {
54 for (int x = availableLabels.Count - 1; x >= 0; x--)
55 {
56 if (currentLevel == this.pathStart && this.pathStart != 0)
57 this.pathLabel = availableLabels[x];
58 if (this.myGraph.IsValidToLabel(currentLevel, availableLabels[x]))
59 {
60 setLabel(currentLevel, availableLabels[x]);
61 walk(currentLevel + 1);
62 }
63 if (!this.isProcessing)
64 break;
65 }
66 }
67 if (currentLevel != 1) { removeLabel(currentLevel - 1); }
68 }
69 }
70 }
71 }
72 }