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
e1556185
Commit
e1556185
authored
3 years ago
by
Jacob Theisen
Browse files
Options
Downloads
Patches
Plain Diff
kjør
parent
77408618
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
+20
-31
20 additions, 31 deletions
ov9/program1.py
with
20 additions
and
31 deletions
ov9/program1.py
+
20
−
31
View file @
e1556185
...
...
@@ -69,26 +69,24 @@ for i in range(len(intresting_file)):
tmp_values
=
intresting_file
[
i
].
split
()
intresting_arr
.
append
(
int_points
(
int
(
tmp_values
[
0
]),
int
(
tmp_values
[
1
]),
'
'
.
join
(
tmp_values
[
2
:])))
max_num
=
max
(
edge_arr
,
key
=
lambda
item
:
item
.
time
)
res_arr
=
[]
def
init_table
():
for
i
in
range
(
num_of_nodes
):
res_arr
.
append
(
results
(
i
,
inf
,
False
,
None
))
res_arr
.
append
(
results
(
i
,
max_num
.
time
+
1
,
False
,
None
))
def
rec_func
(
node
,
counter
,
global_fra
):
print
(
'
in recfunc
'
)
counter
+=
node
.
time
print
(
f
'
node:
{
node
.
node
}
, node_time:
{
node
.
time
}
, time_count:
{
counter
}
'
)
if
node
.
node
==
global_fra
:
return
counter
else
:
print
(
node
.
prev
)
node
=
[
a
for
a
in
res_arr
if
a
.
node
==
node
.
prev
][
0
]
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
]
print
(
f
'
curr_node:
{
current_node
.
node
}
, edge_time:
{
time
}
, curr_neig_node:
{
current_neighbour
.
node
}
, curr_neig_prev:
{
current_neighbour
.
prev
}
, dist to curr_neig:
{
res_a
.
time
}
, global_fra:
{
slutt
}
'
)
count_a
=
0
count_a
=
rec_func
(
current_neighbour
,
count_a
,
slutt
)
count_b
=
0
...
...
@@ -100,24 +98,16 @@ def calculate_shortest_path(current_node, time, current_neighbour, slutt):
return
False
round
=
0
queue
=
[]
def
dijkstras
(
slutt
,
fra
,
start
):
global
round
round
+=
1
print
(
'
runde:
'
,
round
,
'
queue:
'
,
queue
,
'
start:
'
,
start
)
current_node
=
[
b
for
b
in
res_arr
if
b
.
node
==
fra
][
0
]
print
(
current_node
.
node
)
for
tmp_edge
in
edge_arr
:
if
tmp_edge
.
fra
==
fra
:
current_neighbour
=
[
a
for
a
in
res_arr
if
a
.
node
==
tmp_edge
.
til
][
0
]
if
current_neighbour
.
visited
==
False
:
print
(
f
'
fra:
{
fra
}
, a:
{
current_neighbour
.
visited
}
, til
{
tmp_edge
.
til
}
'
)
if
start
==
fra
:
if
tmp_edge
.
time
<
current_neighbour
.
time
:
if
current_neighbour
.
visited
==
False
and
current_neighbour
.
node
not
in
queue
:
current_neighbour
.
time
=
tmp_edge
.
time
current_neighbour
.
prev
=
fra
if
tmp_edge
.
til
not
in
queue
:
if
tmp_edge
.
til
==
slutt
:
current_node
.
visited
=
True
queue
.
pop
(
0
)
...
...
@@ -125,17 +115,16 @@ def dijkstras(slutt, fra, start):
else
:
queue
.
append
(
tmp_edge
.
til
)
elif
current_neighbour
.
visited
==
True
and
current_neighbour
.
node
!=
start
:
print
(
current_node
.
node
,
tmp_edge
.
time
,
current_neighbour
.
node
,
start
)
elif
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
==
slutt
:
#not finished
print
(
'
sho
'
)
print
(
'
ferdig, resultater er: node, tid, prev, besøkt
'
)
for
i
in
res_arr
:
if
i
.
time
!=
inf
:
if
i
.
time
!=
max_num
.
time
+
1
:
print
(
i
.
node
,
i
.
time
,
i
.
prev
,
i
.
visited
)
exit
()
...
...
@@ -157,8 +146,8 @@ def init_things():
slutt
=
2
init_table
()
queue
.
append
(
start
)
start_node
=
[
a
for
a
in
res_arr
if
a
.
node
==
s
lut
t
][
0
]
start_node
.
time
=
0
start_node
=
[
a
for
a
in
res_arr
if
a
.
node
==
s
tar
t
][
0
]
start_node
.
time
=
1
dijkstras
(
slutt
,
start
,
start
)
elif
sys
.
argv
[
1
]
==
'
-a
'
:
print
(
'
A* not yet implemented
'
)
...
...
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