Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <time.h>
- #define OutputToFile 1
- #define NrCTC 1000
- #define nodes 100000
- using namespace std;
- ofstream fout("data.out");
- ofstream dout("debug.out");
- vector<int> ctc[NrCTC+1];
- int a[nodes+1];
- struct edge{
- int x, y;
- };
- vector<edge> edges;
- vector<edge> edges_between_ctc;
- int main()
- {
- srand(time(0));
- for(int i=1; i<=nodes; i++)
- {
- int ctc_assign = rand() % NrCTC + 1;
- ctc[ctc_assign].push_back(i); /// nu exista ctc[0]
- a[i] = ctc_assign;
- }
- for(int i=1; i<=NrCTC; i++)
- {
- dout << "CTC "<< i << ": ";
- for(auto nod:ctc[i])
- dout << nod << ' ';
- dout << endl;
- }
- for(int i=1; i<=NrCTC; i++)
- {
- if (ctc[i].size()==0) continue;
- edge e;
- /// adding edges to make CTC (in a cricle):
- for(int j=0; j<ctc[i].size()-1; j++)
- {
- e.x = ctc[i][j];
- e.y = ctc[i][j+1];
- edges.push_back(e);
- }
- e.x = ctc[i][ctc[i].size()-1]; // closing circle
- e.y = ctc[i][0];
- edges.push_back(e);
- /// probabilistically adding random edges in ith CTC:
- while(rand() % 100 < 97)
- {
- //int nrr1 = rand()%(ctc[i].size()-1;
- //int nrr2 = rand()%(ctc[i].size()-1;
- e.x = ctc[i][rand()%ctc[i].size()];
- e.y = ctc[i][rand()%ctc[i].size()];
- if (e.x==e.y) continue;
- int alreadyAdded = 0;
- for(auto ee:edges)
- if (ee.x==e.x && ee.y==e.y) alreadyAdded = 1;
- if (!alreadyAdded) edges.push_back(e);
- }
- }
- /// adding random edges and counting remembering how they connect the CTCs
- /// not connecting CTC both ways:
- while(rand() % 100 < 98)
- {
- edge e;
- e.x = rand()% nodes + 1;
- e.y = rand()% nodes + 1;
- if (e.x==e.y) continue; /// the same node
- if (a[e.x]== a[e.y]) continue; /// they are already in same CTC
- int ctc1 = a[e.x];
- int ctc2 = a[e.y];
- if (ctc1<ctc2)
- {
- swap(e.x, e.y);
- }
- int alreadyAdded = 0;
- for(auto ee:edges)
- {
- /// non of the edges between CTCs exists:
- if (a[ee.x]==a[e.x] && a[ee.y]==a[e.y])
- alreadyAdded = 1;
- }
- if (!alreadyAdded) edges.push_back(e);
- }
- if (OutputToFile) fout << nodes << ' ' << edges.size() << endl << endl;
- else cout << nodes << ' ' << edges.size() << endl << endl;
- for(auto e:edges){
- if (OutputToFile) fout << e.x << ' ' << e.y << '\n';
- else cout << e.x << ' ' << e.y << '\n';
- }
- fout<< '\n' << nodes << '\n';
- for(int i=1; i<=nodes; i++) fout << i << ' ';
- if (OutputToFile) fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment