-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceManager.cpp
38 lines (32 loc) · 1.1 KB
/
DeviceManager.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
#include"DeviceManager.h"
DeviceManager::DeviceManager() {
for (int i = 0; i < DEVICENUM; i++) {
DeviceState[i] = queue<double>(); // 创建空队列
}
}
void DeviceManager::occupyDevice(int DeviceNo, double Time) {
if (DeviceNo >= 0 && DeviceNo < DEVICENUM) {
DeviceState[DeviceNo].push(Time);//将占用时间加入状态队列
}
else {
// 处理设备编号超出范围的情况
cout << "设备编号超出范围" << endl;
}
}
vector<int> DeviceManager::runDevice() {
vector<int> finishedDevices;
for (int i = 0; i < DEVICENUM; i++) {
if (!DeviceState[i].empty()) {
double remainingTime = DeviceState[i].front();
remainingTime -= 0.1;//若设备状态队列不为空,表示设备正在运行,取出队首,剩余时间减一
if (remainingTime <= 0) {
finishedDevices.push_back(i);
DeviceState[i].pop();//设备任务完成
}
else {
DeviceState[i].front() = remainingTime;
}
}
}
return finishedDevices;
}