-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_sat1.cpp
300 lines (272 loc) · 6.4 KB
/
my_sat1.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
//#define lli long long int;
int main(int argc, char* argv[]){
// vector<pair<int,pair<int,int>>> Ys;
freopen(argv[1],"r",stdin);
long long int V,E,K;
cin>>V;
cin>>E;
cin>>K;
// string str = "";
long long int temp;
int x[(V*V)+1];
long long int v1,v2;
for(int i=1;i<=V;i++){
for(int j=i+1;j<=V;j++){
x[V*(i-1)+j] = 0;
}
}
for(int i=0;i<E;i++){
cin>>v1;
cin>>v2;
if(v1<v2){
x[V*(v1-1)+v2] = 1;
}
else{
x[V*(v2-1)+v1] = 1;
}
}
ofstream myfile;
myfile.open (argv[2]);
myfile<< "p cnf ";
long long int num_var = (V*(V-1))/2 + V*K + (V*(V-1)*K)/2 + V*(K*K - K);
//long long int num_var = V*V + V*K + V*V*K + V*K*K;
// long long int hasharray[V*V + V*K + V*V*K + V*K*K];
vector<long long int> hasharray(V*V + V*K + V*V*K + V*K*K);
for(long long int i=0;i<(V*V + V*K + V*V*K + V*K*K);i++)
hasharray.at(i) = 0;
long long int counter = 1;
// cout << num_var;
myfile<<num_var;
myfile<<" ";
long long int num_clause = (V*(V-1)*(3*K+1))/2 + (V*(V-1)*(K+1))/2 + (3*V+1)*(K*K - K);
myfile<<num_clause;
myfile<<"\n";
for(int i=1;i<=V;i++){
for(int j=i+1;j<=V;j++){
// ostringstream str1;
temp = V*(i-1)+j;
// str1 << temp;
if(x[V*(i-1)+j] == 0){
myfile << "-";
// hasharray.at(temp) = counter;
// myfile << counter;
// counter++;
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
myfile<<counter;
counter++;
}
else
myfile<<hasharray.at(temp);
myfile << " 0\n";
// str = str + "-" + str1.str()+" 0\n";
}
else{
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
myfile<<counter;
counter++;
}
else
myfile<<hasharray.at(temp);
myfile << " 0\n";
}
}
}
long long int temp1,temp2,temp3;
// string str_temp = "";
for(int i=1;i<=V;i++){
for(int j=i+1;j<=V;j++){
ostringstream my_str;
// ostringstream str1,str2;
temp1 = V*(i-1)+j;
// str1 << temp;
// str2<<temp;
myfile << "-";
myfile << hasharray.at(temp1);
// str = str + "-"+ str1.str();
temp = V*V + V*K + (i-1)*V + j;
// str1<<temp;
// cout<<str1<<" it\n";
for(int k=1;k<=K;k++){
myfile << " ";
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
myfile<<counter;
counter++;
}
else
myfile<<hasharray.at(temp);
// str = str + " "+ str1.str();
my_str<<hasharray.at(temp1);
my_str<<" -";
my_str<<hasharray.at(temp);
my_str<<" 0\n";
// str_temp = str_temp + str2.str() + " -" + str1.str()+" 0\n";
temp += V*V;
// str1<<temp;
}
//str = str + " 0\n";
myfile<<" 0\n";
myfile<< (my_str.str());
//str = str + str_temp;
}
}
long long int to_return = counter;
for(int k=1;k<=K;k++){
temp = V*V + (k-1)*V;
for(int i=1;i<=V;i++){
temp+=1;
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
// myfile<<counter;
counter++;
}
else
cout << "You shouldn't have ventured out here \n";
}
}
for(int i=1;i<=V;i++){
for(int j=i+1;j<=V;j++){
// ostringstream str1,str2,str3;
temp1 = V*V + i;
temp2 = V*V + j;
temp3 = V*V + V*K + (i-1)*V + j;
// str1 << temp1;
// str2<<temp2;
// str3 << temp3;
for(int k=1;k<=K;k++){
myfile<<"-";
myfile<<hasharray.at(temp1);
myfile<<" -";
myfile<<hasharray.at(temp2);
myfile<<" ";
myfile<<hasharray.at(temp3);
myfile<<" 0\n";
myfile<<"-";
myfile<<hasharray.at(temp3);
myfile<<" ";
myfile<<hasharray.at(temp1);
myfile<<" 0\n";
myfile<<"-";
myfile<<hasharray.at(temp3);
myfile<<" ";
myfile<<hasharray.at(temp2);
myfile<<" 0\n";
// str = str + "-" + str1.str() + " -" + str2.str() + " " + str3.str() + " 0\n";
// str = str + "-" + str3.str() + " " + str1.str() + " 0\n";
// str = str + "-" + str3.str() + " " + str2.str() + " 0\n";
temp1 += V;
temp2 += V;
temp3 += V*V;
// str1<<temp1;
// str2<<temp2;
// str3<<temp3;
}
}
}
for(int k1=1;k1<=K;k1++){
for(int k2=1;k2<=K;k2++){
if(k1!=k2){
// ostringstream str1;
temp = V*V + V*K + V*V*K + (k1-1)*K + k2;
// str1<<temp;
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
myfile<<counter;
counter++;
}
else
myfile<<hasharray.at(temp);
//str = str + str1.str();
for(int i=2;i<=V;i++){
temp += K*K;
// str1<<temp;
myfile<<" ";
if(hasharray.at(temp)==0){
hasharray.at(temp) = counter;
myfile<<counter;
counter++;
}
else
myfile<<hasharray.at(temp);
//str = str + " " + str1.str();
}
//str = str + " 0\n";
myfile<<" 0\n";
}
}
}
for(int k1=1;k1<=K;k1++){
for(int k2=1;k2<=K;k2++){
if(k1!=k2){
//ostringstream str1,str2,str3;
temp1 = V*V + (k1-1)*V + 1;
temp2 = V*V + (k2-1)*V + 1;
temp3 = V*V + V*K + V*V*K + (k1-1)*K + k2;
//str1 << temp1;
//str2<<temp2;
//str3 << temp3;
for(int i=1;i<=V;i++){
myfile<<hasharray.at(temp1);
myfile<<" -";
myfile<<hasharray.at(temp2);
myfile<<" ";
myfile<<hasharray.at(temp3);
myfile<<" 0\n";
myfile<<"-";
myfile<<hasharray.at(temp3);
myfile<<" -";
myfile<<hasharray.at(temp1);
myfile<<" 0\n";
myfile<<"-";
myfile<<hasharray.at(temp3);
myfile<<" ";
myfile<<hasharray.at(temp2);
myfile<<" 0\n";
// str = str + str1.str() + " -" + str2.str() + " " + str3.str() + " 0\n";
// str = str + "-" + str3.str() + " -" + str1.str() + " 0\n";
// str = str + "-" + str3.str() + " " + str2.str() + " 0\n";
temp1 += 1;
temp2 += 1;
temp3 += K*K;
// str1<<temp1;
// str2<<temp2;
// str3<<temp3;
}
}
}
}
// cout<<str<<"\n";
myfile.close();
ofstream aux;
aux.open (argv[3]);
aux << V << " " << K << " "<< to_return <<"\n";
aux.close();
//Generate my hash mappings
// for(int vert = 1; vert <= V; vert++)
// {
// int temp_vr = V*V + vert;
// for(int subg = 1; subg <= K; subg++)
// {
// Ys.push_back(make_pair(temp_vr,make_pair(vert,subg)));
// temp_vr += V;
// }
// }
// freopen("mappings.txt","w",stdout);
// for(auto w: Ys)
// {
// cout << w.first << " - > " << w.second.first << " , " <<w.second.second << endl;
// }
}