Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mesterseges Intelligencia HF01
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Cseh Viktor
Mesterseges Intelligencia HF01
Commits
7264e199
Commit
7264e199
authored
Oct 11, 2021
by
Cseh Viktor
Browse files
Options
Downloads
Patches
Plain Diff
Vegre keszvan 12 pontra ez a fos
parent
d45db2c0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
GG2DP5_hf01.zip
+0
-0
0 additions, 0 deletions
GG2DP5_hf01.zip
input
+6
-1
6 additions, 1 deletion
input
mi_GG2DP5_hf1.py
+46
-58
46 additions, 58 deletions
mi_GG2DP5_hf1.py
with
52 additions
and
59 deletions
GG2DP5_hf01.zip
+
0
−
0
View file @
7264e199
No preview for this file type
This diff is collapsed.
Click to expand it.
input
+
6
−
1
View file @
7264e199
...
...
@@ -15,3 +15,8 @@ route_between_points
1 0
1 2
0 2
input3 rossz 2db, majd jo kimenete:
380.42 84.85 118.79 67.88 106.07
380.42 465.28 543.06 272.94 364.87
316.85 368.61 442.56 237.84 325.31
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mi_GG2DP5_hf1.py
+
46
−
58
View file @
7264e199
#########################################
# Keszitette Cseh Viktor - GG2DP5 #
# 2021.10.
08
#
# 2021.10.
11
#
#########################################
#import sys
import
math
##### Global variables #####
...
...
@@ -15,73 +14,63 @@ route_between_points = []
route
=
[]
calculated_lengths
=
[]
distance
=
[]
notseenpoints
=
[]
verticles
=
[]
##### Global functions #####
def
dijkstra
(
a
,
b
):
if
(
a
==
b
):
# Ekkor elertuk a keresett pontot
calculated_lengths
.
append
(
distance
[
b
])
return
##### Classes #####
for
i
in
range
(
0
,
len
(
route_between_points
),
2
):
# iteralni a route_between_points-on, hogy az == e a meghivottal es kiszamolni a szomszedokhoz tartozo utat, ami esetleg legrovidebb lehet
if
(
route_between_points
[
i
]
==
a
):
length
=
calc_route_length
(
route_between_points
[
i
],
route_between_points
[
i
+
1
])
## Ebben fogjuk majd tarolni a graf pontjaihoz tartozo adatokat
class
vertice
:
def
__init__
(
self
,
name
,
x
,
y
,
neighbours
):
self
.
name
=
name
self
.
x
=
x
self
.
y
=
y
self
.
neighbours
=
neighbours
self
.
distance
=
math
.
inf
if
(
length
+
distance
[
a
]
<
distance
[
route_between_points
[
i
+
1
]]):
# ha kisebb az eddig tudott utvonalnal a most talalt, akkor cserelje ki arra
distance
[
route_between_points
[
i
+
1
]]
=
length
+
distance
[
a
]
##### Global functions #####
elif
(
route_between_points
[
i
+
1
]
==
a
):
length
=
calc_route_length
(
route_between_points
[
i
],
route_between_points
[
i
+
1
])
## Neve megteveszto, mert ez nem az egesz dijkstra algoritmus, csak a szomszedokat kiszamolo resze.
## Amikor az egesz algoritmus itt volt, akkor a csodalatos hf.mit.bme.hu ellenorzo rendszer panaszkodott,
## hogy tul nagy a rekurzio melysege, igy fail-elt a leadas.....
def
dijkstra
(
a
,
b
,
notseenpoints
):
if
(
a
.
name
==
b
):
calculated_lengths
.
append
(
a
.
distance
)
return
if
(
length
+
distance
[
a
]
<
distance
[
route_between_points
[
i
]]):
distance
[
route_between_points
[
i
]]
=
length
+
distance
[
a
]
for
i
in
a
.
neighbours
:
lenght
=
calc_route_length
(
a
,
verticles
[
i
])
if
(
lenght
+
a
.
distance
<
verticles
[
i
].
distance
):
verticles
[
i
].
distance
=
a
.
distance
+
lenght
## Ez lenne a dijkstra masodik resze, ami az elozo vegere ment volna kb
def
route_search
():
notseenpoints
=
[]
# minden kiszamolando ut, minden kovetkezo legkisebb eleresi utu pontjara meghivja a szomszedok tavolsaganak a kiszamolasat
for
x
in
range
(
0
,
len
(
route_to_calc
),
2
):
for
i
in
range
(
map_config
[
1
]):
if
(
i
==
route_to_calc
[
x
]):
distance
.
append
(
0
)
verticles
[
i
].
distance
=
0
else
:
distance
.
append
(
math
.
inf
)
notseenpoints
.
append
(
i
)
verticles
[
i
].
distance
=
math
.
inf
notseenpoints
.
append
(
verticles
[
i
]
)
while
(
len
(
notseenpoints
)
!=
0
):
minimum_distance
=
math
.
inf
corresponding_point
=
None
cntr
=
0
for
i
in
range
(
len
(
notseenpoints
)):
if
(
distance
[
notseenpoints
[
i
]]
!=
None
):
#Meghivni ra a dijkstra algoritmust rekurzivan, ha mar szamoltuk, de ne jartunk meg benne
if
(
distance
[
notseenpoints
[
i
]]
<
minimum_distance
):
# Es legkisebb a tavolsaga eddig
cntr
+=
1
minimum_distance
=
distance
[
notseenpoints
[
i
]]
corresponding_point
=
notseenpoints
[
i
]
if
(
cntr
>
0
):
notseenpoints
.
remove
(
corresponding_point
)
dijkstra
(
corresponding_point
,
route_to_calc
[
x
+
1
])
distance
.
clear
()
notseenpoints
.
clear
()
def
calc_route_length
(
a
,
b
):
# X koordinata lekerese es szamolasa a pitagorasz tetelhez
x1
=
int
(
point_coordinates
[
a
*
2
])
notseenpoints
=
sorted
(
notseenpoints
,
key
=
lambda
verticle
:
verticle
.
distance
)
x2
=
int
(
point_coordinates
[
b
*
2
])
dijkstra
(
notseenpoints
[
0
],
route_to_calc
[
x
+
1
],
notseenpoints
)
notseenpoints
.
clear
()
x
=
abs
(
x1
-
x2
)
# Y koordinata lekerese es szamolasa a pitagorasz tetelhez
def
calc_route_length
(
a
,
b
):
# X tavolsag szamolasa pitagorasz tetelhez
y1
=
int
(
point_coordinates
[
a
*
2
+
1
]
)
x
=
abs
(
int
(
a
.
x
)
-
int
(
b
.
x
)
)
y2
=
int
(
point_coordinates
[
b
*
2
+
1
])
# Y tavolsag szamolasa pitagorasz tetelhez
y
=
abs
(
y1
-
y2
)
y
=
abs
(
a
.
y
-
b
.
y
)
# Pitagorasz tetel
...
...
@@ -111,6 +100,8 @@ def read_from_input():
point_coordinates
.
append
(
int
(
arr
[
0
],
10
))
point_coordinates
.
append
(
int
(
arr
[
1
],
10
))
temp
=
vertice
(
i
,
int
(
arr
[
0
],
10
),
int
(
arr
[
1
],
10
),
neighbours
=
[])
verticles
.
append
(
temp
)
x
=
input
()
...
...
@@ -120,6 +111,8 @@ def read_from_input():
route_between_points
.
append
(
int
(
arr
[
0
],
10
))
route_between_points
.
append
(
int
(
arr
[
1
],
10
))
verticles
[
int
(
arr
[
0
],
10
)].
neighbours
.
append
(
int
(
arr
[
1
],
10
))
verticles
[
int
(
arr
[
1
],
10
)].
neighbours
.
append
(
int
(
arr
[
0
],
10
))
def
output_lengths
():
output
=
""
...
...
@@ -135,12 +128,7 @@ def main():
read_from_input
()
route_search
()
output_lengths
()
#print(map_config, file=sys.stderr)
#print(route_to_calc, file=sys.stderr)
#print(point_coordinates, file=sys.stderr)
#print(route_between_points, file=sys.stderr)
#print("almafa")
#print("***" + map_config[0] + "***", file=sys.stderr)
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
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