diff --git a/.idea/Seminar.iml b/.idea/Seminar.iml index d0876a7..75ba541 100644 --- a/.idea/Seminar.iml +++ b/.idea/Seminar.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file diff --git a/algorithms.py b/algorithms.py index 25f3177..da9b3e9 100644 --- a/algorithms.py +++ b/algorithms.py @@ -1,3 +1,4 @@ +from argparse import ArgumentError from math import log, ceil from operator import itemgetter from classes import * @@ -87,9 +88,9 @@ class MST(): tour = [] for edge in tree:# go throug all edges and recursively walk down all that lead to new places, on return add back edge - if edge[0] == start and edge[1] not in visited: + if edge[0].get_location() == start.get_location() and edge[1].get_location() not in visited: tour.append(edge) - visited.append(start) # visited only needs to be carried in for a node downwards but not upwards, since this is a MST + visited.append(start.get_location()) # visited only needs to be carried in for a node downwards but not upwards, since this is a MST data = self._dfs_recursive(tree,edge[1],visited) tour+= data # add subtree tour.append((edge[1],edge[0],edge[2])) #append reversed edge @@ -111,22 +112,46 @@ class MST(): return walk - - - - - - - - class AlgorithmA(SolvingAlgorithm): def __init__(self, space:MetricSpace, gMngr: GarageManager): super().__init__(space, gMngr) gar_set = set(gMngr.garages) self.mst = MST(gar_set,space.distancefunction,space,True) - def getGarageForCar(self, car: Point): - + def getGarageForCar(self, car: Car): + garagedata= self.garageManager.get_garage_at_location(car.get_location()) + garagefound = garagedata[0] + garage: Garage = garagedata[1] + if(not garagefound): + raise ArgumentError("No garage found INSIDE of ALGO A") + + if(not self.garageManager.is_full(garage)): + car.set_walk(0) + garage.cars_parked.append(car) + return garage + + carParked = False + while not carParked: + walk = self.mst.get_dfs_eulerwalk(car,car.get_walk()) # implicite, position of car determines where it arrived! + + if len(walk) <1: continue + if car.get_walk() >32: + raise ArgumentError("walk got over power 32, this is likely an error and an infinite loop") + + currentGarage = self.garageManager.get_garage_at_location(car.get_location()) + for x in walk: + currentGarage = self.garageManager.get_garage_at_location( + x[1].get_location()) # second argument of edge + + ##TODO Finish implementation, garage full case and proper start + + if not self.garageManager.is_full(currentGarage): + garage.cars_parked.append(car) + return garage + + + car.add_to_walk(1) + return super().getGarageForCar(car) diff --git a/classes.py b/classes.py index 70446f5..ce78961 100644 --- a/classes.py +++ b/classes.py @@ -295,6 +295,12 @@ class GarageManager: for x in self.currentFillLevel.keys(): self.currentFillLevel[x]=0 + def get_garage_at_location(self, location:Point): + for x in self.garages: + if x.get_location() == location.get_location(): + return (True,x) + return (False, Point(-100,-100)) + def is_full(self, garage:Point): garage_found = False current_garage:Garage diff --git a/main.py b/main.py index 9fa756d..f8c23db 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ import numpy as np FRAME_MULTIPLIER_VIDEO = 10 -def renderTomp4(removeImageSource = True): +def renderTomp4(removeImageSource = False): img_list_unfiltered = os.listdir(OUTPUT_DIR) img_list =[] @@ -84,10 +84,10 @@ def createRandomsListSequence(points:set):#, garages:set def main(): # seeded randomness - random.seed(0) + random.seed(25) space = MetricSpace.getPopulatedSpace(10,10) - ammountToKeep = random.randint(20,95) + ammountToKeep = 100#random.randint(50,95) points = createRandomSubspace(space.points,ammountToKeep) func = space.distancefunction @@ -95,7 +95,7 @@ def main(): space = MetricSpace(points,func) # generate garages - garagesCount = random.randint(3, 8) + garagesCount = 3#random.randint(5, 10) garages_locations = createRandomSubspace(points, garagesCount) capactiyPerGarage = math.ceil(50.0/garagesCount) #create Garage capacity @@ -103,15 +103,22 @@ def main(): for x in garages_locations: garages.append(Garage(x,capactiyPerGarage)) + garages = [Garage(Point(0,0),1), + Garage(Point(5,9),1), + Garage(Point(8,5),1)] + gMngr = GarageManager(garages) # initiate solving Algorithm algo : SolvingAlgorithm = SolvingAlgorithm(space,gMngr) - algo : SolvingAlgorithm = AlgorithmA(space,gMngr) + #algo : SolvingAlgorithm = AlgorithmA(space,gMngr) # sequence = createRandomsListSequence(points.difference(garages),garages) squence without garages - #sequence = createRandomsListSequence(points) - sequence = createRandomsListSequence(garages) # For algo A + sequence = createRandomsListSequence(points) + #sequence = createRandomsListSequence(garages) # For algo A + sequence = [Car(Point(5,5),0), + Car(Point(9,0),1), + Car(Point(1,1),2)] fmg = frameGenerator(space,gMngr) fmg.renderFrame()