-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeightNormal.php
91 lines (78 loc) · 2.27 KB
/
WeightNormal.php
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
<?php
/*
* MIT license.
* By [email protected]
*/
/**
* task priority based on Task scheduling for hetergeneous computing systems
* DOI 10.1007/s11227-016-1917-2
*
*/
class WeightNormal {
private $table = [];
/**
* calculate rank and fill the table
*
* @param array $tree
* @return array
*/
public function getRankTable($tree)
{
for($i = count($tree)-1 ; $i >= 0 ; $i--){
$this->table[$i] = [];
$this->table[$i]["rank"] = $this->getTaskRank($i,$tree);
$this->table[$i]["weight"] = $this->getWeight($tree[$i]);
$this->table[$i]["task"] = $i;
}
return $this->table;
}
/**
* calculate weight_ni using (ni,pj - ni,pk)/(ni,pj / ni,pk)
*
* @param Task object $task
* @return int
*/
private function getWeight($task)
{
$maxWeight = $task->weight[0];
$minWeight = $task->weight[0];
$highProc = NULL; //proccessor had max wight
$lowProc = NULL; //proccessor had min weight
foreach ($task->weight as $key => $value) {
if($value < $minWeight){
$minWeight = $value;
$lowProc = $key;
}
if($value > $maxWeight){
$maxWeight = $value;
$highProc = $key;
}
}
return ($maxWeight - $minWeight) / ($maxWeight / $minWeight);
}
/**
* calculate task rank using weight_ni + MAX(AVG(cij) + rank(nj))
*
* @param index $taskNum
* @param array $tree
* @return int
*/
private function getTaskRank($taskNum,$tree)
{
$maxRank = 0;
$task = $tree[$taskNum];
$weight = $this->getWeight($task);
$comWeight = 0;
// exit node
if(count($task->successor) == 0){
return $weight;
}
foreach ($task->successor as $node) {
if($this->table[$node["target"]]["rank"]+$node["weight"] > $maxRank+$comWeight){
$maxRank = $this->table[$node["target"]]["rank"];
$comWeight = $node["weight"];
}
}
return $weight+$comWeight+$maxRank;
}
}