Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataScienceSWP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
phwitte
DataScienceSWP
Commits
56206752
Commit
56206752
authored
7 years ago
by
markr
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
7c211de4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Final/python files/help_functions.py
+72
-0
72 additions, 0 deletions
Final/python files/help_functions.py
with
72 additions
and
0 deletions
Final/python files/help_functions.py
0 → 100644
+
72
−
0
View file @
56206752
import
math
import
numpy
as
np
# -------------------------------------------------------------------
# help functions
# Distance function betwen points xi, yi and xii,yii
def
distance
(
xi
,
xii
,
yi
,
yii
):
sq1
=
(
xi
-
xii
)
*
(
xi
-
xii
)
sq2
=
(
yi
-
yii
)
*
(
yi
-
yii
)
return
math
.
sqrt
(
sq1
+
sq2
)
# absolute value of a two dimensional vector
def
absvec
(
a
,
b
):
absV
=
math
.
sqrt
(
a
*
a
+
b
*
b
)
if
absV
==
0
:
absV
=
0.001
return
absV
# angle between two vector´s in degrees
def
calc_angle
(
x1
,
y1
,
x2
,
y2
):
skalar
=
x1
*
x2
+
y1
*
y2
abs1
=
absvec
(
x1
,
y1
)
abs2
=
absvec
(
x2
,
y2
)
erg
=
skalar
/
(
abs1
*
abs2
)
if
erg
>
1
:
erg
=
1
elif
erg
<
-
1
:
erg
=
-
1
return
math
.
degrees
(
math
.
acos
(
erg
))
# find nearest neighbour of a given Agent
def
nearest_neighbour
(
agent
,
agents
):
minDis
=
float
(
'
inf
'
)
nearestNeighbour
=
None
for
neighbour
in
agents
:
if
(
agent
==
neighbour
):
True
elif
(
nearestNeighbour
==
None
):
nearestNeighbour
=
neighbour
else
:
dis
=
distance
(
agent
.
point
.
getX
(),
neighbour
.
point
.
getX
(),
agent
.
point
.
getY
(),
neighbour
.
point
.
getY
())
if
(
dis
<
minDis
):
minDis
=
dis
nearestNeighbour
=
neighbour
return
nearestNeighbour
# --------------------------------------------------
# used to plot
def
avgdistancetoall
(
agent
,
agents
):
i
=
0
totaldistance
=
0
for
i
in
range
(
len
(
agents
)):
if
agents
[
i
]
==
agent
:
True
else
:
totaldistance
+=
distance
(
agent
.
point
.
getX
(),
agent
.
point
.
getY
(),
agents
[
i
].
point
.
getX
(),
agents
[
i
].
point
.
getY
())
avgdistance
=
totaldistance
/
i
return
avgdistance
def
totalavgdistance
(
agents
,
numplist
):
for
agent
in
agents
:
numplist
=
np
.
append
(
numplist
,
avgdistancetoall
(
agent
,
agents
))
return
numplist
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