Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algoritmer og datastrukturer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacob Theisen
Algoritmer og datastrukturer
Commits
de38e5a2
Commit
de38e5a2
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
treg som faen
parent
274fcb17
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ov9/program1.py
+58
-92
58 additions, 92 deletions
ov9/program1.py
with
58 additions
and
92 deletions
ov9/program1.py
+
58
−
92
View file @
de38e5a2
...
...
@@ -78,28 +78,8 @@ def init_table():
for
i
in
range
(
num_of_nodes
):
res_arr
.
append
(
results
(
i
,
max_num
.
time
+
1
,
False
,
False
,
None
))
print
(
'
prep done, files loaded to lists
'
)
# def rec_func(node, counter, global_fra, end_switch):
# if not end_switch:
# counter += node.time
# if node.node == global_fra:
# return counter
# else:
# node = [a for a in res_arr if a.node == node.prev][0]
# return rec_func(node, counter, global_fra, end_switch)
# elif end_switch:
# counter += node.time
# path.append(node.node)
# if node.node == global_fra:
# return counter, path
# else:
# node = [a for a in res_arr if a.node == node.prev][0]
# return rec_func(node, counter, global_fra, end_switch)
def
rec_func2
(
node
,
global_fra
):
path
=
[]
while
node
.
node
!=
global_fra
:
...
...
@@ -109,40 +89,26 @@ def rec_func2(node, global_fra):
return
path
# def calculate_shortest_path(current_node, time, current_neighbour, slutt):
# count_a = 0
# count_a, _ = rec_func2(current_neighbour, count_a, slutt)
# count_b = 0
# count_b, _ = rec_func2(current_node, count_b, slutt)
# count_b += time
# if count_b < count_a:
# return True
# else:
# return False
# def update_que(que):
# tmp_arr = [a for a in res_arr if a.node in que]
# tmp_arr.sort(key=lambda x: x.total_time, reverse=True)
# que = [a.node for a in tmp_arr if a in tmp_arr]
# return que
end_que
=
PriorityQueue
()
queue
=
PriorityQueue
()
we_soon_to_be_done
=
False
def
dijkstras
(
slutt
,
start
):
global
we_soon_to_be_done
global
queue
node_count
=
0
while
queue
or
not
end_que
.
empty
:
node_count
+=
1
if
node_count
%
100
==
0
:
print
(
node_count
)
if
we_soon_to_be_done
:
tmp_que_item
=
end_que
.
get
()
current_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
tmp_que_item
][
0
]
else
:
tmp_que_item
=
queue
.
get
()
current_node
=
[
b
for
b
in
res_arr
if
b
.
total_time
==
tmp_que_item
and
b
.
in_que
][
0
]
if
current_node
.
total_time
==
422488
:
print
(
'
ye
'
,
node_count
)
for
tmp_edge
in
edge_arr
:
if
tmp_edge
.
fra
==
current_node
.
node
:
current_neighbour
=
[
a
for
a
in
res_arr
if
a
.
node
==
tmp_edge
.
til
][
0
]
...
...
@@ -163,12 +129,15 @@ def dijkstras(slutt, start):
elif
current_neighbour
.
node
!=
start
:
if
current_node
.
total_time
+
tmp_edge
.
time
<
current_neighbour
.
total_time
:
index_in_que
=
queue
.
queue
.
index
(
current_neighbour
.
total_time
)
old_time
=
current_neighbour
.
total_time
current_neighbour
.
total_time
=
tmp_edge
.
time
+
current_node
.
total_time
current_neighbour
.
prev
=
current_node
.
node
if
old_time
in
queue
.
queue
:
index_in_que
=
queue
.
queue
.
index
(
old_time
)
queue
.
queue
[
index_in_que
]
=
current_neighbour
.
total_time
if
we_soon_to_be_done
and
end_que
.
empty
():
print
(
'
Done mapping, calcualting result
'
)
end_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
slutt
][
0
]
travel_arr
=
rec_func2
(
end_node
,
start
)
travel_arr
=
reversed
(
travel_arr
)
...
...
@@ -178,17 +147,14 @@ def dijkstras(slutt, start):
if
i
.
total_time
!=
max_num
.
time
+
1
:
count
+=
1
print
(
'
total nodes added to map:
'
,
count
)
exit
()
break
else
:
if
we_soon_to_be_done
:
current_node
.
visited
=
True
current_node
.
in_que
=
False
dijkstras
(
slutt
,
start
)
else
:
current_node
.
visited
=
True
current_node
.
in_que
=
False
#queue = update_que(queue)
dijkstras
(
slutt
,
start
)
...
...
@@ -198,7 +164,7 @@ def init_things():
if
sys
.
argv
[
1
]
==
'
-d
'
:
#node_id
start
=
20
slutt
=
3
0
slutt
=
40
0
init_table
()
queue
.
put
(
0
)
start_node
=
next
(
a
for
a
in
res_arr
if
a
.
node
==
start
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment