-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCANteamformation (3).java
209 lines (167 loc) · 7.23 KB
/
SCANteamformation (3).java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.SQLOutput;
import java.util.*;
public class SCANteamformation {
public static void main(String arg[])throws Exception {
String folderName = "C:\\Users\\AmangelB\\IdeaProjects\\Finalthesis\\src\\50K";
String twoHopFileName = "2HopCoverDist_1000.0_G1_50K.txt";
String filename = "invertedTermMap.txt";
String graphG1 = "G1.txt";
String filePath = folderName + "/" + filename;
String filepath1 = folderName + "/" + graphG1;
String line;
MethodsForSCAN mds = new MethodsForSCAN();
Map<String, List<Integer>> invertedmap = mds.getInvertedIndexMap(folderName, filename);
for (Map.Entry<String, List<Integer>> entry : invertedmap.entrySet()) {
String key = entry.getKey();
List<Integer> value = entry.getValue();
// System.out.println(" Skill:"+ key +"-"+ value);
}
//create a list to store list of required skill for the project
List<String> reqSkill = new ArrayList<String>();
reqSkill.add("technique");
reqSkill.add("workflows");
reqSkill.add("activities");
// System.out.println(reqSkill);
List<Expertskills> PoolofExperts = mds.CollectAllRequiredExpert(reqSkill, invertedmap);
System.out.println("initial Pool:");
for (Expertskills ex : PoolofExperts) {
System.out.print(ex.skills + ": ");
for (int j = 0; j < ex.experts.length; j++) {
System.out.print(ex.experts[j] + ",");
}
System.out.println();
}
//store all experts without skill into a list
List<Integer> Expertsonly = new ArrayList<Integer>();
for (Expertskills es : PoolofExperts) {
for (int j = 0; j < es.experts.length; j++) {
Expertsonly.add(es.experts[j]);
}
}
FileReader fr = new FileReader(filepath1);
BufferedReader br = new BufferedReader(fr);
List<Expertskills> ExpertCounting = new ArrayList<Expertskills>();
String lineE = br.readLine();
int count = 0;
while (lineE != null) {
String[] parts = lineE.split("\\s+");
Expertskills ex = new Expertskills();
int Count = parts.length;
int tempExpertid = Integer.parseInt(parts[0]);
for (String w : parts) {
count++;
}
for (int j = 0; j < Expertsonly.size(); j++) {
if (tempExpertid == Expertsonly.get(j)) {
ex.expertId = tempExpertid;
ex.totconn = count;
ExpertCounting.add(ex);
}
}
lineE = br.readLine();
count = 0;
}
for (Expertskills ex : ExpertCounting) {
System.out.print(ex.expertId + ": " + ex.totconn);
System.out.println();
}
Collections.sort(ExpertCounting, Expertskills.DegreeComparator());
System.out.println("After short");
int highdegree = ExpertCounting.get((ExpertCounting.size()) - 1).totconn;
// if more than one node have the highest degree, collect all into list
List<Integer> CoreGroup = new ArrayList<Integer>();
for (int i = 0; i < ExpertCounting.size(); i++) {
if (ExpertCounting.get(i).totconn == highdegree) {
CoreGroup.add(ExpertCounting.get(i).expertId);
}
}
// then choose random node from all core nodes
int CORE = 0;
for (int i = 0; i < CoreGroup.size(); i++) {
CORE = mds.getRandomList(CoreGroup);
}
System.out.println("CORE:" + CORE);
String skillofcore="";
for (Expertskills ex : PoolofExperts) {
for (int j = 0; j < ex.experts.length; j++) {
if(ex.experts[j]==CORE)
skillofcore=ex.skills;
}
}
reqSkill.remove(skillofcore);
System.out.println(reqSkill);
PoolofExperts = mds.CollectAllRequiredExpert(reqSkill, invertedmap);
for (Expertskills ex : PoolofExperts) {
System.out.print(ex.skills + ": ");
for (int j = 0; j < ex.experts.length; j++) {
System.out.print(ex.experts[j] + ",");
}
System.out.println();
}
GraphIndexing gi = new GraphIndexing();
Map<Integer, TwoHop[]> twoHopMap = gi.readTwoHopIndexArray(twoHopFileName, folderName);
List<Expert> DistwithCORE = new ArrayList<>();
double[] allDist = new double[ExpertCounting.size()];
for (int i = 0; i < ExpertCounting.size() - 1; i++) {
double dist = gi.queryTwoHopArray(twoHopMap, ExpertCounting.get(i).expertId, CORE);
Expert ex = new Expert();
ex.distance = dist;
ex.expertId = ExpertCounting.get(i).expertId;
DistwithCORE.add(ex);
allDist[i] = dist;
}
Collections.sort(DistwithCORE, Expert.DistComparator());
}
// group by distance
Map<Double, List<Expert>> expertByDist = new HashMap<>();
for (Expert p : DistwithCORE) {
if (!expertByDist.containsKey(p.getDistance())) {
expertByDist.put(p.getDistance(), new ArrayList<>());
}
expertByDist.get(p.getDistance()).add(p);
}
List<Integer> clusterwDist=new ArrayList<Integer>();
List<Expertskills> teamofExperts = new ArrayList<Expertskills>();
List<Integer> clusterwDist1=new ArrayList<Integer>();
for (Map.Entry<Double, List<Expert>> entry : expertByDist.entrySet()) {
Double key = entry.getKey();
List<Expert> value = entry.getValue();
for (int i = 0; i < value.size(); i++) {
if (key == 0.0) {
clusterwDist.add(value.get(i).getExpertId());
}
if(key<=3.0)
{
clusterwDist1.add(value.get(i).getExpertId());
}
}
// find the skill of experts who have communication cost 1.0
List<Expertskills> skillofCluster=new ArrayList<Expertskills>();
for(int k=0; k<clusterwDist.size();k++) {
for (Expertskills ex : PoolofExperts) {
for (int j = 0; j < ex.experts.length; j++) {
if (clusterwDist.get(k) == ex.experts[j]) {
Expertskills exx = new Expertskills();
exx.expertId = ex.experts[j];
exx.skills = ex.skills;
skillofCluster.add(exx);
teamofExperts.add(exx);
}
}
}
}
List<Expertskills> skillofCluster1=new ArrayList<Expertskills>();
for(int k=0; k<clusterwDist1.size();k++) {
for (Expertskills ex : PoolofExperts) {
for (int j = 0; j < ex.experts.length; j++) {
if (clusterwDist1.get(k) == ex.experts[j]) {
Expertskills exx = new Expertskills();
exx.expertId = ex.experts[j];
exx.skills = ex.skills;
skillofCluster1.add(exx);
}
}
}
}