Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
f10136c6
Commit
f10136c6
authored
1 year ago
by
fheinrich
Browse files
Options
Downloads
Patches
Plain Diff
Fix reference only usage of graph, needed copy.
parent
7e2b9783
No related branches found
No related tags found
1 merge request
!89
Resolve "simple pathfinding"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cooperative_cuisine/configs/agents/random_agent.py
+38
-25
38 additions, 25 deletions
cooperative_cuisine/configs/agents/random_agent.py
cooperative_cuisine/state_representation.py
+2
-1
2 additions, 1 deletion
cooperative_cuisine/state_representation.py
with
40 additions
and
26 deletions
cooperative_cuisine/configs/agents/random_agent.py
+
38
−
25
View file @
f10136c6
...
...
@@ -22,6 +22,8 @@ from cooperative_cuisine.utils import custom_asdict_factory
TIME_TO_STOP_ACTION
=
3.0
ADD_RANDOM_MOVEMENTS
=
True
def
get_free_neighbours
(
state
:
dict
,
counter_pos
:
list
[
float
]
|
tuple
[
float
,
float
]
|
npt
.
NDArray
...
...
@@ -49,7 +51,7 @@ async def agent():
args
=
parser
.
parse_args
()
async
with
connect
(
args
.
uri
)
as
websocket
:
async
with
(
connect
(
args
.
uri
)
as
websocket
)
:
await
websocket
.
send
(
json
.
dumps
({
"
type
"
:
"
ready
"
,
"
player_hash
"
:
args
.
player_hash
})
)
...
...
@@ -58,6 +60,7 @@ async def agent():
ended
=
False
counters
=
None
all_counters
=
None
movement_graph
=
None
...
...
@@ -89,10 +92,12 @@ async def agent():
if
movement_graph
is
None
:
movement_graph
=
create_movement_graph
(
state
,
diagonal
=
True
)
if
counters
is
None
:
counters
=
defaultdict
(
list
)
for
counter
in
state
[
"
counters
"
]:
counters
[
counter
[
"
type
"
]].
append
(
counter
)
all_counters
=
state
[
"
counters
"
]
for
player
in
state
[
"
players
"
]:
if
player
[
"
id
"
]
==
args
.
player_id
:
...
...
@@ -166,7 +171,7 @@ async def agent():
for
free
in
target_free_spaces
:
try
:
modified_graph
=
restrict_movement_graph
(
graph
=
movement_graph
,
graph
=
movement_graph
.
copy
()
,
player_positions
=
[
p
[
"
pos
"
]
for
p
in
state
[
"
players
"
]
...
...
@@ -195,29 +200,32 @@ async def agent():
movement
=
node_diff
/
node_dist
else
:
movement
=
target_diff
/
target_dist
do_movement
=
True
else
:
movement
=
np
.
array
([
0
,
0
])
task_type
=
None
task_args
=
None
# no paths available
# task_type = None
# task_args = None
do_movement
=
False
if
target_dist
>
1.2
:
if
target_dist
>
1.2
and
do_movement
:
if
target_dist
!=
0
:
# random_small_rotation_angle = (
# np.random.random() * np.pi * 0.1
# )
# rotation_matrix = np.array(
# [
# [
# np.cos(random_small_rotation_angle),
# -np.sin(random_small_rotation_angle),
# ],
# [
# np.sin(random_small_rotation_angle),
# np.cos(random_small_rotation_angle),
# ],
# ]
# )
# movement = rotation_matrix @ movement
if
ADD_RANDOM_MOVEMENTS
:
random_small_rotation_angle
=
(
np
.
random
.
random
()
*
np
.
pi
*
0.1
)
rotation_matrix
=
np
.
array
(
[
[
np
.
cos
(
random_small_rotation_angle
),
-
np
.
sin
(
random_small_rotation_angle
),
],
[
np
.
sin
(
random_small_rotation_angle
),
np
.
cos
(
random_small_rotation_angle
),
],
]
)
movement
=
rotation_matrix
@
movement
await
websocket
.
send
(
json
.
dumps
(
...
...
@@ -238,6 +246,7 @@ async def agent():
)
await
websocket
.
recv
()
else
:
# Target reached here.
task_type
=
None
task_args
=
None
case
"
INTERACT
"
:
...
...
@@ -299,9 +308,13 @@ async def agent():
# task_type = random.choice(["GOTO", "PUT", "INTERACT"])
threshold
=
datetime
.
now
()
+
timedelta
(
seconds
=
TIME_TO_STOP_ACTION
)
if
task_type
==
"
GOTO
"
:
counter_type
=
random
.
choice
(
list
(
counters
.
keys
()))
task_args
=
random
.
choice
(
counters
[
counter_type
])[
"
pos
"
]
print
(
args
.
player_hash
,
args
.
player_id
,
task_type
,
counter_type
)
# counter_type = random.choice(list(counters.keys()))
# task_args = random.choice(counters[counter_type])["pos"]
random_counter
=
random
.
choice
(
all_counters
)
counter_type
=
random_counter
[
"
type
"
]
task_args
=
random_counter
[
"
pos
"
]
print
(
args
.
player_hash
,
args
.
player_id
,
task_type
,
counter_type
,
task_args
)
else
:
print
(
args
.
player_hash
,
args
.
player_id
,
task_type
)
task_args
=
None
...
...
This diff is collapsed.
Click to expand it.
cooperative_cuisine/state_representation.py
+
2
−
1
View file @
f10136c6
...
...
@@ -193,7 +193,8 @@ class StateRepresentation(BaseModel):
def
astar_heuristic
(
x
,
y
):
return
np
.
linalg
.
norm
(
np
.
array
(
list
(
x
))
-
np
.
array
((
y
)))
"""
Heuristic distance function used in astart algorithm.
"""
return
np
.
linalg
.
norm
(
np
.
array
(
x
)
-
np
.
array
(
y
))
def
create_movement_graph
(
state
:
StateRepresentation
,
diagonal
=
True
)
->
Graph
:
...
...
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