Revision 76cefba1
Merged scheduler implementations and modified order structrure class
scout/libscout/src/behaviors/Scheduler.cpp | ||
---|---|---|
29 | 29 |
delete waitingRobots; |
30 | 30 |
} |
31 | 31 |
|
32 |
/** @Brief: Add robot to the waiting queue. */ |
|
32 |
/** @Brief: Add robot to the waiting queue. |
|
33 |
* A robot calls this function with itself |
|
34 |
* and gets pushed on a list of waiting robots. |
|
35 |
* When a task is availaible the scheduler, removes |
|
36 |
* the robot of the waiting queue, and gives it a |
|
37 |
* task. |
|
38 |
*/ |
|
33 | 39 |
void Scheduler::get_task(WH_Robot r) |
34 | 40 |
{ |
35 | 41 |
waitingRobots.push(r); |
... | ... | |
39 | 45 |
void Scheduler::create_orders() |
40 | 46 |
{ |
41 | 47 |
Order a(1,0,0,101,0,0,0); |
42 |
Order b(2,0,0,11,0,0,0);
|
|
43 |
Order c(3,0,0,91,0,0,0);
|
|
44 |
Order d(4,0,0,21,0,0,0);
|
|
45 |
Order e(5,0,0,41,0,0,0);
|
|
48 |
Order b(2,0,0,11,0,0,0); |
|
49 |
Order c(3,0,0,91,0,0,0); |
|
50 |
Order d(4,0,0,21,0,0,0); |
|
51 |
Order e(5,0,0,41,0,0,0); |
|
46 | 52 |
|
47 | 53 |
unassignedOrders.insert(a); |
48 | 54 |
unassignedOrders.insert(b); |
... | ... | |
81 | 87 |
/** @Brief: The scheduling algorithm. Picks a task and pops from the PQWrapper. */ |
82 | 88 |
Order Scheduler::get_next_item() |
83 | 89 |
{ |
90 |
Time time = ros::TIME_MAX; |
|
91 |
|
|
92 |
Order best; |
|
93 |
for(int i=0; i<unassigned_orders.arraySize(); i++) |
|
94 |
{ |
|
95 |
Order order = unassigned_orders.peek(i); |
|
96 |
|
|
97 |
if(order.orderDeadline < time) //TODO: use another function |
|
98 |
{ |
|
99 |
best = order; |
|
100 |
time = order.orderDeadline; |
|
101 |
} |
|
102 |
} |
|
84 | 103 |
|
85 | 104 |
} |
86 | 105 |
|
... | ... | |
90 | 109 |
{ |
91 | 110 |
while (ok()) |
92 | 111 |
{ |
93 |
while(waitingRobots.empty() || unassignedOrders.arraySize()==0) waiting_dance(); |
|
112 |
while(waitingRobots.empty() || unassignedOrders.arraySize()==0) |
|
113 |
waiting_dance(); |
|
114 |
|
|
94 | 115 |
waitingRobots.front().set_task(get_next_item()); |
95 | 116 |
waitingRobots.pop(); |
96 | 117 |
} |
Also available in: Unified diff