Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
结
结合Transformer与多智能体强化学习的多无人机编码缓存传输方法
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
牛辰龙
结合Transformer与多智能体强化学习的多无人机编码缓存传输方法
Commits
afb1dcac
Commit
afb1dcac
authored
Jul 02, 2021
by
hezhiqiang01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add single file env
parent
3f5c8460
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
37 deletions
+46
-37
envs/env.py
envs/env.py
+45
-0
envs/env_wrappers.py
envs/env_wrappers.py
+1
-37
No files found.
envs/env.py
0 → 100644
View file @
afb1dcac
"""
# @Time : 2021/7/2 5:22 下午
# @Author : hezhiqiang01
# @Email : hezhiqiang01@baidu.com
# @File : env.py
"""
import
numpy
as
np
class
Env
(
object
):
"""
# 环境中的智能体
"""
def
__init__
(
self
,
i
):
self
.
agent_num
=
2
# 设置智能体(小飞机)的个数,这里设置为两个
self
.
obs_dim
=
14
# 设置智能体的观测纬度
self
.
action_dim
=
5
# 设置智能体的动作纬度,这里假定为一个五个纬度的
def
reset
(
self
):
"""
# self.agent_num设定为2个智能体时,返回值为一个list,每个list里面为一个shape = (self.obs_dim, )的观测数据
"""
sub_agent_obs
=
[]
for
i
in
range
(
self
.
agent_num
):
sub_obs
=
np
.
random
.
random
(
size
=
(
14
,
))
sub_agent_obs
.
append
(
sub_obs
)
return
sub_agent_obs
def
step
(
self
,
actions
):
"""
# self.agent_num设定为2个智能体时,actions的输入为一个2纬的list,每个list里面为一个shape = (self.action_dim, )的动作数据
# 默认参数情况下,输入为一个list,里面含有两个元素,因为动作纬度为5,所里每个元素shape = (5, )
"""
sub_agent_obs
=
[]
sub_agent_reward
=
[]
sub_agent_done
=
[]
sub_agent_info
=
[]
for
i
in
range
(
self
.
agent_num
):
sub_agent_obs
.
append
(
np
.
random
.
random
(
size
=
(
14
,)))
sub_agent_reward
.
append
([
np
.
random
.
rand
()])
sub_agent_done
.
append
(
False
)
sub_agent_info
.
append
({})
return
[
sub_agent_obs
,
sub_agent_reward
,
sub_agent_done
,
sub_agent_info
]
\ No newline at end of file
envs/env_wrappers.py
View file @
afb1dcac
...
...
@@ -9,6 +9,7 @@ Modified from OpenAI Baselines code to work with multi-agent envs
import
numpy
as
np
import
gym
from
gym
import
spaces
from
envs.env
import
Env
class
MultiDiscrete
(
gym
.
Space
):
...
...
@@ -56,43 +57,6 @@ class MultiDiscrete(gym.Space):
return
np
.
array_equal
(
self
.
low
,
other
.
low
)
and
np
.
array_equal
(
self
.
high
,
other
.
high
)
class
Env
(
object
):
"""
# 环境中的智能体
"""
def
__init__
(
self
,
i
):
self
.
agent_num
=
2
# 设置智能体(小飞机)的个数,这里设置为两个
self
.
obs_dim
=
14
# 设置智能体的观测纬度
self
.
action_dim
=
5
# 设置智能体的动作纬度,这里假定为一个五个纬度的
def
reset
(
self
):
"""
# self.agent_num设定为2个智能体时,返回值为一个list,每个list里面为一个shape = (self.obs_dim, )的观测数据
"""
sub_agent_obs
=
[]
for
i
in
range
(
self
.
agent_num
):
sub_obs
=
np
.
random
.
random
(
size
=
(
14
,
))
sub_agent_obs
.
append
(
sub_obs
)
return
sub_agent_obs
def
step
(
self
,
actions
):
"""
# self.agent_num设定为2个智能体时,actions的输入为一个2纬的list,每个list里面为一个shape = (self.action_dim, )的动作数据
# 默认参数情况下,输入为一个list,里面含有两个元素,因为动作纬度为5,所里每个元素shape = (5, )
"""
sub_agent_obs
=
[]
sub_agent_reward
=
[]
sub_agent_done
=
[]
sub_agent_info
=
[]
for
i
in
range
(
self
.
agent_num
):
sub_agent_obs
.
append
(
np
.
random
.
random
(
size
=
(
14
,)))
sub_agent_reward
.
append
([
np
.
random
.
rand
()])
sub_agent_done
.
append
(
False
)
sub_agent_info
.
append
({})
return
[
sub_agent_obs
,
sub_agent_reward
,
sub_agent_done
,
sub_agent_info
]
class
SubprocVecEnv
(
object
):
def
__init__
(
self
,
all_args
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment