-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectsForRL.cpp
More file actions
104 lines (93 loc) · 2.74 KB
/
objectsForRL.cpp
File metadata and controls
104 lines (93 loc) · 2.74 KB
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
// - CPU Utilization(C)
// - Throughput (T)
// - Turnaround time (TA)
// - Waiting time (WT)
// - Response time (RT)
// - Deadline meet ratio (DR)
//
/*
Structure as define by the paper
Environment: Multicore Processor
Agent: Dispatcher
States:
1. Initial State(S1)
2. Objective Degradation stage(S2)
3. Objective Progression Stage(S3)
4. Objective Stabilization Stage(S4)
Action: Mapping the task to one of the N queues
Reward: The value of the multi objective function.
O=w1*C+w2*T-w3*([TA/TAe] -1)-w4*([WT/WTe] -1)-w5*([RT/RTe] -1)+ w6*DR
*/
/*
struct agent //this is our RL agent
{
queue<task*> tasksToAssign;
int actionToTake;
int totalAssignments;
void assignTask(task *t, queue<task*> &q);
void testAssign(task &t, queue<task*> &q);
void getEvironmentInfo();
};
void zeroQtable(vector<vector<int>> &table)
{
for(int i = 0; i < 5; i++)
{
vector<int> temp(5);
table.push_back(temp);
}
}
vector<int> task::curState()
{
vector<int> temp;
temp.insert(temp.end(), {this->executionTime, this->remainingTime, this->deadline});
return temp;
}
void agent::assignTask(task *t, queue<task*> &q)
{
q.push(t);
}
void qLearning(vector<task*> &tasks, cpu *processor,
vector<queue<task*>> multiLevelQ, int lRate, int dRate, int epsilon, unordered_map<vector<int>, float, VectorHasher> qTable)
{
int nArrivals = 0;
int clock = 0;
while(nArrivals < tasks.size())
{
for(int i = 0; i < tasks.size(); i++) //sending tasks to dispatcher to begin assignment to Queues
{
if(tasks[i]->arrivalTime == clock)
{
dispatcher->tasksToAssign.push(tasks[i]);
nArrivals++;
}
}
double r = ((double) rand() / (RAND_MAX));
vector<int> state = dispatcher->tasksToAssign.front()->curState();
int nextAction;
if(r < 1 - epsilon)
{
int maxReward = 0;
for(int j = 0; j < 3; j++)
{
state.push_back(j);
if(qTable[state] > maxReward)
{
nextAction = j;
maxReward = qTable[state];
}
state.pop_back();
}
state.push_back(nextAction);
}
else
{
nextAction = randomGen(0,3);
state.push_back(nextAction);
}
dispatcher->assignTask(dispatcher->tasksToAssign.front(), multiLevelQ[nextAction]);
checkMultiLevelQ(multiLevelQ, processor);
processor->checkCondition
clock++;
}
}
*/