text
stringlengths 2.42k
4.01k
|
---|
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '^', '^', '^', '*', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '^', '^', '^', '*', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', '*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', '*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', 'O', 'O', '.', 'O', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', 'O', 'O', '.', 'O', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '@', '@', '.', '.', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '@', '@', '.', '.', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', 'O', '.', 'O', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', 'O', '.', 'O', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '~', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '~', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '~', '-', '-', '~', '-', '~'],
['~', '-', '-', '-', '~', '-', '~', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '~', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '~', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '~', '-', '-', '~', '-', '~'],
['~', '-', '-', '-', '~', '-', '~', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', '~', '~'],
['~', '~', '~', ' ', '~', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', '~', ' ', ' ', '~', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', '~', ' ', ' ', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', '~', '~'],
['~', '~', '~', ' ', '~', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', '~', ' ', ' ', '~', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', '~', ' ', ' ', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '^', '*', '^', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '*', '^', '^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '^', '*', '^', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '*', '^', '^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '.', '@', '@', '@', '.', '@', '.', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '@', '@', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '@', '.', '@', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '.', '@', '@', '@', '.', '@', '.', '@'],
['@', '@', '.', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '@', '@', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '@', '.', '@', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '@', '@', '@', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '@', '@', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '.', '.', '@', '.', '@'],
['@', '.', '@', '@', '.', '@', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '@', '@', '@', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '@', '@', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '.', '.', '@', '.', '@'],
['@', '.', '@', '@', '.', '@', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', '*'],
['*', '*', '*', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', '*'],
['*', '*', '*', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '~', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '~', '~', '-', '~', '~'],
['~', '-', '~', '-', '-', '~', '~', '-', '-', '-', '-', '~', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '~', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '~', '~', '-', '~', '~'],
['~', '-', '~', '-', '-', '~', '~', '-', '-', '-', '-', '~', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', 'O', '.', '.', 'O', '.', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', 'O', '.', '.', 'O', '.', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', 'O', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', 'O', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', 'O', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', 'O', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', '~', '~', ' ', '~', '~', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', '~', '~', ' ', '~', '~', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '@', '.', '@'],
['@', '@', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '@', '.', '@'],
['@', '@', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '~', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '-', '-', '-', '~', '~', '~', '~'],
['~', '~', '-', '-', '~', '~', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '~', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '-', '-', '-', '~', '~', '~', '~'],
['~', '~', '-', '-', '~', '~', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '|', '_', '|'],
['|', '|', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '|', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '|', '_', '|'],
['|', '_', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '|', '_', '|'],
['|', '|', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '|', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '|', '_', '|'],
['|', '_', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', '.', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', 'O', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', ' ', '~', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', ' ', '~', '~', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '^', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '^', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', '~', ' ', '~', '~', ' ', ' ', ' ', '~', ' ', '~', '~'],
['~', ' ', '~', '~', '~', ' ', '~', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', '~', ' ', '~', ' ', ' ', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', '~', ' ', '~', '~', ' ', ' ', ' ', '~', ' ', '~', '~'],
['~', ' ', '~', '~', '~', ' ', '~', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', '~', ' ', '~', ' ', ' ', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', 'O', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', 'O', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', 'O', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', 'O', 'O', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '*', '^', '^', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '^', '^', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '*', '*', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '^', '*', '*', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '*', '^', '^', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '^', '^', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '*', '*', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '^', '*', '*', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~'],
['~', '~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', '~', '~', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~'],
['~', '~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', '~', '~', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', '~', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', '~', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', '~', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', 'O', 'O', 'O', '.', 'O', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', 'O', 'O', 'O', '.', 'O', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', '*', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', '*', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '.', '.', '.', '@', '.', '@', '@'],
['@', '@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '@', '.', '.', '.', '.', '@', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '.', '.', '.', '@', '.', '@', '@'],
['@', '@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '@', '.', '.', '.', '.', '@', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '*', '^', '^', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '*', '^', '*', '^', '^', '*', '*', '*', '*', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '*', '^', '^', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '*', '^', '*', '^', '^', '*', '*', '*', '*', '*', '^'],
['^', '^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '_', '_', '_', '|', '|', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '|', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '_', '|', '_', '|', '_', '_', '_', '|'],
['|', '|', '_', '|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '|', '_', '|', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '_', '_', '_', '|', '|', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '|', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '|', '_', '|', '_', '|', '_', '_', '_', '|'],
['|', '|', '_', '|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '|', '_', '|', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', '*', '*', ' ', '*', ' ', ' ', '*', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', '*', '*', ' ', '*', ' ', ' ', '*', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '^', '^', '*', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '^', '^', '*', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '*', '*', '^', '*', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@', '@', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '@', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '.', '.', '@', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '@', '@', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '.', '.', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@', '@', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '.', '@', '@'],
['@', '.', '@', '.', '.', '@', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '.', '.', '@', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '@', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '@', '@', '.', '.', '@', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '.', '.', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', '~', '~', '~', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', '~', '~', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', '~', '~', '~', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', '~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '|', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '|', '_', '_', '_', '_', '|', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '|', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '|', '_', '_', '_', '_', '|', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '~', '~', '~', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '~', '-', '-', '-', '~', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '~', '~', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '~', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '~', '~', '~', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '~', '-', '-', '-', '~', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '-', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '~', '~', '~', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '^', '^', '*', '^'],
['^', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '^', '^', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '^', '^', '*', '^'],
['^', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '^', '^', '*', '*', '^', '*', '^'],
['^', '^', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '_', '|', '_', '_', '|', '_', '|'],
['|', '|', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '|'],
['|', '_', '_', '_', '_', '|', '_', '|', '_', '|'],
['|', '_', '|', '|', '_', '|', '|', '_', '_', '|'],
['|', '|', '_', '|', '_', '|', '|', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '_', '|', '_', '_', '|', '_', '|'],
['|', '|', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '|'],
['|', '_', '_', '_', '_', '|', '_', '|', '_', '|'],
['|', '_', '|', '|', '_', '|', '|', '_', '_', '|'],
['|', '|', '_', '|', '_', '|', '|', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '|', '_', '|', '_', '|', '|', '|', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '|', '|', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '|', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '_', '_', '|', '|', '_', '_', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '|', '_', '|', '_', '|', '|', '|', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '|', '|', '_', '_', '_', '|'],
['|', '_', '_', '|', '_', '_', '|', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '_', '_', '|', '|', '_', '_', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '*', '^', '*', '^', '^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '^', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '*', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '*', '^', '*', '^', '^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '^', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '^', '^'],
['^', '^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '*', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', 'O', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', 'O', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', '*', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '^'],
['^', '^', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '^'],
['^', '^', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '^', '^'],
['^', '^', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', '~'],
['~', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', '~', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', '~'],
['~', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', ' ', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', '~', '~', '~', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', '.', 'O', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', 'O', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', 'O', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '@', '@', '@', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '@', '@', '@', '.', '@'],
['@', '@', '@', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '^', '^', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '^', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '^', '^', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '^', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '^', '^', '*', '*', '^', '^', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '^', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '*', '*', '^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '^', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '^', '^', '*', '*', '^', '^', '*', '^'],
['^', '^', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '^', '*', '*', '^', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '^', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '*', '*', '^', '^', '*', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '^', '^', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '@', '.', '@', '@', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '@', '@', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '@', '.', '@', '@', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '@', '.', '@', '@', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '@', '.', '.', '@'],
['@', '.', '@', '.', '@', '.', '.', '@', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '|', '_', '_', '|', '|', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '|', '_', '|', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '|', '|', '|', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '|', '_', '|', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '|', '_', '_', '|', '|', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '|', '_', '|', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '|', '|', '|', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '|', '_', '_', '|'],
['|', '_', '|', '|', '_', '_', '_', '|', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '|', '_', '|', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', ' ', '*', '*', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', ' ', '*', '*', ' ', ' ', '*'],
['*', ' ', '*', '*', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '@', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '@', '.', '@', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '@', '@', '.', '.', '.', '.', '@'],
['@', '@', '.', '@', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '@', '.', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '@', '@', '.', '.', '.', '@', '@'],
['@', '.', '.', '@', '.', '@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@', '@'],
['@', '@', '.', '@', '.', '@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '.', '@', '.', '@', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '.', '@', '.', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '@', '@', '.', '.', '.', '@', '@'],
['@', '.', '.', '@', '.', '@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '@', '.', '.', '.', '@', '.', '.', '.', '@', '@', '@'],
['@', '@', '.', '@', '.', '@', '.', '@', '.', '.', '.', '.', '.', '@'],
['@', '@', '@', '.', '.', '.', '@', '.', '@', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '^', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '^', '^', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '^', '*', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '^', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '^', '^', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', 'O', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', 'O', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', 'O', '.', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', '.', '.', 'O', '.', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', '~', '~', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', '~', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', '~', ' ', ' ', ' ', '~', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', '~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', '~', '~', '~', ' ', '~', ' ', ' ', ' ', ' ', '~', ' ', '~'],
['~', '~', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '_', '_', '|', '|', '_', '_', '|', '_', '|'],
['|', '_', '|', '_', '|', '_', '_', '|', '|', '_', '|', '|'],
['|', '|', '_', '_', '_', '_', '|', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '|', '|', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '|', '_', '_', '|', '|', '_', '_', '|', '_', '|'],
['|', '_', '|', '_', '|', '_', '_', '|', '|', '_', '|', '|'],
['|', '|', '_', '_', '_', '_', '|', '_', '|', '_', '_', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '|', '|', '_', '|', '_', '_', '|', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '|', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', 'O', 'O'],
['O', 'O', 'O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', 'O', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', 'O', 'O'],
['O', 'O', 'O', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '_', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '|', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '_', '|', '_', '|', '_', '_', '|', '_', '|', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '|', '|', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '_', '|', '_', '|', '_', '_', '|', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '_', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '|', '_', '|', '_', '_', '|', '_', '_', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '_', '_', '|', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '|', '_', '|', '|', '_', '_', '_', '_', '|'],
['|', '_', '_', '_', '_', '|', '|', '_', '_', '_', '_', '|', '|'],
['|', '_', '|', '_', '|', '_', '|', '_', '_', '|', '_', '|', '|'],
['|', '_', '|', '_', '_', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '_', '|', '_', '_', '|', '|', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '_', '|', '_', '|', '_', '_', '|', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '_', '|', '_', '|'],
['|', '_', '_', '|', '|', '_', '_', '_', '_', '_', '|', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '.', '@', '.', '@', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '.', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '@', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '@', '@', '.', '@', '.', '.', '.', '@', '.', '@', '@'],
['@', '@', '@', '@', '@', '@', '.', '.', '.', '.', '.', '.', '@', '@', '@'],
['@', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '.', '@', '.', '@', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '@', '.', '@', '.', '.', '@', '.', '@', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '@', '@', '.', '@', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '.', '@', '@', '.', '@', '.', '.', '.', '@', '.', '@', '@'],
['@', '@', '@', '@', '@', '@', '.', '.', '.', '.', '.', '.', '@', '@', '@'],
['@', '.', '.', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '@', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '@', '.', '@'],
['@', '@', '.', '@', '.', '@', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '.', '@', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '@', '@'],
['@', '.', '.', '.', '.', '@', '@', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '@', '@', '@', '.', '@'],
['@', '@', '.', '@', '.', '@', '@', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '.', '@', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '.', '@', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', '*', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', '*', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', '*', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', '*', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', '*'],
['*', ' ', '*', '*', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*'],
['*', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', '*', ' ', '*', '*', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '^', '^', '^', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '^', '^', '^', '*', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^'],
['^', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '^', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', 'O', 'O', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', 'O', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '^', '*', '*', '^', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '*', '*', '*', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '^', '*', '*', '^', '*', '*', '^', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '^', '^', '*', '*', '*', '^', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '*', '^', '^', '^', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '*', '*', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '^', '*', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '^', '*', '*', '^', '*', '*', '^', '^', '*', '*', '^', '^'],
['^', '*', '*', '*', '^', '^', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '*', '^', '*', '^', '*', '*', '*', '^', '*', '*', '*', '^', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '^', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '^', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '^', '^', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '*', '^', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '-', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '~', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '~', '~', '-', '~'],
['~', '-', '~', '-', '~', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '-', '-', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '~', '-', '-', '~', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '~', '~', '-', '~'],
['~', '-', '~', '-', '~', '~', '-', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*'],
['*', '*', '*', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', '*'],
['*', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', '*', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', ' ', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', '~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', '~', '~', ' ', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', '~', ' ', ' ', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', '~', '~', ' ', '~', '~', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '_', '|', '_', '|', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '|', '_', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '|', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
```
Information about the problem:
1. "N": agent
2. "S": goal
3. "|": wall
4. "_": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "S": 1
[/INST]
import numpy as np
maze=[
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
['|', 'N', '_', '_', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '_', '_', '|', '_', '|', '|'],
['|', '_', '_', '|', '_', '_', '_', '_', '|', '|'],
['|', '|', '_', '|', '|', '_', '_', '_', '|', '|'],
['|', '_', '_', '_', '_', '|', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '_', '_', '_', '_', '|'],
['|', '|', '_', '_', '_', '|', '_', '_', 'S', '|'],
['|', '|', '|', '|', '|', '|', '|', '|', '|', '|'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '|'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'S':
V[i][j] = 2
continue
if maze[i][j] == '|':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '^', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '^', '*', '^', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '^', '^', '*', '^', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '^', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '^', '*', '*', '^', '^', '*', '^', '*', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '*', '^'],
['^', '^', '*', '*', '*', '^', '*', '*', '^', '*', '*', '*', '^', '^', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '^', '*', '^', '*', '^', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '^', '*', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
```
Information about the problem:
1. "S": agent
2. "H": goal
3. "^": wall
4. "*": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
```
The rewards are:
1. "H": 1
[/INST]
import numpy as np
maze=[
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
['^', 'S', '*', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '*', '*', '^', '*', '^', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '^', '*', '^'],
['^', '*', '*', '*', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '^', '*', '*', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '*', '*', '^', '^'],
['^', '^', '*', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '*', '^', '*', '*', '^'],
['^', '^', '^', '*', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '^', '^', '*', '*', '*', '*', '*', '^'],
['^', '*', '*', '*', '*', '*', '^', '^', '*', '*', '^'],
['^', '^', '*', '^', '^', '*', '^', '*', '*', '*', '^'],
['^', '*', '*', '*', '^', '*', '^', '*', '*', 'H', '^'],
['^', '^', '^', '^', '^', '^', '^', '^', '^', '^', '^'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (0, 2), (2, 0), (0, -2), (-2, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '^'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'H':
V[i][j] = 3
continue
if maze[i][j] == '^':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', '.', 'O', 'O', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', 'O', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', '.', '.', '.', 'O', 'O', '.', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', 'O', '.', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', 'O', 'O', 'O', '.', 'O', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', 'O', 'O', 'O', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', 'O', '.', 'O', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', 'O', '.', '.', '.', '.', 'O'],
['O', '.', '.', 'O', '.', '.', '.', 'O', '.', '.', 'O', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
```
Information about the problem:
1. "E": agent
2. "T": goal
3. "*": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "T": 1
[/INST]
import numpy as np
maze=[
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
['*', 'E', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*', '*'],
['*', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*'],
['*', '*', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*'],
['*', ' ', ' ', '*', ' ', '*', ' ', '*', ' ', '*', ' ', ' ', ' ', '*'],
['*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*', 'T', '*'],
['*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '*'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'T':
V[i][j] = 5
continue
if maze[i][j] == '*':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', 'O', '.', 'O', '.', '.', 'O', 'O', '.', 'O', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "R": agent
2. "P": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "P": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'R', 'O', '.', 'O', '.', '.', 'O', 'O', '.', 'O', 'O'],
['O', '.', 'O', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O', 'O'],
['O', '.', 'O', 'O', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', 'O', '.', '.', 'O'],
['O', '.', 'O', 'O', 'O', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', 'O', '.', '.', '.', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', 'O', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', 'O', '.', 'O', '.', '.', '.', '.', 'P', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'P':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '@', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '@', '@', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
```
Information about the problem:
1. "T": agent
2. "O": goal
3. "@": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "O": 1
[/INST]
import numpy as np
maze=[
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
['@', 'T', '@', '@', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '@', '.', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '.', '.', '@'],
['@', '.', '@', '.', '.', '.', '.', '.', '.', '@', '.', '@'],
['@', '.', '.', '.', '@', '.', '.', '.', '.', '.', '.', '@'],
['@', '@', '.', '@', '@', '.', '.', '.', '@', '.', '.', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '@', '@'],
['@', '.', '.', '.', '.', '.', '.', '.', '@', '.', '.', '@'],
['@', '@', '.', '.', '.', '.', '.', '.', '.', '@', 'O', '@'],
['@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@', '@'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '@'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'O':
V[i][j] = 2
continue
if maze[i][j] == '@':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
```
Information about the problem:
1. "L": agent
2. "B": goal
3. "O": wall
4. ".": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0)]
```
The rewards are:
1. "B": 1
[/INST]
import numpy as np
maze=[
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
['O', 'L', 'O', '.', '.', 'O', '.', '.', '.', 'O', '.', 'O'],
['O', '.', 'O', '.', 'O', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', '.', '.', 'O', 'O', 'O', '.', 'O', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', 'O', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', '.', 'O', '.', 'O', 'O', '.', 'O'],
['O', 'O', '.', '.', '.', 'O', '.', '.', '.', '.', 'O', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', 'O', '.', '.', 'O'],
['O', 'O', '.', '.', '.', '.', '.', '.', '.', '.', '.', 'O'],
['O', '.', 'O', '.', '.', 'O', '.', '.', '.', '.', '.', 'O'],
['O', '.', '.', '.', '.', '.', 'O', '.', '.', '.', 'B', 'O'],
['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != 'O'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'B':
V[i][j] = 3
continue
if maze[i][j] == 'O':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '~', '-', '~', '-', '~', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '~', '~', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '-', '~'],
['~', '~', '-', '-', '~', '-', '~', '~', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~', '-', '-', '~', '~'],
['~', '-', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "D": agent
2. "C": goal
3. "~": wall
4. "-": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "C": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'D', '-', '~', '-', '~', '-', '~', '-', '~', '~', '-', '~'],
['~', '-', '-', '-', '-', '-', '-', '-', '~', '-', '~', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '~'],
['~', '~', '~', '~', '~', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '~', '-', '-', '-', '-', '-', '-', '-', '-', '~', '-', '~'],
['~', '~', '-', '-', '~', '-', '~', '~', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '~', '-', '-', '~', '~'],
['~', '-', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '~', '-', '-', '-', '-', '-', '-', '-', '-', '-', '~'],
['~', '-', '-', '-', '~', '-', '-', '-', '-', '-', '~', '~', '~'],
['~', '-', '-', '-', '-', '~', '-', '-', '-', '-', '-', 'C', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'C':
V[i][j] = 2
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |
<s>[INST] <<SYS>>\n\n<</SYS>>\n\n
This is a maze problem that I want you to solve.
```
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', ' ', '~', '~', ' ', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', '~', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
```
Information about the problem:
1. "P": agent
2. "X": goal
3. "~": wall
4. " ": empty space
These are the set of actions that an agent can perform:
```
actions=[(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
```
The rewards are:
1. "X": 1
[/INST]
import numpy as np
maze=[
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
['~', 'P', ' ', '~', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', ' ', ' ', '~', ' ', '~', '~', ' ', ' ', '~', ' ', '~'],
['~', ' ', '~', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', '~', ' ', ' ', ' ', '~', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', ' ', '~', ' ', '~', '~', ' ', ' ', '~'],
['~', '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', '~', '~', ' ', ' ', ' ', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '~'],
['~', ' ', '~', ' ', ' ', '~', ' ', ' ', '~', ' ', '~', ' ', ' ', '~', '~'],
['~', ' ', ' ', ' ', '~', '~', '~', ' ', ' ', ' ', ' ', '~', '~', 'X', '~'],
['~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~', '~'],
]
def value_iteration(maze, gamma=0.9):
rows = len(maze)
cols = len(maze[0])
# Initialize the value function
V = np.zeros((rows, cols))
# Define actions:
actions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# Helper function to check if a cell is valid to move into
def is_valid_move(x, y):
return 0 <= x < rows and 0 <= y < cols and maze[x][y] != '~'
# Perform value iteration
for i in range(1000):
for i in range(rows):
for j in range(cols):
if maze[i][j] == 'X':
V[i][j] = 5
continue
if maze[i][j] == '~':
continue # Walls or obstacles have no value
max_value = float('-inf')
for action in actions:
new_i, new_j = i + action[0], j + action[1]
if is_valid_move(new_i, new_j):
max_value = max(max_value, V[new_i][new_j])
V[i][j] = gamma * max_value
return V
np.set_printoptions(precision=2)
print(value_iteration(maze))
</s> |