-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate_re_players_graph.cpp
241 lines (194 loc) · 4.57 KB
/
duplicate_re_players_graph.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
#include <iostream>
#include<cstdio>
#include<stdlib.h>
#include<limits>
#include<math.h>
#include<string.h>
#include<conio.h>
using namespace std;
static int k=0;
static int l=0;
int aray[100][10];
int graph[100][100];
struct Edge
{
int src;// source
int des;// destination
int weight;
};
struct Graph
{
int V;//no of vertices
int E;//no pf edges
struct Edge* edge;
};
struct Graph* graph_create_graph(int V,int E)
{
struct Graph* graph=(struct Graph*)malloc(sizeof(struct Graph));
graph->V=V;
graph->E=E;
graph->edge=(struct Edge*)malloc(graph->E*sizeof(struct Edge));
return graph;
};
void create_edge_set(int matrix[][100],int power,int l)
{
int V = power; // Number of vertices in graph
int E = l;
int m=0;
int i,j;// Number of edges in graph
struct Graph* graph = graph_create_graph(V, E);
for( i=0;i<V;i++)
{
for( j=0;j<V;j++)
{
if(matrix[i][j]==1)
{
graph->edge[m].src=i;
graph->edge[m].des=j;
graph->edge[m].weight=8;
m++;
}
}
}
for( i=0;i<m;i++)
{
printf("%d %d %d ",graph->edge[i].src,graph->edge[i].des,graph->edge[i].weight);
printf("\n");
}
return;
}
void print_graph(int graph[][100],int power)
{
for(int i=0;i<power;i++)
{
for(int j=0;j<power;j++)
{
cout<<graph[i][j]<<" ";
}
cout<<endl;
}
}
void print(int aray[][10],int n,int power,int r[],int f[],int x)
{
for(int i=0;i<n;i++)
cout<<aray[k][i]<< " ";
k++;
int temp_dec[100];
if(k==power)
{
cout<<endl;
for(int i=0;i<power;i++)
{
for(int j=0;j<n;j++)
{
if(aray[i][j]-f[j]<aray[0][j])
temp_dec[j]=aray[i][j]-aray[0][j];
else
temp_dec[j]=f[j];
}
}
for(int i=0;i<power;i++)
{
for(int m=0;m<power;m++)
{
int flag=1;
for(int j=0;j<n && flag==1;j++)
{
if((aray[i][j]+r[j]==aray[m][j]) || (aray[i][j]-temp_dec[j]==aray[m][j]))
{
flag=1;
}
else
flag=0;
}
if(flag==1)
{
for(int z=0;z<n;z++)
cout<< aray[i][z]<< " ";
cout<<" -";
for(int z=0;z<n;z++)
cout<<aray[m][z]<< " ";
cout<<endl;
graph[i][m]=1;
l++;//count number of edges;
}
else
graph[i][m]=0;
}
}
for(int i=0;i<power;i++)
{
bool mark=true;
for(int k=0;k<power && mark==true;k++)
{
for(int j=0;j<n ;j++)
{
if(aray[i][j]-temp_dec[j]!=aray[k][j])
mark=false;
}
if(mark==true)
{
graph[i][k]=0;
l--;
}
}
}
print_graph(graph,power);
create_edge_set(graph,power,l);
}
return;
}
void add(int ary[], int n,int power,int r[],int f[],int x)
{
for ( int i = 0; i < n; ++i)
{
aray[k][i]=ary[i];
}
print(aray,n,power,r,f,x);
}
void tr(int depth,int top,int k, int *arr,int x,int machines,int power,int r[],int f[])
{
for(int i=0;i<x;i++)
{
if(depth!=machines)
{
arr[top]=k+i;
tr(depth+1,top+1,k,arr,x,machines,power,r,f);
}
}
if(depth==machines)
{
add(arr,top,power,r,f,x);
cout<<endl;
}
return ;
}
int main()
{
//int arr[100];
int power, p,n1,n2,i;
int m=0;
cout<<"enter the number of machines: ";
cin>>p;//Number of players
cout<<"enter the starting band: ";
cin>>n1;
cout<<"enter the ending band: ";
cin>>n2;
int band_diff = n2-n1-1;
cout<<band_diff<<endl;
power=pow((n2-n1-1),p);
int *arr=(int*)malloc(((n2-n1)-1)*sizeof(int*));
for( i=n1+1;i<n2;i++)
{
arr[m]=i;
m++;
}
for( i=0;i<(n2-n1-1);i++)
printf("%d \n",arr[i]);
int r[]={1,2,3,2,1};
int f[]={1,2,3,2,2};
printf("Total number of nodes in graph : %d",power);
printf("\n");
tr(0,0,arr[0],arr,band_diff,p,power,r,f);
return 0;
}