-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalgorithm_move.cpp
89 lines (60 loc) · 2.56 KB
/
algorithm_move.cpp
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
#include <iostream>
#include <climits>
#include "custom_types/ts.h"
#include "custom_types/state.h"
#include "get_delta_t.h"
#include "scheduler.h"
#include "pruning_constraints.h"
#include <cinttypes>
// check which jobs interfere lower priority jobs
void update_interferance_flags(state& s, const uint8_t m, const uint8_t* perm) {
if (s.pendJobsNum > m)
for (int i = 0; i < m; i++)
s.interferred[perm[i]] = true;
}
// Deadline check
bool deadline_miss(const state& s, const bool verbose) {
const uint8_t N = s.tsLocal.n;
if (s.d(N-1) < s.c[N-1]) {
if (verbose) {
cout << "Failure state:" << endl;
for (int i = 0; i < N; i++) {
cout << "c[" << i << "]: " << s.c[i] << " d[" << i << "]: " << s.d(i) << " p[" << i << "]" << s.p[i] << endl;
}
}
return true;
}
return false;
}
// return codes:
// -1 - deadline miss
// 0 - continue traversal of successors
// 1 - schedule can be discarded
int8_t algorithm_move(state& s, const uint8_t N, const uint8_t m, bool verbose) {
if (!conditionA_cri_tau_i(s, m)) return 1;
if (!conditionB_cri_tau_i(s, m)) return 1;
uint8_t* perm = new uint8_t [N];
//unsigned short* perm = new unsigned short [N];
sortTasksByPriorities(s, N, perm);
update_interferance_flags(s, m, perm);
//uint8_t dt = deltaT(s, N, m, perm);
int dt = deltaT(s, N, m, perm);
if (!condition_job_interference(s, m, dt, perm)) {
// interf. cond. violated
for (uint8_t i = 0; i < m; i++) s.c[perm[i]] = max(s.c[perm[i]] - dt, 0);
for (uint8_t i = 0; i < N; i++) s.p[i] = max(s.p[i] - dt, 0); // ????????? to recheck
if (deadline_miss(s, verbose)) return -1;
else return 1; // no deadline miss, but interference cond. violated
} else {
// interf. cond. holds
const uint8_t previousCk = s.c[N-1];
for (uint8_t i = 0; i < N; i++) s.jobCanBeReleasedBefore[i] = ((s.p[i] == 0)?true:false);
conditionC_cri_tau_i(s, m, perm); // set .releaseAtEarliest flags
for (uint8_t i = 0; i < m; i++) s.c[perm[i]] = max(s.c[perm[i]] - dt, 0);
for (uint8_t i = 0; i < N; i++) s.p[i] = max(s.p[i] - dt, 0);
if (deadline_miss(s, verbose)) return -1;
for (uint8_t i = 0; i < N; i++) s.prevState_processorAvailableForTau_i[i] = s.processorAvailableForTau_i[i];
if ((previousCk > 0) && (s.c[N-1] == 0)) return 1; // state is discarded, as analyzed job completes execution
}
return 0;
}