-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHIVE.java
104 lines (82 loc) · 2.43 KB
/
HIVE.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
/*
* Authors: Luca Ostertag-Hill, Tom Lucy, Jake Rourke
* Date: 11/7/2018
*
* This class defines a HIVE object for use in Ant Colony Optimization on the SMTWTP.
* A HIVE object contains all of the ANTs for use in the algorithms, stored as an
* array of ANTs, the integer number of jobs in the SMTWTP problem instance, the
* integer number of ants for use in the algorithm instance, the score of the best
* workflow found so far by any ants, stored as a double, and the best worklow found so
* far by any of the ants, stored as an array of integers.
*
*/
public class HIVE {
ANT[] hive;
int num_jobs;
int num_ants;
double best_score_so_far;
int[] best_workflow_so_far;
/* Purpose: Initialize a HIVE object
* Parameters: An integer number of ants, an integer number of jobs, and the SMTWTP instance.
* Return: N/A
*/
public HIVE(int num_ants, int num_jobs, SMTWTP smtwtp) {
this.num_ants = num_ants;
this.num_jobs = num_jobs;
this.hive = new ANT[num_ants];
this.best_score_so_far = Double.MAX_VALUE;
this.best_workflow_so_far = new int[num_jobs];
//create the ants
for (int i = 0; i < num_ants; i++) {
hive[i] = new ANT(num_jobs, smtwtp);
}
}
/* Purpose: Find the best workflow of all the ANTs in the HIVE
* Parameters: None
* Return: boolean indicating whether a new best tour was found
*/
public boolean findBest() {
boolean is_new_best = false;
for (int i = 0; i < num_ants; i++) {
if (hive[i].getWorkflow_score() < best_score_so_far) {
this.best_score_so_far = hive[i].getWorkflow_score();
this.best_workflow_so_far = hive[i].getWorkflow().clone();
is_new_best = true;
}
}
return is_new_best;
}
/*
* Getters and Setters
*/
public ANT[] getHive() {
return hive;
}
public void setHive(ANT[] hive) {
this.hive = hive.clone();
}
public int getNum_jobs() {
return num_jobs;
}
public void setNum_jobs(int num_jobs) {
this.num_jobs = num_jobs;
}
public int getNum_ants() {
return num_ants;
}
public void setNum_ants(int num_ants) {
this.num_ants = num_ants;
}
public double getBest_score_so_far() {
return best_score_so_far;
}
public void setBest_score_so_far(double best_score_so_far) {
this.best_score_so_far = best_score_so_far;
}
public int[] getBest_workflow_so_far() {
return best_workflow_so_far;
}
public void setBest_workflow_so_far(int[] best_workflow_so_far) {
this.best_workflow_so_far = best_workflow_so_far.clone();
}
}