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
1bbe3280
Commit
1bbe3280
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
KJØR
parent
6d7f8117
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
+28
-14
28 additions, 14 deletions
ov9/program1.py
with
28 additions
and
14 deletions
ov9/program1.py
+
28
−
14
View file @
1bbe3280
...
...
@@ -75,19 +75,32 @@ def init_table():
for
i
in
range
(
num_of_nodes
):
res_arr
.
append
(
results
(
i
,
max_num
.
time
+
1
,
False
,
None
))
def
rec_func
(
node
,
counter
,
global_fra
):
path
=
[]
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
)
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
calculate_shortest_path
(
current_node
,
time
,
current_neighbour
,
slutt
):
end_switch
=
False
count_a
=
0
count_a
=
rec_func
(
current_neighbour
,
count_a
,
slutt
)
count_a
=
rec_func
(
current_neighbour
,
count_a
,
slutt
,
end_switch
)
count_b
=
0
count_b
=
rec_func
(
current_node
,
count_b
,
slutt
)
count_b
=
rec_func
(
current_node
,
count_b
,
slutt
,
end_switch
)
count_b
+=
time
if
count_b
<
count_a
:
return
True
...
...
@@ -133,11 +146,12 @@ def dijkstras(slutt, fra, start):
current_neighbour
.
prev
=
tmp_edge
.
fra
if
we_soon_to_be_done
and
not
len
(
end_que
):
#not finished
print
(
'
ferdig, resultater er: node, tid, prev, besøkt
'
)
for
i
in
res_arr
:
if
i
.
time
!=
max_num
.
time
+
1
:
print
(
i
.
node
,
i
.
time
,
i
.
prev
,
i
.
visited
)
print
(
'
que when done is:
'
,
queue
)
end_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
slutt
][
0
]
total_time
=
0
end_switch
=
True
total_time
,
travel_arr
=
rec_func
(
end_node
,
total_time
,
start
,
end_switch
)
travel_arr
=
reversed
(
travel_arr
)
print
(
f
'
total time:
{
total_time
}
\n
shortest path:
{
"
->
"
.
join
(
str
(
v
)
for
v
in
travel_arr
)
}
'
)
exit
()
else
:
if
we_soon_to_be_done
:
...
...
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