tkn-tub / ns3-gym

ns3-gym - The Playground for Reinforcement Learning in Networking Research
GNU General Public License v2.0
524 stars 198 forks source link

some problem in run cognitive-agent-v1.py #80

Open bunuaaxjw opened 1 year ago

bunuaaxjw commented 1 year ago

Traceback (most recent call last): File "./cognitive-agent-v1.py", line 66, in next_state = np.reshape(next_state, (1, s_size)) File "<__array_function__ internals>", line 5, in reshape File "/home/xujunwei/anaconda3/envs/tensorflow/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 298, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/home/xujunwei/anaconda3/envs/tensorflow/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc return bound(*args, **kwds) ValueError: cannot reshape array of size 1 into shape (1,4)

It seems that the return of the function env.reset() is not an array, so the reshape function could not work.

GeorgeFrangulea commented 1 year ago

Hello, did you manage to solve this issue?

I have the same problem when I try to use env = ns3env.Ns3Env().

Using env = gym.make('ns3-v0') does seem to compile but the resulting figure shows that no learning has happened. Do you know why that is?

bunuaaxjw commented 1 year ago

@GeorgeFrangulea I solved this problem. It seems that the connection between ns3 and gym have some problems, so it went wrong. The state in code turned to be None, which cause this problem. I solved it by set when "state = None" then jump out of the loop and continue the loop. The result is correct. As I konw, you should use env = ns3env.Ns3Env() to create the environment.