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
dc383a71
Commit
dc383a71
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
names
parent
9184f2ea
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
+32
-25
32 additions, 25 deletions
ov9/program1.py
with
32 additions
and
25 deletions
ov9/program1.py
+
32
−
25
View file @
dc383a71
...
...
@@ -47,7 +47,7 @@ with open('./test_files/kanter.txt','r') as file:
edge_file
=
file
.
read
()
edge_file
=
edge_file
.
split
()
num_of_edges
=
edge_file
[
0
]
num_of_edges
=
int
(
edge_file
[
0
]
)
edge_file
.
pop
(
0
)
edge_arr
=
[]
...
...
@@ -60,7 +60,7 @@ with open('./test_files/interessepkt.txt','r') as file:
intresting_file
=
file
.
read
()
intresting_file
=
intresting_file
.
split
(
'
\n
'
)
num_of_intresting
=
intresting_file
[
0
]
num_of_intresting
=
int
(
intresting_file
[
0
]
)
intresting_file
.
pop
(
0
)
intresting_arr
=
[]
...
...
@@ -84,6 +84,8 @@ def rec_func(node, counter, global_fra):
def
calculate_shortest_path
(
b
,
i
,
a
,
global_fra
):
print
(
'
in calculate
'
)
res_a
=
[
a
for
a
in
res_arr
if
a
==
a
.
node
]
print
(
f
'
curr_node:
{
b
.
node
}
, edge_time:
{
i
}
, curr_neig_node:
{
a
.
node
}
, curr_neig_prev:
{
a
.
prev
}
, global_fra:
{
global_fra
}
'
)
count_a
=
0
count_a
=
rec_func
(
a
,
count_a
,
global_fra
)
count_b
=
0
...
...
@@ -95,10 +97,12 @@ def calculate_shortest_path(b, i, a, global_fra):
return
False
round
=
0
queue
=
[]
def
dijkstras
(
global_fra
,
fra
,
til
):
print
(
queue
)
def
dijkstras
(
slutt
,
fra
,
start
):
global
round
round
+=
1
print
(
'
runde:
'
,
round
,
'
queue:
'
,
queue
)
current_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
fra
][
0
]
print
(
current_node
.
node
)
for
tmp_edge
in
edge_arr
:
...
...
@@ -107,33 +111,36 @@ def dijkstras(global_fra, fra, til):
if
current_neighbour
:
if
current_neighbour
.
visited
==
False
:
print
(
f
'
fra:
{
fra
}
, a:
{
current_neighbour
.
visited
}
, til
{
tmp_edge
.
til
}
'
)
if
global_fra
==
fra
:
if
start
==
fra
:
if
tmp_edge
.
time
<
current_neighbour
.
time
:
current_neighbour
.
time
=
tmp_edge
.
time
current_neighbour
.
prev
=
fra
if
tmp_edge
.
til
not
in
queue
:
if
tmp_edge
.
til
==
til
:
if
tmp_edge
.
til
==
slutt
:
current_node
.
visited
=
True
queue
.
pop
(
0
)
dijkstras
(
global_fra
,
til
,
til
)
dijkstras
(
start
,
slutt
,
slutt
)
else
:
queue
.
append
(
tmp_edge
.
til
)
elif
current_neighbour
.
visited
==
True
and
current_neighbour
.
node
!=
global_fra
:
if
calculate_shortest_path
(
current_node
,
tmp_edge
.
time
,
current_neighbour
,
global_fra
):
elif
current_neighbour
.
visited
==
True
and
current_neighbour
.
node
!=
start
:
print
(
current_node
.
node
,
tmp_edge
.
time
,
current_neighbour
.
node
,
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
==
til
:
if
fra
==
slutt
:
#not finished
print
(
'
sho
'
)
for
i
in
res_arr
:
if
i
.
time
!=
inf
:
print
(
i
.
node
,
i
.
time
,
i
.
prev
,
i
.
visited
)
exit
()
else
:
queue
.
pop
(
0
)
current_node
.
visited
=
True
dijkstras
(
global_fra
,
queue
[
0
],
til
)
dijkstras
(
start
,
queue
[
0
],
slutt
)
...
...
@@ -144,13 +151,13 @@ def init_things():
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
'
-d
'
:
#node_id
fra
=
0
til
=
1
start
=
0
slutt
=
2
init_table
()
queue
.
append
(
fra
)
a_
start_node
=
[
a
for
a
in
res_arr
if
a
.
node
==
fra
][
0
]
a_
start_node
.
time
=
0
dijkstras
(
fra
,
fra
,
til
)
queue
.
append
(
start
)
start_node
=
[
a
for
a
in
res_arr
if
a
.
node
==
slutt
][
0
]
start_node
.
time
=
0
dijkstras
(
slutt
,
start
,
start
)
elif
sys
.
argv
[
1
]
==
'
-a
'
:
print
(
'
A* not yet implemented
'
)
else
:
...
...
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