-
Notifications
You must be signed in to change notification settings - Fork 3
/
model345-peg.cpp
191 lines (184 loc) · 4.99 KB
/
model345-peg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Copyright (C) 2000,2001 Franz Josef Och (RWTH Aachen - Lehrstuhl fuer Informatik VI)
This file is part of GIZA++ ( extension of GIZA ).
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
#include "model3.h"
#include "collCounts.h"
bool makeOneMoveSwap(const alignment&x,const alignment&y,set<OneMoveSwap>&soms)
{
OneMoveSwap oms;
oms.type=0;
int count=0;
Vector<int> positions(4);
assert(x.get_m()==y.get_m());
for(PositionIndex j=1;j<=x.get_m();j++)
if(x(j)!=y(j))
{
if(count==4)
return 0;
positions[count]=j;
count++;
}
assert(count>0);
if(count==1)
{
oms.type=1;
oms.a=positions[0];
oms.b=y(positions[0]);
soms.insert(oms);
for(unsigned int j=1;j<=x.get_m();++j)
{
if( int(j)!=positions[0]&&y(j)==y(positions[0]))
{
oms.type=3;
oms.a=j;
oms.b=x(positions[0]);
soms.insert(oms);
}
}
for(unsigned int j=1;j<=x.get_m();++j)
{
if( int(j)!=positions[0]&&x(j)==x(positions[0]))
{
oms.type=2;
oms.a=positions[0];
oms.b=j;
if( oms.b<oms.a)swap(oms.b,oms.a);
soms.insert(oms);
}
}
return 1;
}
else if(count==2)
{
if(x(positions[0])==y(positions[1]) && x(positions[1])==y(positions[0]))
{
oms.type=4;
oms.a=positions[0];
oms.b=positions[1];
soms.insert(oms);
for(unsigned int j=1;j<=x.get_m();++j)
{
if( int(j)!=positions[0]&&y(j)==y(positions[0]))
{
oms.type=2;oms.a=j;oms.b=positions[1];if( oms.b<oms.a)swap(oms.b,oms.a);soms.insert(oms);
}
if( int(j)!=positions[1]&&y(j)==y(positions[1]))
{
oms.type=2;oms.a=j;oms.b=positions[0];if( oms.b<oms.a)swap(oms.b,oms.a);soms.insert(oms);
}
}
}
else if(x(positions[0])==y(positions[1]) )
{
oms.type=3;
oms.a=positions[0];
oms.b=x(positions[1]);
soms.insert(oms);
oms.type=2;
oms.a=positions[0];
oms.b=positions[1];
soms.insert(oms);
}
else if( x(positions[1])==y(positions[0]) )
{
oms.type=3;
oms.a=positions[1];
oms.b=x(positions[0]);
soms.insert(oms);
oms.type=2;
oms.a=positions[0];
oms.b=positions[1];
soms.insert(oms);
}
oms.type=3;
oms.a=positions[0];
oms.b=x(positions[0]);
soms.insert(oms);
oms.a=positions[1];
oms.b=x(positions[1]);
soms.insert(oms);
return 1;
}
else if( count==3 )
{ // three differences and three different numbers
Vector<int> xx(3),yy(3);
xx[0]=x(positions[0]);xx[1]=x(positions[1]);xx[2]=x(positions[2]);
yy[0]=y(positions[0]);yy[1]=y(positions[1]);yy[2]=y(positions[2]);
sort(xx.begin(),xx.end());
sort(yy.begin(),yy.end());
if(xx==yy)
{
oms.type=2;oms.a=positions[0];oms.b=positions[1];soms.insert(oms);
oms.type=2;oms.a=positions[0];oms.b=positions[2];soms.insert(oms);
oms.type=2;oms.a=positions[1];oms.b=positions[2];soms.insert(oms);
}
else
{
//cout << "HERE.\n";
if( x(positions[0])==y(positions[1])&&x(positions[1])==y(positions[0]) )
{
oms.type=2;oms.a=positions[0];oms.b=positions[1];
if( oms.b<oms.a) swap(oms.b,oms.a);
soms.insert(oms);
oms.type=3;oms.a=positions[2];oms.b=x(positions[2]);soms.insert(oms);
}
if( x(positions[2])==y(positions[1])&&x(positions[1])==y(positions[2]) )
{
oms.type=2;oms.a=positions[2];oms.b=positions[1];
if( oms.b<oms.a) swap(oms.b,oms.a);
soms.insert(oms);
oms.type=3;oms.a=positions[0];oms.b=x(positions[0]);soms.insert(oms);
}
if( x(positions[0])==y(positions[2])&&x(positions[2])==y(positions[0]) )
{
oms.type=2;oms.a=positions[0];oms.b=positions[2];
if( oms.b<oms.a) swap(oms.b,oms.a);
soms.insert(oms);
oms.type=3;oms.a=positions[1];oms.b=x(positions[1]);soms.insert(oms);
}
}
return 1;
}
else if(count==4)
{
Vector<int> xx(4),yy(4);
for(int i=0;i<4;++i)
{
xx[i]=x(positions[i]);
yy[i]=y(positions[i]);
}
sort(xx.begin(),xx.end());
sort(yy.begin(),yy.end());
if(xx==yy)
{
oms.type=2;
for(int j1=0;j1<4;j1++)
for(int j2=j1+1;j2<4;j2++)
{
if(x(positions[j1])!=x(positions[j2])&&
x(positions[j1])==y(positions[j2])&&
x(positions[j2])==y(positions[j1]))
{
oms.type=2;oms.a=positions[j1];oms.b=positions[j2];
soms.insert(oms);
}
}
}
return 1;
}
else
return 0;
}