Question: 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
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 openparamsjson'
parameters json.loadf
state, money, stepcost position parameterskey for key in state 'money', 'stepcost 'position'
h w nparraystateshape
pltrcParamsfigurefigsize'w h
printmoney: formatmoney
printstep cost: formatstepcost
printposition: formatposition
ax snsheatmapstate linewidth linecolor'black', annotTrue, cmap'RdBu', cbarFalse, vmin vmax
pltxticks
pltyticks
pltshow
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
