-
Notifications
You must be signed in to change notification settings - Fork 28
/
conflict.py
46 lines (35 loc) · 1.27 KB
/
conflict.py
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
"""Class file for `Conflict`."""
from utils import str2sha1
class Conflict:
"""`Conflict` represents two aircrafts are too close to each other in an
airport.
"""
def __init__(self, locations, aircrafts):
self.locations = locations
self.aircrafts = aircrafts
callsigns = []
for aircraft in aircrafts:
callsigns.append(aircraft.callsign)
callsigns.sort()
self.hash = str2sha1("%s#%s" %
("#".join(callsigns),
"#".join(str(self.locations))))
def __hash__(self):
return self.hash
def __eq__(self, other):
return self.hash == other.hash
def __ne__(self, other):
return not self == other
def __repr__(self):
return "<Conflict: %s %s>" % (self.locations, self.aircrafts)
def get_less_priority_aircraft(self, scenario):
"""Retrieves the less priority aircraft between the two conflicted
aircrafts.
"""
first, second = (scenario.get_flight(self.aircrafts[0]),
scenario.get_flight(self.aircrafts[1]))
return (
self.aircrafts[1]
if first.departure_time < second.departure_time
else self.aircrafts[0]
)