-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEFTSelection.php
161 lines (145 loc) · 4.54 KB
/
EFTSelection.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
* MIT license.
* By [email protected]
*/
/**
* processor selection based on Task scheduling for hetergeneous computing systems
* chapter 3 related works
* DOI 10.1007/s11227-016-1917-2
*/
class EFTSelection {
private $peat = [0,0]; //processor earliest available time
private $selectedprocessor = [];
private $est = [];
private $eft = [];
/**
* running schedule
*
* @param array $tree
* @param array $table
*/
public function runSchedule($tree, $table)
{
foreach ($table as$task) {
$eft = $this->getEFT($task["task"],$tree);
$meft = $this->getMinimumEFT($eft[$task["task"]]);
if ($this->getCommunication($tree[$task["task"]],$meft["processor"]) == 0){
$this->peat[$meft["processor"]] = $eft[$task["task"]][$meft["processor"]];
} else {
$this->peat[$meft["processor"]] = $eft[$task["task"]][$meft["processor"]]+$tree[$task["task"]]->weight[$meft["processor"]];
}
$this->selectedprocessor[$task["task"]]["processor"] = $meft["processor"];
$this->selectedprocessor[$task["task"]]["eft"] = $meft["time"];
$this->selectedprocessor[$task["task"]]["est"] = $eft[$task["task"]]["est"][$meft["processor"]];
$this->selectedprocessor[$task["task"]]["task"] = $task["task"];
}
return $this->selectedprocessor;
}
/**
* calculating Earliest Finish Time
*
* @param object $task
* @param array $tree
* @return array
*/
private function getEFT($task,$tree)
{
$est = $this->getEST($task,$tree);
foreach ($est as $key=>$EST){
$this->eft[$task][$key] = $tree[$task]->weight[$key]+$EST;
$this->eft[$task]["est"][$key] = $EST;
}
return $this->eft;
}
private function getEST($task,$tree)
{
foreach ($this->peat as $key=>$processor){
$lastEFT = $this->getPredeccessorEFT($task, $tree, $key);
if($lastEFT > $processor){
$this->est[$task][$key] = $lastEFT;
} else {
$this->est[$task][$key] = $processor;
}
}
return $this->est[$task];
}
/**
* finding a processor with minimum EFT
*
* @param array $eft
* @return $array
*/
private function getMinimumEFT($eft)
{
$processor = 0;
$minimum = $eft[0];
foreach ($eft as $key => $e){
if($minimum > $e && $key != "est"){
$minimum = $e;
$processor = $key;
}
}
return ["processor"=>$processor, "time"=>$minimum];
}
/**
* get communication weight
*
* @param type $task
* @param type $pr
* @return boolean
*/
private function getCommunication($task,$pr)
{
$flag = 0;
foreach($task->predeccessor as $pred){
if($pr == $this->selectedprocessor[$pred["target"]]){
$flag = $pred["weight"];
}
}
return $flag;
}
/**
* geting predeccessors eft
*
* @param type $task
* @param type $processor
* @return max eft as int
*/
private function getPredeccessorEFT($task,$tree,$processor)
{
$eft = 0;
$com = 0;
foreach ($tree[$task]->predeccessor as $pred){
$e = $this->eft[$pred["target"]][$this->selectedprocessor[$pred["target"]]["processor"]];
if($this->isItLocalTo($pred["target"], $task, $tree, $processor)==FALSE){
$e += $pred["weight"];
}
if($eft < $e){
$eft = $e;
}
}
return $eft+$com;
}
private function isItLocalTo($pr ,$task,$tree,$key)
{
$flag = FALSE;
if($key == $this->selectedprocessor[$pr]["processor"]){
$flag = TRUE;
} elseif ($this->isSuccessorRunOn($pr,$tree,$key)) {
$flag = TRUE;
}
return $flag;
}
private function isSuccessorRunOn($task, $tree, $processor)
{
$flag = FALSE;
$succes = $tree[$task]->successor;
foreach ($succes as $suc){
if( isset($this->selectedprocessor[$suc["target"]]) && $processor == $this->selectedprocessor[$suc["target"]]["processor"]){
$flag = TRUE;
}
}
return $flag;
}
}