-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDifferentialEvolution_Sensor.js
81 lines (67 loc) · 2.73 KB
/
DifferentialEvolution_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
"use strict";
importScripts('./DifferentialEvolution.js', './SensorDeploymentProblem.js');
function DifferentialEvolution_Sensor(parameters) {
DifferentialEvolution.call(this, parameters);
this.sensorDeploymentProblem = new SensorDeploymentProblem(parameters.numOfSensors, parameters.numOfPoints,
parameters.radius, parameters.width, parameters.height);
this.sensorDeploymentProblem.setPointsArray(parameters.initialPointsArray);
}
;
DifferentialEvolution_Sensor.prototype = Object.create(DifferentialEvolution.prototype);
DifferentialEvolution_Sensor.prototype.constructor = DifferentialEvolution;
DifferentialEvolution_Sensor.prototype.calculateObjValue = function (array) {
this.sensorDeploymentProblem.setSensorsArray(array);
return -1 * this.sensorDeploymentProblem.getCoverage();
};
DifferentialEvolution_Sensor.prototype.createRandomPosition = function () {
var randPos = this.sensorDeploymentProblem.generateRandomSensorsArray();
return randPos;
};
DifferentialEvolution_Sensor.prototype.createInitialPopulation = function () {
var i, min = Number.MAX_VALUE, minIndex = 0;
//initialization step
for (var i = 0; i < this.NP; i++) {
var randPos = this.sensorDeploymentProblem.generateRandomSensorsArray();
var randF = this.calculateObjValue(randPos);
this.solutions[i] = new Solution(randPos, randF); //create random solution
if (randF < min) {
min = randF;
minIndex = i;
}
}
this.globalBest = new Solution(this.solutions[minIndex].position.slice(0), min);
};
DifferentialEvolution_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],
"CR": e.data[1],
"F": e.data[2],
"maxFEs": e.data[3],
"upperBound": e.data[4],
"lowerBound": e.data[5],
"dimension": e.data[6],
"numOfSensors": e.data[7],
"numOfPoints": e.data[8],
"radius": e.data[9],
"width": e.data[10],
"height": e.data[11],
"initialPointsArray": e.data[12]
};
var de_s = new DifferentialEvolution_Sensor(parameters);
de_s.solve();
};