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
6d7f8117
Commit
6d7f8117
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
koffein takk
parent
66633662
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
+22
-15
22 additions, 15 deletions
ov9/program1.py
with
22 additions
and
15 deletions
ov9/program1.py
+
22
−
15
View file @
6d7f8117
from
math
import
inf
import
sys
class
int_points
(
object
):
...
...
@@ -85,8 +84,6 @@ def rec_func(node, counter, global_fra):
return
rec_func
(
node
,
counter
,
global_fra
)
def
calculate_shortest_path
(
current_node
,
time
,
current_neighbour
,
slutt
):
print
(
'
\n
in calculate
'
)
res_a
=
[
c
for
c
in
res_arr
if
c
.
node
==
current_neighbour
.
node
][
0
]
count_a
=
0
count_a
=
rec_func
(
current_neighbour
,
count_a
,
slutt
)
count_b
=
0
...
...
@@ -105,10 +102,14 @@ def update_que(que):
que
=
[
a
.
node
for
a
in
tmp_arr
if
a
in
tmp_arr
]
return
que
end_que
=
[]
queue
=
[]
we_soon_to_be_done
=
False
def
dijkstras
(
slutt
,
fra
,
start
):
global
we_soon_to_be_done
global
queue
if
we_soon_to_be_done
:
end_que
.
pop
(
0
)
current_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
fra
][
0
]
for
tmp_edge
in
edge_arr
:
if
tmp_edge
.
fra
==
fra
:
...
...
@@ -118,8 +119,11 @@ def dijkstras(slutt, fra, start):
current_neighbour
.
prev
=
fra
if
tmp_edge
.
til
==
slutt
:
current_node
.
visited
=
True
queue
.
pop
(
0
)
dijkstras
(
slutt
,
slutt
,
start
)
we_soon_to_be_done
=
True
end_que
.
append
(
tmp_edge
.
til
)
else
:
if
tmp_edge
.
fra
==
slutt
:
end_que
.
append
(
tmp_edge
.
til
)
else
:
queue
.
append
(
tmp_edge
.
til
)
...
...
@@ -127,8 +131,7 @@ def dijkstras(slutt, fra, start):
if
calculate_shortest_path
(
current_node
,
tmp_edge
.
time
,
current_neighbour
,
start
):
current_neighbour
.
time
=
tmp_edge
.
time
current_neighbour
.
prev
=
tmp_edge
.
fra
if
fra
==
slutt
:
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
:
...
...
@@ -136,6 +139,10 @@ def dijkstras(slutt, fra, start):
print
(
i
.
node
,
i
.
time
,
i
.
prev
,
i
.
visited
)
print
(
'
que when done is:
'
,
queue
)
exit
()
else
:
if
we_soon_to_be_done
:
current_node
.
visited
=
True
dijkstras
(
slutt
,
end_que
[
0
],
start
)
else
:
queue
.
pop
(
0
)
current_node
.
visited
=
True
...
...
@@ -149,8 +156,8 @@ def init_things():
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
'
-d
'
:
#node_id
start
=
0
slutt
=
2
start
=
2
0
slutt
=
2
7
init_table
()
queue
.
append
(
start
)
start_node
=
[
a
for
a
in
res_arr
if
a
.
node
==
start
][
0
]
...
...
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