-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jury_Pool1.java
executable file
·97 lines (81 loc) · 3.18 KB
/
Jury_Pool1.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
package jury;
import java.util.ArrayList;
public class Jury_Pool1 {
int initialSize = 0;
int juryPoolSize = 0;
int[] juryPoolList;
/*In the constructor below a string is passed as parameter to first
* The variable "initialSize" represents the size of the initial list of candidates.
* The variable "juryPoolSize" is the size of the final pool of potential jurors without any 'relationship'
* in the first sense. This number is unique for a given input list of candidates.
* The variable "juryPoolList" is an integer array containing a list of potential juror id's. These lists
* can vary. But of course they must all satisfy the basic criterion that there is no 'relationship'
* (in the first sense) between any pair.
* The class JuryGraph represents the basic graph of direct relations.
*/
public Jury_Pool1(String s) {
JuryGraph candidateRelation = new JuryGraph(s);
/*
The string 's' represents the path to the input file.
*/
initialSize = candidateRelation.graph_Size;
juryPoolSize = calcPoolsize(candidateRelation);
juryPoolList = calcPoolList(candidateRelation);
System.out.println(juryPoolSize);
System.out.println("");
for (int i = 0; i < juryPoolList.length; i++) {
System.out.println(juryPoolList[i]);
}
}
public ArrayList<Integer> calculate (JuryGraph jG){
int graph[][] = new int[jG.graph_Size][jG.graph_Size];
for (int i=0; i<jG.graph_Size; i++)
for (int j=0; j<jG.candidate_List.get(i+1).adj_List.size(); j++) {
graph[i][jG.candidate_List.get(i+1).adj_List.get(j).id-1] = 1;
}
GraphClosure g = new GraphClosure(jG.graph_Size);
g.transitiveClosure(graph);
ArrayList<Integer> al = new ArrayList<Integer>();
for (int i=0; i<graph[0].length; i++) {
for (int j=0; j<graph[0].length; j++) {
if (i!=j) {
if(graph[i][j]==1 && al.contains(i+1)==false) {
al.add(j+1);
}
}
}
}
ArrayList<Integer> jList = new ArrayList<Integer>();
for (int j = 1; j <= jG.graph_Size; j++) {
if (!al.contains(jG.candidate_List.get(j).id))
jList.add(jG.candidate_List.get(j).id);
}
return jList;
}
int calcPoolsize(JuryGraph jG) {
int poolSize = 0;
/*
The variable poolSize is given as a suggestion. You are free to change it if you wish.
Of course you have to return some variable of integer type. It has been initialized to 0.
Note: 0 is not an acceptable value for the jury pool size.
You can write any other classes and methods
to help you calculate.
*/
poolSize = calculate(jG).size();
return poolSize;
}
int[] calcPoolList(JuryGraph jG) {
int[] poolList = new int[juryPoolSize];
/*
* We have an integer array poolList. To create this array you will have to calculate
* juryPoolSize first. You can change it. But make sure the function returns an array
* of integers that represents an acceptable jury pool.
* It is suggested that you create some classes and methods of your own and call them here. This
* method and the one preceding can be considered 'wrapper' methods.
*/
ArrayList<Integer> x = calculate(jG);
for (int i=0; i<juryPoolSize; i++)
poolList[i] = x.get(i);
return poolList;
}
}