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
7eb86dae
Commit
7eb86dae
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Gitlab bughunting
parent
eb0841cd
No related branches found
No related tags found
1 merge request
!89
Resolve "simple pathfinding"
Pipeline
#48893
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cooperative_cuisine/configs/agents/random_agent.py
+1
-1
1 addition, 1 deletion
cooperative_cuisine/configs/agents/random_agent.py
cooperative_cuisine/state_representation.py
+45
-47
45 additions, 47 deletions
cooperative_cuisine/state_representation.py
with
46 additions
and
48 deletions
cooperative_cuisine/configs/agents/random_agent.py
+
1
−
1
View file @
7eb86dae
...
...
@@ -34,7 +34,7 @@ def get_free_neighbours(
free_space
=
np
.
ones
((
width
,
height
),
dtype
=
bool
)
for
counter
in
state
[
"
counters
"
]:
grid_idx
=
np
.
array
(
counter
[
"
pos
"
]).
astype
(
int
)
free_space
[
*
grid_idx
]
=
False
free_space
[
grid_idx
[
0
],
grid_idx
[
1
]
]
=
False
i
,
j
=
np
.
array
(
counter_pos
).
astype
(
int
)
free
=
[]
...
...
This diff is collapsed.
Click to expand it.
cooperative_cuisine/state_representation.py
+
45
−
47
View file @
7eb86dae
...
...
@@ -13,8 +13,6 @@ from networkx import Graph
from
pydantic
import
BaseModel
from
typing_extensions
import
Literal
,
TypedDict
from
cooperative_cuisine
import
ROOT_DIR
class
OrderState
(
TypedDict
):
"""
Format of the state representation of an order.
"""
...
...
@@ -281,48 +279,48 @@ def create_json_schema() -> dict[str, Any]:
if
__name__
==
"
__main__
"
:
sample_state_path
=
ROOT_DIR
/
"
pygame_2d_vis
"
/
"
sample_state.json
"
with
open
(
sample_state_path
,
"
r
"
)
as
f
:
state
=
json
.
load
(
f
)
graph
=
create_movement_graph
(
state
,
diagonal
=
False
)
width
,
height
=
state
[
"
kitchen
"
][
"
width
"
],
state
[
"
kitchen
"
][
"
height
"
]
free_space
=
np
.
ones
((
width
,
height
),
dtype
=
bool
)
for
counter
in
state
[
"
counters
"
]:
grid_idx
=
np
.
array
(
counter
[
"
pos
"
]).
round
().
astype
(
int
)
free_space
[
*
grid_idx
]
=
False
other_players
=
[[
2
,
2
],
[
3
,
3
]]
restricted
=
restrict_movement_graph
(
graph
,
other_players
)
print
(
graph
.
nodes
)
source
=
(
1
,
1
)
target
=
(
10
,
7
)
try
:
path
=
networkx
.
astar_path
(
G
=
restricted
,
source
=
source
,
target
=
target
,
heuristic
=
astar_heuristic
)
except
networkx
.
exception
.
NetworkXNoPath
:
print
(
"
NO PATH FOUND
"
)
path
=
[]
width
,
height
=
free_space
.
shape
for
i
in
range
(
width
):
for
j
in
range
(
height
):
if
(
i
,
j
)
==
source
:
print
(
"
S
"
,
end
=
""
)
elif
(
i
,
j
)
==
target
:
print
(
"
T
"
,
end
=
""
)
elif
(
i
,
j
)
in
path
:
print
(
"
x
"
,
end
=
""
)
elif
[
i
,
j
]
in
other_players
:
print
(
"
O
"
,
end
=
""
)
elif
free_space
[
i
,
j
]:
print
(
"
"
,
end
=
""
)
else
:
print
(
"
#
"
,
end
=
""
)
print
()
#
print(json.dumps(create_json_schema()))
#
sample_state_path = ROOT_DIR / "pygame_2d_vis" / "sample_state.json"
#
with open(sample_state_path, "r") as f:
#
state = json.load(f)
#
#
graph = create_movement_graph(state, diagonal=False)
#
width, height = state["kitchen"]["width"], state["kitchen"]["height"]
#
free_space = np.ones((width, height), dtype=bool)
#
for counter in state["counters"]:
#
grid_idx = np.array(counter["pos"]).round().astype(int)
#
free_space[
grid_idx[0],
grid_idx
[1]
] = False
#
#
other_players = [[2, 2], [3, 3]]
#
restricted = restrict_movement_graph(graph, other_players)
#
#
print(graph.nodes)
#
#
source = (1, 1)
#
target = (10, 7)
#
#
try:
#
path = networkx.astar_path(
#
G=restricted, source=source, target=target, heuristic=astar_heuristic
#
)
#
except networkx.exception.NetworkXNoPath:
#
print("NO PATH FOUND")
#
path = []
#
#
width, height = free_space.shape
#
for i in range(width):
#
for j in range(height):
#
if (i, j) == source:
#
print(" S ", end="")
#
elif (i, j) == target:
#
print(" T ", end="")
#
elif (i, j) in path:
#
print(" x ", end="")
#
elif [i, j] in other_players:
#
print(" O ", end="")
#
elif free_space[i, j]:
#
print(" ", end="")
#
else:
#
print(" # ", end="")
#
print()
print
(
json
.
dumps
(
create_json_schema
()))
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