-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Round environment #48
Changes from 9 commits
dfb9dc1
ac9e493
d08a7e3
3a073dd
e61ecca
9b3e07f
c40ff66
4fde313
465e8bb
5f486f6
b990a13
768941d
12a35dc
377b298
b74d604
fdd57fd
d3359aa
8e02862
887199b
edf6d39
09f67da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Docker Login | ||
env: | ||
DOCKER_USER: ${{secrets.DOCKER_USER}} | ||
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | ||
run: | | ||
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD | ||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/scioip34abm:latest | ||
- name: Push Docker image to DockerHub | ||
run: docker push ${{secrets.DOCKER_USER}}/scioip34abm:latest |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Python package | ||
|
||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,4 +245,7 @@ cython_debug/ | |
.idea | ||
|
||
# ignore all copied env files | ||
*_copy.env | ||
*_copy.env | ||
|
||
# ignore videos | ||
*.mp4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import numpy as np | ||
import pygame | ||
|
||
from abm.contrib import movement_params | ||
|
||
|
@@ -36,3 +37,38 @@ def F_reloc_LR(vel_now, V_now, v_desired=None, theta_max=None): | |
D_leftright = left_excitation - right_excitation | ||
theta = D_leftright * theta_max | ||
return (v_desired - vel_now), theta | ||
|
||
|
||
def reflection_from_circular_wall(dx, dy, orientation): | ||
""" | ||
Calculating the reflection of the agent from the circle arena border. | ||
SEE: https://stackoverflow.com/questions/54543170/angle-reflexion-for-bouncing-ball-in-a-circle | ||
|
||
:param dx: x coordinate of the agent minus center of the circle | ||
:param dy: y coordinate of the agent minus center of the circle | ||
:param orientation: orientation of the agent | ||
:return: new orientation of the agent | ||
""" | ||
# normal vector of the circle | ||
c_norm = (pygame.math.Vector2(dx, dy)).normalize() | ||
# incident vector: the current direction vector of the bouncing agent | ||
vec_i = pygame.math.Vector2(np.cos(orientation), np.sin(orientation)) | ||
# orientation inside the circle | ||
i_orientation = np.pi + np.arctan2(vec_i[1], vec_i[0]) | ||
|
||
# reflection vector: outgoing direction vector of the bouncing agent | ||
vec_r = vec_i - 2 * c_norm.dot(vec_i) * c_norm | ||
# np.degrees(self.orientation) | ||
new_orientation = np.pi + np.arctan2(vec_r[1], vec_r[0]) | ||
|
||
# make sure that the new orientation points inside the circle and not too | ||
# flat to the border | ||
if np.abs(new_orientation - i_orientation) > np.pi / 4: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this fixes the behavior, but I am wondering why it is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess it has something to do with the curvature of the boundary and the step size per update 😅 |
||
new_orientation = i_orientation | ||
# make sure that the change of the orientation is not too big; this prevents | ||
# the agent from "jumping" over the border and other wierd behavior when the | ||
# agent changes its orientation too ofter | ||
elif np.abs(new_orientation - orientation) > np.pi / 4: | ||
new_orientation = i_orientation | ||
|
||
return new_orientation |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,24 @@ def test_random_walk(): | |
|
||
assert dvel == 1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for me random walk test fails can you please check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah it is because the env parameters, we might want to mock this so that a new local env file won't influence the test results There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is strange because all the tests in the workflow passed 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you replace the .env file (i.e. you are after running the playground tool) the tests won't pass. Or do they pass for you even with a new .env file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never had any problems with tests before or after running the playground 😅🤔 |
||
assert dtheta == -0.0752759286915825 | ||
|
||
|
||
def test_reflection_from_circular_wall(): | ||
"""Test reflection_from_circular_wall()""" | ||
|
||
new_orientation = cs_supcalc.reflection_from_circular_wall( | ||
0, 1, np.pi / 2) | ||
assert new_orientation == np.pi * 3 / 2 | ||
|
||
new_orientation = cs_supcalc.reflection_from_circular_wall( | ||
1, 0, np.pi) | ||
assert new_orientation == np.pi * 2 | ||
|
||
# test very flat reflection angle | ||
orient = np.pi + np.pi / 6 | ||
vec_i = [np.cos(orient), np.sin(orient)] | ||
# orientation inside the circle | ||
i_orientation = np.pi + np.arctan2(vec_i[1], vec_i[0]) | ||
new_orientation = cs_supcalc.reflection_from_circular_wall( | ||
0, 1, orient) | ||
assert new_orientation == i_orientation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are changing the position of the agents twice in a single time step. Once in
self.update()
and once here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this solution? b990a13