86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
from enum import Enum
|
|
import math
|
|
|
|
|
|
class ParsingMode(Enum):
|
|
LOCATIONS = 1
|
|
FLIGHTSCHEDULE = 2
|
|
FINDCONNECTION = 3
|
|
|
|
|
|
class LocationType(Enum):
|
|
LOCATION = 1
|
|
HALTESTELLE = 2
|
|
FLUGHAFEN = 3
|
|
|
|
|
|
class TransportData():
|
|
def __init__(self, co2: float, speed: float, distance_penalty: float):
|
|
self.co2 = co2
|
|
self.speed = speed
|
|
self.distance_penalty = distance_penalty
|
|
|
|
|
|
class TransportMethod(Enum):
|
|
"""
|
|
(co2 emission, speed, distance_penalty)
|
|
"""
|
|
WALK = TransportData(0, 4, 0.2)
|
|
CITY = TransportData(0.189, 30, 0.2)
|
|
AUTOBAHN = TransportData(0.189, 100, 0.2)
|
|
OEPNV = TransportData(0.055, 30, 0.1)
|
|
ICE = TransportData(0.055, 100, 0.1)
|
|
AIRPLANE = TransportData(0.2113, 900, 0.02)
|
|
|
|
|
|
class Coordinate:
|
|
def __init__(self, lat: float, long: float):
|
|
self.lat = lat
|
|
self.long = long
|
|
|
|
def __str__(self):
|
|
return f"Lat: {self.lat}, Long: {self.long}"
|
|
|
|
def __repr__(self):
|
|
return self.__str__()
|
|
|
|
|
|
class Location:
|
|
def __init__(self, coord: Coordinate, continent: int, name: str, type: LocationType):
|
|
self.coord = coord
|
|
self.continent = continent
|
|
self.name = name
|
|
self.type = type
|
|
|
|
def __str__(self):
|
|
return f"{{Location: {self.coord}, continent: {self.continent}, name: {self.name}, type: {self.type}}}"
|
|
|
|
def __repr__(self):
|
|
return self.__str__()
|
|
|
|
def distance(self, loc2) -> float:
|
|
"""
|
|
Calculate the distance im km between two locations with the help of the
|
|
Seitenkosinussatz
|
|
"""
|
|
rErde = 6378.388
|
|
lat1 = float(self.coord.lat)
|
|
long1 = float(self.coord.long)
|
|
lat2 = float(loc2.coord.lat)
|
|
long2 = float(loc2.coord.long)
|
|
inner = math.sin(lat1) * math.sin(lat2) + math.cos(lat1) * math.cos(lat2) * math.cos(long2 - long1)
|
|
return rErde * math.acos(inner)
|
|
|
|
|
|
class DataSet:
|
|
def __init__(self, locations: dict, flights: dict, connection: tuple):
|
|
self.locations = locations
|
|
self.flights = flights
|
|
self.connection = connection
|
|
|
|
def __str__(self):
|
|
return f"locations: {self.locations}, flights: {self.flights}, connection: {self.connection}"
|
|
|
|
def __repr__(self):
|
|
return self.__str__()
|