root / scout / libscout / src / helper_classes / Order.cpp @ 9b4328d7
History | View | Annotate | Download (1.27 KB)
1 |
#include "Order.h" |
---|---|
2 |
|
3 |
using namespace std; |
4 |
|
5 |
/** @Brief: Regular order constructor */
|
6 |
Order::Order(int order_id, Address order_source, Address order_dest, Time order_deadline, Time order_start_time, Path order_path, Time order_est_time)
|
7 |
{ |
8 |
id = order_id; |
9 |
source = order_source; |
10 |
dest = order_dest; |
11 |
start_time = order_start_time; |
12 |
path = order_path; |
13 |
est_time = order_est_time; |
14 |
} |
15 |
|
16 |
/** @Brief: Get order ID */
|
17 |
int Order::getid() const |
18 |
{ |
19 |
return id;
|
20 |
} |
21 |
|
22 |
Address Order::get_source() const
|
23 |
{ |
24 |
return source;
|
25 |
} |
26 |
|
27 |
Address Order::get_dest() const
|
28 |
{ |
29 |
return dest;
|
30 |
} |
31 |
|
32 |
Time Order::get_start_time() const
|
33 |
{ |
34 |
return start_time;
|
35 |
} |
36 |
|
37 |
Path Order::get_path() const
|
38 |
{ |
39 |
return path;
|
40 |
} |
41 |
|
42 |
bool Order::operator==(Order& o1, Order& o2) |
43 |
{ |
44 |
return o1.id == o2.id;
|
45 |
} |
46 |
|
47 |
void Order::set_path(Path order_path)
|
48 |
{ |
49 |
path = order_path; |
50 |
return;
|
51 |
} |
52 |
/** @Brief: Order comparison function for PQWrapper
|
53 |
* NOTE: In order to have a min priority queue, using c++'s pq
|
54 |
* implementation, the compare function must return true if
|
55 |
* o1 is greater than o2.
|
56 |
*/
|
57 |
bool CompareOrder::operator()(Order& o1, Order& o2) |
58 |
{ |
59 |
int pq_value1 = o1.get_start_time + MAX_WAIT_TIME - o1.get_est_time();
|
60 |
int pq_value2 = o2.get_start_time + MAX_WAIT_TIME - o2.get_est_time();
|
61 |
return pq_value1 > pq_value2;
|
62 |
} |
63 |
|