-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArtificialBeeColony_Sensor.js
83 lines (68 loc) · 2.76 KB
/
ArtificialBeeColony_Sensor.js
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
"use strict";
importScripts('./ArtificialBeeColony.js', './SensorDeploymentProblem.js');
function ArtificialBeeColony_Sensor(parameters) {
ArtificialBeeColony.call(this, parameters);
this.sensorDeploymentProblem = new SensorDeploymentProblem(parameters.numOfSensors, parameters.numOfPoints,
parameters.radius, parameters.width, parameters.height);
this.sensorDeploymentProblem.setPointsArray(parameters.initialPointsArray);
}
;
ArtificialBeeColony_Sensor.prototype = Object.create(ArtificialBeeColony.prototype);
ArtificialBeeColony_Sensor.prototype.constructor = ArtificialBeeColony;
ArtificialBeeColony_Sensor.prototype.calculateObjValue = function (array) {
this.sensorDeploymentProblem.setSensorsArray(array);
return -1 * this.sensorDeploymentProblem.getCoverage();
};
ArtificialBeeColony_Sensor.prototype.createRandomPosition = function () {
var randPos = this.sensorDeploymentProblem.generateRandomSensorsArray();
return randPos;
};
ArtificialBeeColony_Sensor.prototype.createInitialPopulation = function () {
var i, min = Number.MAX_VALUE, minIndex = 0;
//initialization step
for (i = 0; i < this.foodNumber; i++) {
var randPos = this.sensorDeploymentProblem.generateRandomSensorsArray();
var randF = this.calculateObjValue(randPos);
this.foods[i] = new Solution(randPos, randF); //create random solution
this.trial[i] = 0; //init the trial number
if (randF < min) {
min = randF;
minIndex = i;
}
}
this.globalBest = new Solution(this.foods[minIndex].position.slice(0), min);
console.log("Initial: " + min);
};
ArtificialBeeColony_Sensor.prototype.fixBoundary = function (array) {
for (var i = 0; i < this.sensorDeploymentProblem.getNumOfSensors(); i++) {
if (array[2 * i] > this.sensorDeploymentProblem.getAreaWidth()) {
array[2 * i] = this.sensorDeploymentProblem.getAreaWidth();
} else if (array[2 * i] < 0) {
array[2 * i] = 0;
}
if (array[2 * i + 1] > this.sensorDeploymentProblem.getAreaHeight()) {
array[2 * i + 1] = this.sensorDeploymentProblem.getAreaHeight();
} else if (array[2 * i + 1] < 0) {
array[2 * i + 1] = 0;
}
}
return array;
};
onmessage = function (e) {
var parameters = {
"NP": e.data[0],
"limit": e.data[1],
"maxFEs": e.data[2],
"upperBound": e.data[3],
"lowerBound": e.data[4],
"dimension": e.data[5],
"numOfSensors": e.data[6],
"numOfPoints": e.data[7],
"radius": e.data[8],
"width": e.data[9],
"height": e.data[10],
"initialPointsArray": e.data[11]
};
var abc_s = new ArtificialBeeColony_Sensor(parameters);
abc_s.solve();
};