-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPEFT.php
141 lines (122 loc) · 3.3 KB
/
PEFT.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/*
* MIT license.
* By [email protected]
*/
/**
* task priority based on Task scheduling for hetergeneous computing systems
* chapter 3 related works
* DOI 10.1007/s11227-016-1917-2
*/
class PEFT {
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;
echo $i+1 ."-----------\n";
}
return $this->table;
}
private function OCTTable($task)
{
return $this->table[$task]["rank"];
}
/**
* calculate weight
*
* @param Task object $task
* @return int
*/
private function getWeight($task)
{
$wsum = 0;
foreach ($task->weight as $weight){
$wsum += $weight;
}
return $wsum / count($task->weight);
}
/**
* calculate task rank using AVG(weight_i) + MAX(AVG(cij) + rank(nj))
*
* @param index $taskNum
* @param array $tree
* @return int
*/
private function getTaskRank($taskNum,$tree)
{
$task = $tree[$taskNum];
$oct = 0;
foreach ($task->weight as $key=>$proc){
$oct += $this->getOCT($taskNum,$tree,$key);
echo $oct."h\n";
}
echo $oct / count($task->weight)."f\n";
return $oct / count($task->weight);
}
private function getOCT($taskNum,$tree,$processor)
{
$maxOCT = 0;
$minOCT = null;
$task = $tree[$taskNum];
foreach ($task->successor as $suc){
foreach ($task->weight as $key=>$proc){
$oct = $this->OCTTable($suc["target"])
+ $this->getWeight($tree[$suc["target"]])
+ $this->getCommunication($tree[$suc["target"]], $processor,$key);
echo $oct."\n";
if($oct < $minOCT || $minOCT == NULL){
$minOCT = $oct;
}
}
if($minOCT > $maxOCT){
$maxOCT = $minOCT;
}
}
return $maxOCT;
}
/**
* get processor with low processing time for given task
*
* @param object $task
* @return array
*/
private function getMinimumProcessor($task)
{
$processor = 0;
$minimum = $task->weight[0];
foreach ($task->weight as $key => $e){
if($minimum > $e){
$minimum = $e;
$processor = $key;
}
}
return ["proccessor"=>$processor, "time"=>$minimum];
}
/**
* get communication weight
*
* @param type $task
* @param type $pr
* @return boolean
*/
private function getCommunication($task,$pr,$key)
{
$flag = 0;
foreach($task->predeccessor as $pred){
if($pr != $key){
$flag = $pred["weight"];
}
}
return $flag;
}
}