Skip to content
Snippets Groups Projects
Commit d45db2c0 authored by Cseh Viktor's avatar Cseh Viktor
Browse files

Objektumorientalta kell teni, hatha ugy gyorsabb lesz

parent 314768be
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -3,7 +3,7 @@
# 2021.10.08 #
#########################################
import sys
#import sys
import math
##### Global variables #####
......@@ -15,75 +15,55 @@ route_between_points = []
route = []
calculated_lengths = []
distance = [] #Ebbe mennek a pontok eleresi hosszai
seen = []
distance = []
notseenpoints = []
##### Global functions #####
# Start search route from point, and gives back a route. Works recursive
# Start from point a, and not stopping until point b reached
def dijkstra(a, b):
seen[a] = 1 # jeloljuk, hogy mar jartunk itt, ne kezdjuk el
if(a == b): # Ekkor elertuk a keresett pontot
calculated_lengths.append(distance[b])
#print("*** debug: kiszamoltuk a legrovidebb utat" , file=sys.stderr)
return
for i in range(0, len(route_between_points), 2): # iteralni a route_between_points-on, hogy az == e a meghivottal es kiszamolni a szomszedokhoz tartozo utat, ami esetleg legrovidebb lehet
if(route_between_points[i] == a):
length = calc_route_length(a, route_between_points[i+1])
if(distance[route_between_points[i+1]] == None):
distance[route_between_points[i+1]] = length + distance[a]
#print("*** debug: distance = " + str(distance[route_between_points[i+1]]), file=sys.stderr)
continue
length = calc_route_length(route_between_points[i], route_between_points[i+1])
if(length + distance[a] < distance[route_between_points[i+1]]): # ha kisebb az eddig tudott utvonalnal a most talalt, akkor cserelje ki arra
distance[route_between_points[i+1]] = length + distance[a]
if(route_between_points[i+1] == a ):
length = calc_route_length(a, route_between_points[i])
if(distance[route_between_points[i]] == None):
distance[route_between_points[i]] = length + distance[a]
continue
elif(route_between_points[i+1] == a):
length = calc_route_length(route_between_points[i], route_between_points[i+1])
if(length + distance[a] < distance[route_between_points[i]]):
distance[route_between_points[i]] = length + distance[a]
def route_search():
asd = len(point_coordinates)
asd = asd/2
asd = int(asd)
for x in range(0,len(route_to_calc),2):
for i in range(asd):
for i in range(map_config[1]):
if(i == route_to_calc[x]):
distance.append(0)
else:
distance.append(None)
distance.append(math.inf)
notseenpoints.append(i)
for i in range(asd):
seen.append(0)
for y in range(map_config[1]):
while(len(notseenpoints) != 0):
minimum_distance = math.inf
corresponding_point = None
cntr = 0
i = 0
for i in range(0, len(seen), 1):
if(seen[i] == 0 and (distance[i] != None)): #Meghivni ra a dijkstra algoritmust rekurzivan, ha mar szamoltuk, de ne jartunk meg benne
for i in range(len(notseenpoints)):
if(distance[notseenpoints[i]] != None): #Meghivni ra a dijkstra algoritmust rekurzivan, ha mar szamoltuk, de ne jartunk meg benne
if(distance[notseenpoints[i]] < minimum_distance): # Es legkisebb a tavolsaga eddig
cntr += 1
if(distance[i] < minimum_distance): # Es legkisebb a tavolsaga eddig
minimum_distance = distance[i]
corresponding_point = i
minimum_distance = distance[notseenpoints[i]]
corresponding_point = notseenpoints[i]
if(cntr > 0):
notseenpoints.remove(corresponding_point)
dijkstra(corresponding_point, route_to_calc[x+1])
distance.clear()
seen.clear()
notseenpoints.clear()
def calc_route_length(a, b):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment