changes for temp render
This commit is contained in:
Generated
+4
-2
@@ -1,8 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
<orderEntry type="inheritedJdk" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12 (Seminar)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
+37
-12
@@ -1,3 +1,4 @@
|
|||||||
|
from argparse import ArgumentError
|
||||||
from math import log, ceil
|
from math import log, ceil
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from classes import *
|
from classes import *
|
||||||
@@ -87,9 +88,9 @@ class MST():
|
|||||||
tour = []
|
tour = []
|
||||||
|
|
||||||
for edge in tree:# go throug all edges and recursively walk down all that lead to new places, on return add back edge
|
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)
|
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)
|
data = self._dfs_recursive(tree,edge[1],visited)
|
||||||
tour+= data # add subtree
|
tour+= data # add subtree
|
||||||
tour.append((edge[1],edge[0],edge[2])) #append reversed edge
|
tour.append((edge[1],edge[0],edge[2])) #append reversed edge
|
||||||
@@ -111,22 +112,46 @@ class MST():
|
|||||||
|
|
||||||
return walk
|
return walk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AlgorithmA(SolvingAlgorithm):
|
class AlgorithmA(SolvingAlgorithm):
|
||||||
def __init__(self, space:MetricSpace, gMngr: GarageManager):
|
def __init__(self, space:MetricSpace, gMngr: GarageManager):
|
||||||
super().__init__(space, gMngr)
|
super().__init__(space, gMngr)
|
||||||
gar_set = set(gMngr.garages)
|
gar_set = set(gMngr.garages)
|
||||||
self.mst = MST(gar_set,space.distancefunction,space,True)
|
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)
|
return super().getGarageForCar(car)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -295,6 +295,12 @@ class GarageManager:
|
|||||||
for x in self.currentFillLevel.keys():
|
for x in self.currentFillLevel.keys():
|
||||||
self.currentFillLevel[x]=0
|
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):
|
def is_full(self, garage:Point):
|
||||||
garage_found = False
|
garage_found = False
|
||||||
current_garage:Garage
|
current_garage:Garage
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import numpy as np
|
|||||||
|
|
||||||
FRAME_MULTIPLIER_VIDEO = 10
|
FRAME_MULTIPLIER_VIDEO = 10
|
||||||
|
|
||||||
def renderTomp4(removeImageSource = True):
|
def renderTomp4(removeImageSource = False):
|
||||||
img_list_unfiltered = os.listdir(OUTPUT_DIR)
|
img_list_unfiltered = os.listdir(OUTPUT_DIR)
|
||||||
img_list =[]
|
img_list =[]
|
||||||
|
|
||||||
@@ -84,10 +84,10 @@ def createRandomsListSequence(points:set):#, garages:set
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# seeded randomness
|
# seeded randomness
|
||||||
random.seed(0)
|
random.seed(25)
|
||||||
space = MetricSpace.getPopulatedSpace(10,10)
|
space = MetricSpace.getPopulatedSpace(10,10)
|
||||||
|
|
||||||
ammountToKeep = random.randint(20,95)
|
ammountToKeep = 100#random.randint(50,95)
|
||||||
|
|
||||||
points = createRandomSubspace(space.points,ammountToKeep)
|
points = createRandomSubspace(space.points,ammountToKeep)
|
||||||
func = space.distancefunction
|
func = space.distancefunction
|
||||||
@@ -95,7 +95,7 @@ def main():
|
|||||||
space = MetricSpace(points,func)
|
space = MetricSpace(points,func)
|
||||||
|
|
||||||
# generate garages
|
# generate garages
|
||||||
garagesCount = random.randint(3, 8)
|
garagesCount = 3#random.randint(5, 10)
|
||||||
garages_locations = createRandomSubspace(points, garagesCount)
|
garages_locations = createRandomSubspace(points, garagesCount)
|
||||||
capactiyPerGarage = math.ceil(50.0/garagesCount)
|
capactiyPerGarage = math.ceil(50.0/garagesCount)
|
||||||
#create Garage capacity
|
#create Garage capacity
|
||||||
@@ -103,15 +103,22 @@ def main():
|
|||||||
for x in garages_locations:
|
for x in garages_locations:
|
||||||
garages.append(Garage(x,capactiyPerGarage))
|
garages.append(Garage(x,capactiyPerGarage))
|
||||||
|
|
||||||
|
garages = [Garage(Point(0,0),1),
|
||||||
|
Garage(Point(5,9),1),
|
||||||
|
Garage(Point(8,5),1)]
|
||||||
|
|
||||||
gMngr = GarageManager(garages)
|
gMngr = GarageManager(garages)
|
||||||
|
|
||||||
# initiate solving Algorithm
|
# initiate solving Algorithm
|
||||||
algo : SolvingAlgorithm = SolvingAlgorithm(space,gMngr)
|
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.difference(garages),garages) squence without garages
|
||||||
#sequence = createRandomsListSequence(points)
|
sequence = createRandomsListSequence(points)
|
||||||
sequence = createRandomsListSequence(garages) # For algo A
|
#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 = frameGenerator(space,gMngr)
|
||||||
fmg.renderFrame()
|
fmg.renderFrame()
|
||||||
|
|||||||
Reference in New Issue
Block a user