ea11273b05da71589c876d9b1f9a260ac4b59584
[mussa.git] / mussa_nway_refine.cc
1 PathList
2 ExtendPathWindows(PathList raw_list)
3 {
4   // to keep track of everything, this function acts like a finite state
5   // automata:  3 bitfields: reset, extending, scanning - ie 8 states
6   int reset = 0, extending = 0, scanning = 0;
7
8   int species_num = raw_list.SpeciesNum();
9   int win_num = raw_list.WinNum();
10
11   int *cur_path, *next_path;
12
13   cur_path = new int[species_num];
14   next_path = new int[species_num];
15
16   raw_list.ResetIndex();
17
18   while (no more windows avaible)
19   {
20     //cur_indices[0] + ref_ext == next_indices[0] + 1:
21
22     // state 000 - start/nominal search
23     // 
24     if !reset && !extending && !scanning
25     {
26       if cur_path[0] == next_path[0]
27       {
28         scanning = 1;                   // go to state 001
29         raw_list.IncreIndex();
30       }
31       else if cur_path[0] + 1 == next_path[0]
32       {
33         extending = 1;                  // go to state 010
34         win_ext = 1;
35         raw_list.SetDirty();
36         raw_list.IncreIndex();
37       }
38       else
39         reset = 1;                      // go to state 100
40     }
41
42     // state 001 - scanning for ext window thru possible interleaving
43     // 
44     else if !reset && !extending && scanning
45     {
46       if cur_path[0] == next_path[0]
47         raw_list.IncreIndex();
48       else if cur_path[0] + 1 == next_path[0]
49       {
50         extending = 1;                  // go to state 011
51         win_ext = 1;
52         raw_list.SetDirty();
53         raw_list.IncreIndex();
54       }
55       else
56         reset = 1;                      // go to state 101
57     }
58
59     // state 010 - extending window with no interleaving
60     // 
61     else if !reset && extending && !scanning
62     {
63       if (cur_path[0] + win_ext) == next_path[0]
64       {
65         extending = 1;                  // go to state 011
66         raw_list.IncreIndex();
67       }
68       else if (cur_path[0] + win_ext + 1) == next_path[0]
69       {
70         win_ext++;
71         raw_list.SetDirty();
72         raw_list.IncreIndex();
73       }
74       else
75         reset = 1;                      // go to state 110
76     }
77
78     // state 011 - extending window with interleaving
79     // 
80     else if !reset && extending && scanning
81     {
82       if (cur_path[0] + win_ext) == next_path[0]
83         raw_list.IncreIndex();
84       else if (cur_path[0] + win_ext + 1) == next_path[0]
85       {
86         win_ext++;
87         raw_list.SetDirty();
88         raw_list.IncreIndex();
89       }
90       else
91         reset = 1;                      // go to state 111
92     }
93
94
95     // reset condition states, return to 000 after taking appropiate action
96
97     // state 100 - no extended window, no scanning happened
98     // save basic window to extended window list
99     if reset && !extending && !scanning
100     {
101       // return to start/nominal search state
102       reset = 0;
103     }
104
105     // state 101 - no extended window, scanned for interleaving
106     // save basic window to extended window list, return to first clean 
107     else if reset && !extending && scanning
108     {
109       // return to start/nominal search state
110       reset = 0;
111       scanning = 0;
112     }
113
114     // state 110 - extended window, no interleaving
115     // calc extended window, save to extended window list
116     else if reset && extending && !scanning
117     {
118       // return to start/nominal search state
119       reset = 0;
120       extending = 0;
121     }
122        
123     // state 111 - extended window, interleaved
124     // calc extended window, save to ext win list, return to first clean
125     else if reset && extending && scanning
126     {        
127       // return to start/nominal search state
128       reset = 0;
129       extending = 0;
130       scanning = 0;
131      }
132
133   return ext_win;
134 }