-
Notifications
You must be signed in to change notification settings - Fork 0
/
pajek.h
115 lines (94 loc) · 2.89 KB
/
pajek.h
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
#include<iostream>
#include<ostream>
#include<vector>
#include "loadingGraph.h"
void pajek(string inputFileName, vector<vector<int> >myCommunity, Graph *graph)
{
//.clu
ofstream clufile;
string file=inputFileName.substr(0,inputFileName.size()-4)+".clu";
clufile.open(file.c_str());
vector<int> inputcommunitynum;
cout<<endl<<"请输入想要画出的社团编号(输入-1代表画出所有社团):"<<endl;
int input;
cin>>input;
if (input == -1)
for (int i = 0; i < myCommunity.size(); i++)
inputcommunitynum.push_back(i+1);
else
while(input >= 0)
{
inputcommunitynum.push_back(input);
cin>>input;
}
// set<int> allcom;
// for (int x=0;x<myCommunity.size();x++)
// {
// for (int y=0;y<myCommunity[x].size();y++)
// {
// allcom.insert(myCommunity[x][y]);
// }
// }
cout<<endl<<endl;
set<int> allcom;
vector<vector<int> > myC;
for (int x=0;x<inputcommunitynum.size();x++)
{
myC.push_back(myCommunity[inputcommunitynum[x]-1]);
cout<<"第"<<inputcommunitynum[x]<<"个社团:( "<<myCommunity[inputcommunitynum[x]-1].size()<<"个节点 )"<<endl;
for (int y=0;y<myCommunity[inputcommunitynum[x]-1].size();y++)/////////////////////////////////////////////////
{
cout<<graph->Nodenames[myCommunity[inputcommunitynum[x]-1][y]]<<" ";
allcom.insert(myCommunity[inputcommunitynum[x]-1][y]);
}
cout<<endl;
}
clufile<<"*Vertices "<<allcom.size()<<endl;
for (set<int>::const_iterator it=allcom.begin();it!=allcom.end();it++)
{
int node=*it;
int flag=0,communitynum=0;
for (int x=0;x<myC.size();x++)
{
vector<int> v=myC[x];
if (find(v.begin(),v.end(),node)!=v.end())
{
flag=flag+1;
communitynum=x+1;
}
}
if (flag==1)
clufile<<communitynum<<endl;
else if(flag>=2)
clufile<<myC.size()+1<<endl;
}
clufile.close();
//.net
ofstream netfile;
file=inputFileName.substr(0,inputFileName.size()-4)+".net";
netfile.open(file.c_str());
netfile<<"*Vertices "<<allcom.size()<<endl;
int y = 1;
for (set<int>::iterator x=allcom.begin(); x != allcom.end(); x++)
{
// char c[256];
// itoa(x,c,10);
// netfile<<x<<" "<<c<<endl;
netfile<<y++<<" "<<graph->Nodenames[*x]<<endl;
}
netfile<<"*Arcs"<<endl;
netfile<<"*Edges"<<endl;
int index1=0,index2=0;
for (set<int>::const_iterator x=allcom.begin();x!=allcom.end();x++)
{
index1++;
index2=0;
for (set<int>::const_iterator y=allcom.begin();y!=allcom.end();y++)
{
index2++;
if(graph->isConnect(*x,*y))
netfile<<index1<<" "<<index2<<endl;
}
}
netfile.close();
}