Question: Wanting a code as an answer: Using AgentPy Provide the code proposed for modeling an agent in a room. Consider the following rules: Environment: A
Wanting a code as an answer: Using AgentPy Provide the code proposed for modeling an agent in a room. Consider the following rules:
Environment:
A room is a rectangle, arranged in cells, with m
rows and
n columns.
A cell can contain a reward
negative value
or a penalty
positive value
As the robot passes over the cell, it collects and removes the item it contains.
Agent:
A robot can obtain the information of each cell in the room using a coordinate system
row
column
The robot takes
unit of time to travel from one cell to any neighboring cell
up
down
right or left
The robot spends
unit of energy to travel from one cell to any neighboring cell.
The robot's energy is modified according to the values
given in each cell.
The robot stops if there are no more cells with rewards or if its energy runs out.
Actions
Design the robot's behavior according to the following rules, considering the updated information:
The robot moves randomly in the room.
The robot selects the cell with the highest reward and traces a route to collect it
The robot searches for the nearest cell with a reward and traces a route to collect it
Add some graphs to visualize The answer
Parameters in
json:
money
:
position
:
step
cost
:
state
:
ParameterViewer:
import json, numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
# Reading information from files
f
open
params
json'
parameters
jsonload
f
state, money, step
cost
position
parameters
key
for key in
state
money 'step
cost
position
h
w
np
array
state
shape
plt
rcParams
figure
figsize'
w
h
print
money:
format
money
print
step cost:
format
step
cost
print
position:
format
position
ax
sns
heatmap
state
linewidth
linecolor
'black', annot
True, cmap
'RdBu', cbar
False, vmin
vmax
plt
xticks
plt
yticks
plt
show
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
