-
Notifications
You must be signed in to change notification settings - Fork 0
/
comm.cpp
193 lines (170 loc) · 5.35 KB
/
comm.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
192
//
// comm.cpp
// Lstar
//
// Created by Liang on 16/5/29.
// Copyright © 2016年 Liang. All rights reserved.
//
#include "comm.hpp"
bool getT(std::string str, std::vector<std::string> Uset) {
// if (str == "")
// return false;
//
for (auto uStr : Uset) {
if (uStr == str) {
return true;
}
}
return false;
}
// 得到s*sigema
void getSdotSigemaFromSandSigema(vector<string> sigemaSet, vector<string> sSet,
vector<string> & SdotSigemaSet) {
// 当S为空时
if (sSet.size() == 0) {
for (auto s : sigemaSet) {
SdotSigemaSet.push_back(s);
}
} else {
for (auto s_sSet : sSet) {
for (auto s_sigemaSet : sigemaSet) {
SdotSigemaSet.push_back(s_sSet + s_sigemaSet);
}
}
}
}
// 更新S和S*sigema
void updateSandSdotSigema(string sa, vector<string> sigemaSet,
vector<string> & sSet, vector<string> & SdotSigemaSet) {
// 将sa放入S集合
sSet.push_back(sa);
// 更新SdotSigemaSet
for (auto s_sigemaSet : sigemaSet) {
SdotSigemaSet.push_back(sa + s_sigemaSet);
}
}
string getSa(vector<string> sSet, vector<string> sigemaSet, vector<string> eSet, vector<string> Uset) {
string sa = "";
if (eSet.size() == 0) {
// sSet和eSet为空
if (sSet.size() == 0) {
for (auto a_sigemaSet : sigemaSet) {
string s0 = a_sigemaSet;
string s1 = "";
if (getT(s0, Uset) != getT(s1, Uset)) {
sa = s0;
goto over;
}
}
} else {
// eSet为空, sSet不为空
for (auto s1_sSet : sSet) {
string s1 = s1_sSet;
for (auto s_sSet : sSet) {
for (auto a_sigemaSet : sigemaSet) {
string s0 = s_sSet + a_sigemaSet;
if (getT(s0, Uset) != getT(s1, Uset)) {
sa = s_sSet + a_sigemaSet;
goto over;
}
}
}
}
}
}
else {
if (sSet.size() == 0) {
// sSet为空, eSet不为空
for (auto a_sigemaSet : sigemaSet) {
for (auto e_sSet : eSet) {
string s0 = a_sigemaSet + e_sSet;
string s1 = e_sSet;
if (getT(s0, Uset) != getT(s1, Uset)) {
sa = a_sigemaSet;
goto over;
}
}
}
} else {
for (auto s_sSet : sSet) {
for (auto a_sigemaSet : sigemaSet) {
bool isNowSA = true;
for (auto s1_sSet : sSet) {
int okfors1_sSet = 0;
for (auto e_sSet : eSet) {
string s0 = s_sSet + a_sigemaSet + e_sSet;
string s1 = s1_sSet + e_sSet;
if (getT(s0, Uset) == getT(s1, Uset)) {
okfors1_sSet ++;
}
}
if (okfors1_sSet == eSet.size()) {
isNowSA = false;
break;
}
}
if (isNowSA == true) {
sa = s_sSet + a_sigemaSet;
goto over;
}
}
}
}
}
over:
return sa;
}
void getF(vector<string> sSet, vector<string> & fSet, vector<string> Uset) {
fSet.clear();
for (auto s : sSet) {
if (getT(s, Uset) == true) {
fSet.push_back(s);
}
}
}
void getDelta(vector<string> sSet, vector<string> SdotSigemaSet,vector<string> eSet,
vector<string> Uset, vector<Sdelta> & deltaSet) {
deltaSet.clear();
for(auto sa : SdotSigemaSet) {
for (auto s_1 : sSet) {
bool ok = true;
for (auto e : eSet) {
if (getT(sa+e, Uset) != getT(s_1+e, Uset)) {
ok = false;
break;
}
}
if (ok == true) {
int len = sa.length();
string _s = sa.substr(0, len - 1);
string _a = sa.substr(len - 1, 1);
Sdelta sdelta(_s, _a, s_1);
deltaSet.push_back(sdelta);
}
}
}
}
bool solveCounterExample(string strCEX, vector<string> & eSet) {
bool ret = true;
int sublen = 1;
string str_e = "";
for (int index = strCEX.length() - 1; index >= 0; index--, sublen++) {
str_e = strCEX.substr(index, sublen);
if (strInList(str_e, eSet) == false) {
eSet.push_back(str_e);
}
}
if (str_e == "") {
return false;
} else {
return true;
}
}
bool strInList(string str, vector<string> strList) {
for (auto strFromList : strList) {
if (str == strFromList) {
return true;
}
}
return false;
}