Skip to content

forward-aways/multi-agent_scheduler

Repository files navigation

多智能体协作任务调度系统

基于深度强化学习的多智能体协作框架

Python PyTorch License Platform

English | 中文文档


项目简介

本项目实现了一个通用的多智能体强化学习框架,采用去中心化架构和插件式设计,支持多种应用场景的智能体协作。系统通过精心设计的奖励机制和环境耦合,实现了智能体间的隐式协作,无需显式通信即可达成协同目标。

核心优势

  • 插件化架构 - 动态加载环境和策略,易于扩展新场景
  • 开箱即用 - 单命令启动完整系统(UI + API + 可视化)
  • 实时监控 - PyQt6图形界面 + Web控制台双重监控
  • 双算法支持 - MAPPO(去中心化)和 MADDPG(集中训练)
  • 高度可配置 - YAML配置文件管理所有参数
  • 自动化评估 - 批量测试、报告生成、性能对比

应用场景

场景 描述 智能体数量 关键指标
服务器调度 多服务器负载均衡与任务分配 5台服务器 负载均衡度优化显著
无人机协同 3D空间队形保持、巡检、包围 3架无人机 队形误差 < 4米
物流调度 多仓库货物调度与车辆配送 3仓库+5车辆 订单完成率 > 90%

技术架构

系统架构图

┌─────────────────────────────────────────────────────────────┐
│                     用户交互层                               │
│  ┌──────────────┐         ┌──────────────────────┐         │
│  │  PyQt6 UI    │◄───────►│   Web API Console    │         │
│  │  (主窗口)     │         │   (Flask, Port 5003) │         │
│  └──────┬───────┘         └──────────┬───────────┘         │
└─────────┼────────────────────────────┼─────────────────────┘
          │                            │
┌─────────▼────────────────────────────▼─────────────────────┐
│                   核心调度引擎层                             │
│  ┌──────────────────────────────────────────────────┐      │
│  │           SchedulerEngine (调度引擎)              │      │
│  │  • 插件管理  • 场景切换  • 回调机制  • 批量评估   │      │
│  └────────────────────┬─────────────────────────────┘      │
└───────────────────────┼────────────────────────────────────┘
                        │
┌───────────────────────▼────────────────────────────────────┐
│                    插件层                                   │
│  ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐   │
│  │ Environment │  │  Strategy    │  │  Evaluation     │   │
│  │   Plugins   │  │   Plugins    │  │    Plugins      │   │
│  └──────┬──────┘  └──────┬───────┘  └────────┬────────┘   │
└─────────┼────────────────┼───────────────────┼────────────┘
          │                │                   │
┌─────────▼────────────────▼───────────────────▼────────────┐
│                  环境实现层 (Gymnasium)                     │
│  ┌────────────────┐ ┌──────────────┐ ┌─────────────────┐  │
│  │ ServerEnv      │ │ DroneEnv     │ │ LogisticsEnv    │  │
│  │ (服务器调度)    │ │ (无人机协同)  │ │ (物流配送)       │  │
│  └────────────────┘ └──────────────┘ └─────────────────┘  │
└────────────────────────────────────────────────────────────┘
          │
┌─────────▼──────────────────────────────────────────────────┐
│                 智能体层 (Actor-Critic)                      │
│  ┌─────────────┐  ┌──────────────┐                         │
│  │ MAPPO Agent │  │ MADDPG Agent │                         │
│  │ • Actor Net │  │ • Actor Net  │                         │
│  │ • CriticNet │  │ • Critic Net │                         │
│  │ • GAE       │  │ • Replay Buf │                         │
│  └─────────────┘  └──────────────┘                         │
└────────────────────────────────────────────────────────────┘

协作机制

虽然采用去中心化架构,但系统通过以下机制实现智能体协作:

  1. 观测共享 - 每个智能体可观测其他智能体的相对状态
  2. 全局奖励 - 团队整体表现影响个体奖励
  3. 角色分工 - 领航-跟随者等明确的任务分工
  4. 环境耦合 - 共享的环境状态将所有智能体联系在一起
# 观测空间示例:包含协作信息
observation = {
    'local_state': [...],        # 自身状态
    'neighbor_states': [...],    # 邻居智能体相对位置
    'leader_state': [...],       # 领航机位置(如适用)
    'global_metrics': [...]      # 全局性能指标
}

快速开始

环境要求

  • Python: 3.9+
  • 操作系统: Windows 10/11 或 Linux
  • 内存: 建议 8GB+
  • GPU: 可选(CUDA加速训练)

安装步骤

# 1. 克隆项目
git clone <repository-url>
cd multi_agent_scheduler

# 2. 创建虚拟环境(推荐)
python -m venv venv
source venv/bin/activate  # Linux/Mac
#
venv\Scripts\activate     # Windows

# 3. 安装依赖
pip install -r requirements.txt

一键启动

python run_ui.py

启动后系统将自动:

  1. 启动 Flask API 服务器(端口 5003)
  2. 打开 PyQt6 图形界面
  3. 提供 Web 控制台访问入口

访问 http://127.0.0.1:5003/ 查看 Web 控制台


使用指南

训练模型

服务器调度训练

# MAPPO 算法(推荐)
python train/server/train_mappo_server.py --episodes 600

# MADDPG 算法
python train/server/train_maddpg_server.py --episodes 1000

无人机队形训练

# 三角形队形
python train/drone/train_mappo_formation.py \
    --formation triangle \
    --episodes 600

# 一字形队形
python train/drone/train_mappo_formation.py \
    --formation line \
    --episodes 600

# V字形队形
python train/drone/train_mappo_formation.py \
    --formation v_shape \
    --episodes 600

物流调度训练

python train/logistics/train_mappo_logistics.py --episodes 2000

推理与测试

方式1:图形界面

  1. 运行 python run_ui.py
  2. 在左侧面板选择调度模式(自动/手动)
  3. 选择算法(MAPPO/MADDPG)
  4. 点击"启动调度"开始推理

方式2:API 调用(系统启动后即可使用)

系统启动后内置 Flask API 服务运行在 http://127.0.0.1:5003,提供以下 RESTful 端点:

方法 端点 功能
GET /api/status 获取系统状态
GET /api/plugins 获取插件列表
GET /api/scenarios 获取可用场景
GET /api/strategy/current 获取当前策略
POST /api/scenario/load 加载场景
POST /api/strategy/switch 切换策略
POST /api/task/allocate 任务分配
POST /api/task/batch_allocate 批量任务分配

完整调用流程示例(使用 Postman):

系统启动后,打开 Postman,按以下步骤依次发送请求:

① 查看系统状态

  • 方法:GET
  • URL:http://127.0.0.1:5003/api/status

② 查看可用插件

  • 方法:GET
  • URL:http://127.0.0.1:5003/api/plugins

③ 加载服务器场景

  • 方法:POST
  • URL:http://127.0.0.1:5003/api/scenario/load
  • Headers:Content-Type: application/json
  • Body (raw JSON):
{
    "environment": "server_environment",
    "strategy": "random_strategy",
    "env_config": {
        "num_servers": 5,
        "num_tasks": 10
    },
    "strategy_config": {
        "num_actions": 3
    }
}

④ 切换策略到 MAPPO

  • 方法:POST
  • URL:http://127.0.0.1:5003/api/strategy/switch
  • Headers:Content-Type: application/json
  • Body (raw JSON):
{
    "strategy_name": "mappo_strategy",
    "config": {
        "scenario_type": "server",
        "state_dim": 31,
        "num_actions": 3
    }
}

⑤ 发送任务,获取调度决策

  • 方法:POST
  • URL:http://127.0.0.1:5003/api/task/allocate
  • Headers:Content-Type: application/json
  • Body (raw JSON):
{
    "task_info": {
        "task_id": "task_001",
        "task_type": "computation",
        "priority": 5
    },
    "agent_id": "agent_0"
}

⑥ 批量分配 - 5个智能体各分配一个任务(演示多智能体决策)

  • 方法:POST
  • URL:http://127.0.0.1:5003/api/task/batch_allocate
  • Headers:Content-Type: application/json
  • Body (raw JSON):
{
    "tasks": [
        {
            "task_info": { "task_id": "task_001", "task_type": "computation", "priority": 5 },
            "agent_id": "agent_0"
        },
        {
            "task_info": { "task_id": "task_002", "task_type": "computation", "priority": 3 },
            "agent_id": "agent_1"
        },
        {
            "task_info": { "task_id": "task_003", "task_type": "storage", "priority": 7 },
            "agent_id": "agent_2"
        },
        {
            "task_info": { "task_id": "task_004", "task_type": "network", "priority": 2 },
            "agent_id": "agent_3"
        },
        {
            "task_info": { "task_id": "task_005", "task_type": "computation", "priority": 8 },
            "agent_id": "agent_4"
        }
    ]
}

批量分配返回示例:

{
    "success": true,
    "total_tasks": 5,
    "successful_allocations": 5,
    "failed_allocations": 0,
    "allocations": [
        { "agent_id": "agent_0", "task_id": "task_001", "action": 1, "strategy": "random_strategy" },
        { "agent_id": "agent_1", "task_id": "task_002", "action": 0, "strategy": "random_strategy" },
        { "agent_id": "agent_2", "task_id": "task_003", "action": 2, "strategy": "random_strategy" },
        { "agent_id": "agent_3", "task_id": "task_004", "action": 0, "strategy": "random_strategy" },
        { "agent_id": "agent_4", "task_id": "task_005", "action": 1, "strategy": "random_strategy" }
    ]
}

⑦ 仿真运行 - 注入一批任务,5个智能体协同运行多步

  • 方法:POST
  • URL:http://127.0.0.1:5003/api/scenario/run
  • Headers:Content-Type: application/json
  • Body (raw JSON):
{
    "environment": "server_environment",
    "strategy": "mappo_strategy",
    "strategy_config": {
        "scenario_type": "server",
        "state_dim": 31,
        "num_actions": 3
    },
    "tasks": [
        { "cpu_req": 20, "memory_req": 10, "priority": 5, "type": "compute" },
        { "cpu_req": 15, "memory_req": 5,  "priority": 3, "type": "storage" },
        { "cpu_req": 30, "memory_req": 20, "priority": 8, "type": "compute" },
        { "cpu_req": 10, "memory_req": 15, "priority": 2, "type": "network" },
        { "cpu_req": 25, "memory_req": 10, "priority": 6, "type": "compute" }
    ],
    "max_steps": 30
}

仿真运行返回摘要示例:

{
    "success": true,
    "simulation_summary": {
        "environment": "server_environment",
        "strategy": "mappo_strategy",
        "total_steps": 25,
        "total_tasks_injected": 5,
        "tasks_completed": 5,
        "tasks_dropped": 0,
        "total_reward": 28.5,
        "elapsed_seconds": 0.15
    },
    "agent_summary": {
        "server_0": { "total_actions": 25, "action_distribution": { "accept": 8, "reject": 12, "priority": 5 }, "total_reward": 6.2 },
        "server_1": { "total_actions": 25, "action_distribution": { "accept": 6, "reject": 14, "priority": 5 }, "total_reward": 4.8 },
        "server_2": { "total_actions": 25, "action_distribution": { "accept": 10, "reject": 10, "priority": 5 }, "total_reward": 7.5 },
        "server_3": { "total_actions": 25, "action_distribution": { "accept": 5, "reject": 15, "priority": 5 }, "total_reward": 3.2 },
        "server_4": { "total_actions": 25, "action_distribution": { "accept": 9, "reject": 11, "priority": 5 }, "total_reward": 6.8 }
    }
}

Python SDK 调用:

from api.scheduler_sdk import SchedulerSDK

sdk = SchedulerSDK("http://127.0.0.1:5003")

# 1. 查看系统状态
print(sdk.get_status())

# 2. 加载服务器场景
sdk.load_scenario({
    "environment": "server_environment",
    "strategy": "random_strategy",
    "env_config": {"num_servers": 5, "num_tasks": 10},
    "strategy_config": {"num_actions": 3}
})

# 3. 切换策略到 MAPPO
sdk.switch_strategy("mappo_strategy", {
    "scenario_type": "server",
    "state_dim": 31,
    "num_actions": 3
})

# 4. 单任务分配
result = sdk.allocate_task("task_001", "computation", priority=5)
print(result)

# 5. 批量分配 - 5个智能体各一个任务,返回各自的决策
results = sdk.batch_allocate([
    {"task_info": {"task_id": "t1", "task_type": "computation", "priority": 5}, "agent_id": "agent_0"},
    {"task_info": {"task_id": "t2", "task_type": "computation", "priority": 3}, "agent_id": "agent_1"},
    {"task_info": {"task_id": "t3", "task_type": "storage", "priority": 7},    "agent_id": "agent_2"},
    {"task_info": {"task_id": "t4", "task_type": "network", "priority": 2},    "agent_id": "agent_3"},
    {"task_info": {"task_id": "t5", "task_type": "computation", "priority": 8}, "agent_id": "agent_4"},
])

for alloc in results["allocations"]:
    print(f"{alloc['agent_id']} -> action={alloc['action']}")

# 6. 仿真运行 - 注入5个任务,5个智能体协同运行多步
result = sdk.run_simulation({
    "strategy": "mappo_strategy",
    "strategy_config": {"scenario_type": "server", "state_dim": 31, "num_actions": 3},
    "tasks": [
        {"cpu_req": 20, "memory_req": 10, "priority": 5, "type": "compute"},
        {"cpu_req": 15, "memory_req": 5,  "priority": 3, "type": "storage"},
        {"cpu_req": 30, "memory_req": 20, "priority": 8, "type": "compute"},
        {"cpu_req": 10, "memory_req": 15, "priority": 2, "type": "network"},
        {"cpu_req": 25, "memory_req": 10, "priority": 6, "type": "compute"}
    ],
    "max_steps": 30
})

summary = result["simulation_summary"]
print(f"任务完成: {summary['tasks_completed']}/{summary['total_tasks_injected']}, 总奖励: {summary['total_reward']}")

for agent_id, info in result["agent_summary"].items():
    print(f"{agent_id}: accept={info['action_distribution']['accept']}, reward={info['total_reward']}")

浏览器直接访问(无需任何工具):

功能 浏览器输入
系统状态 http://127.0.0.1:5003/api/status
插件列表 http://127.0.0.1:5003/api/plugins
API控制台 http://127.0.0.1:5003/

方式3:命令行测试

# 测试插件系统
python test/test_plugin_system.py

# 测试无人机队形
python test/test_all_formations.py

# 测试物流调度
python test/test_logistics_comprehensive.py

自动化评估

图形界面评估

  1. 切换到"自动化评估"标签页
  2. 配置评估参数(环境、策略、回合数)
  3. 点击"开始评估"
  4. 查看实时进度和结果报告

API 评估

from api.evaluation_api import EvaluationAPI

eval_api = EvaluationAPI()
result = eval_api.run_evaluation({
    'name': 'server_eval_001',
    'environment': 'server_environment',
    'strategy': 'mappo_strategy',
    'episodes': 100,
    'export_format': 'json',
    'export_path': 'evaluations/test_run'
})

print(f"平均奖励: {result['avg_reward']:.2f}")
print(f"成功率: {result['success_rate']:.2%}")

项目结构

multi_agent_scheduler/
├── config/                    # 配置文件
│   └── config.yaml              # 系统配置(YAML格式)
│
├── core/                      # 核心模块
│   ├── plugin_interface.py      # 插件接口定义
│   ├── plugin_manager.py        # 插件管理器
│   └── scheduler_engine.py      # 调度引擎核心
│
├── api/                       # API 服务
│   ├── scheduler_api.py         # 调度器 REST API
│   └── evaluation_api.py        # 评估 API
│
├── plugins/                   # 插件目录
│   ├── server_environment.py    # 服务器环境插件
│   ├── drone_environment.py     # 无人机环境插件
│   ├── logistics_environment.py # 物流环境插件
│   ├── mappo_strategy.py        # MAPPO 策略插件
│   ├── maddpg_strategy.py       # MADDPG 策略插件
│   ├── round_robin_strategy.py  # 轮询策略插件
│   └── random_strategy.py       # 随机策略插件
│
├── environments/              # Gymnasium 环境
│   ├── multi_agent_server_env.py
│   ├── multi_agent_drone_env.py
│   └── multi_agent_logistics_env.py
│
├── train/                     # 训练脚本
│   ├── server/
│   │   ├── train_mappo_server.py
│   │   └── train_maddpg_server.py
│   ├── drone/
│   │   ├── train_mappo_formation.py
│   │   └── train_mappo_encirclement.py
│   └── logistics/
│       └── train_mappo_logistics.py
│
├── ui/                        # 图形界面
│   ├── main_window.py           # 主窗口
│   ├── backend_controller.py    # 后端控制器
│   ├── server_visualization.py  # 服务器可视化
│   ├── drone_visualization.py   # 无人机 3D 可视化
│   ├── logistics_visualization.py
│   └── evaluation_widget.py     # 评估模块 UI
│
├── models/                    # 预训练模型
│   ├── multi_agent_server/
│   ├── multi_agent_drone/
│   └── multi_agent_logistics/
│
├── evaluations/               # 评估报告输出
├── logs/                      # 日志文件
├── templates/                 # Web 模板
│   └── index.html               # API 控制台页面
│
├── test/                      # 测试脚本(30+测试用例)
├── utils/                     # 工具函数
│   ├── logging_config.py        # 日志配置
│   └── training_visualizer.py   # 训练可视化
│
├── requirements.txt             # Python 依赖
├── run_ui.py                    # 启动脚本
└── README.md                    # 项目文档

算法详解

MAPPO (Multi-Agent PPO)

特点:完全去中心化,每个智能体独立决策

网络结构

Actor Network (策略网络):
Input(state_dim) → Linear(256) → Tanh → Linear(256) → Tanh → Linear(action_dim) → Softmax

Critic Network (价值网络):
Input(state_dim) → Linear(256) → Tanh → Linear(256) → Tanh → Linear(1)

关键超参数

参数 默认值 说明
actor_lr 3e-4 Actor 学习率
critic_lr 1e-3 Critic 学习率
gamma 0.99 折扣因子
gae_lambda 0.95 GAE 参数
clip_epsilon 0.2 PPO 裁剪系数
entropy_coef 0.01 熵正则化系数
ppo_epochs 10 每次更新的迭代次数
mini_batch_size 64 小批量大小

训练流程

for episode in range(num_episodes):
    states = env.reset()
    
    for step in range(max_steps):
        # 1. 每个智能体选择动作
        for agent in agents:
            action, log_prob, value = agent.select_action(states[agent.id])
            agent.store_transition(states, actions, log_probs, values)
        
        # 2. 执行联合动作
        next_states, rewards, dones, _ = env.step(actions)
        
        # 3. 存储奖励
        for agent in agents:
            agent.rewards[-1] = rewards[agent.id]
        
        # 4. 回合结束时更新
        if all(dones):
            for agent in agents:
                advantages, returns = agent.compute_gae(next_value)
                agent.update(advantages, returns)

MADDPG (Multi-Agent DDPG)

特点:集中式训练 + 分布式执行

核心差异

特性 MAPPO MADDPG
架构 完全去中心化 集中训练,分散执行
Critic输入 局部观测 全局状态+所有动作
经验存储 各智能体独立 共享经验回放池
探索策略 熵正则化 ε-greedy 衰减
更新方式 PPO 裁剪 软更新目标网络
适用场景 大规模多智能体 需要强协调的场景

性能基准

训练结果汇总

服务器调度(MAPPO, 600回合)

指标 数值 趋势
平均奖励 ~180 稳步上升
Actor Loss -0.003 ~ -0.015 稳定
Critic Loss 0.5 ~ 2.0 收敛
熵值 0.8 ~ 1.1 适度探索

无人机队形(MAPPO, 600回合)

队形 总奖励 平均奖励/步 队形误差 评价
Triangle 8841 44.2 4.26m 优秀
Line 9241 46.2 3.00m 优秀
V-Shape 2451 12.3 5.98m 一般

物流调度(MAPPO, 550回合)

指标 数值 评价
平均奖励 ~600 良好
订单完成率 > 90% 达标
车辆利用率 75-85% 高效
平均配送时间 减少 30% 优化明显

评估指标说明

指标 计算公式 理想值 说明
成功率 成功回合数 / 总回合数 > 90% 任务完成比例
平均奖励 Σ奖励 / 回合数 越高越好 策略质量
任务完成率 完成任务数 / 总任务数 > 80% 系统吞吐量
负载均衡度 1 - std(利用率) / mean(利用率) 接近 1.0 资源分配均匀性
稳定性得分 1 / (1 + reward_std) > 0.8 策略一致性

开发指南

添加新环境

  1. 创建环境类
# environments/my_custom_env.py
import gymnasium as gym
import numpy as np

class MyCustomEnv(gym.Env):
    def __init__(self, config):
        super().__init__()
        self.num_agents = config.get('num_agents', 3)
        
        # 定义观测空间和动作空间
        self.observation_spaces = {
            f'agent_{i}': gym.spaces.Box(low=-1, high=1, shape=(10,))
            for i in range(self.num_agents)
        }
        self.action_spaces = {
            f'agent_{i}': gym.spaces.Discrete(5)
            for i in range(self.num_agents)
        }
    
    def reset(self, seed=None, options=None):
        # 重置环境逻辑
        observations = {...}
        infos = {...}
        return observations, infos
    
    def step(self, actions):
        # 执行动作逻辑
        observations = {...}
        rewards = {...}
        terminated = {...}
        truncated = {...}
        infos = {...}
        return observations, rewards, terminated, truncated, infos
  1. 创建环境插件
# plugins/my_custom_environment.py
from core.plugin_interface import EnvironmentPlugin
from environments.my_custom_env import MyCustomEnv

class MyCustomEnvironmentPlugin(EnvironmentPlugin):
    def __init__(self):
        super().__init__(name="my_custom_environment", version="1.0.0")
    
    def initialize(self, config):
        self.env = MyCustomEnv(config)
        return True
    
    def reset(self):
        return self.env.reset()
    
    def step(self, actions):
        return self.env.step(actions)
  1. 注册到系统

将插件文件放入 plugins/ 目录,系统会自动发现并加载。

添加新策略

# plugins/my_strategy.py
from core.plugin_interface import StrategyPlugin
import torch
import numpy as np

class MyStrategyPlugin(StrategyPlugin):
    def __init__(self):
        super().__init__(name="my_strategy", version="1.0.0")
        self.model = None
    
    def initialize(self, config):
        # 加载模型或初始化策略
        model_path = config.get('model_path')
        if model_path:
            self.load_model(model_path)
        return True
    
    def make_decision(self, observation, agent_id):
        # 根据观测做出决策
        if self.model:
            with torch.no_grad():
                action = self.model.predict(observation)
        else:
            action = np.random.randint(0, 5)  # 随机动作
        return action
    
    def load_model(self, model_path):
        # 加载预训练模型
        pass
    
    def save_model(self, model_path):
        # 保存模型
        pass

自定义奖励函数

奖励函数设计是实现智能体协作的关键。以下是设计原则:

def compute_reward(agent_state, global_state):
    reward = 0.0
    
    # 1. 个体奖励:鼓励智能体完成自身任务
    reward += individual_task_completion * 2.0
    
    # 2. 团队奖励:鼓励协作行为
    reward += team_performance_metric * 1.5
    
    # 3. 均衡奖励:避免资源分配不均
    reward -= resource_imbalance_penalty * 0.5
    
    # 4. 效率奖励:鼓励快速完成任务
    reward += efficiency_bonus * 1.0
    
    # 5. 惩罚项:避免不良行为
    reward -= collision_penalty * 5.0
    reward -= resource_waste_penalty * 2.0
    
    return reward

常见问题

Q1: 训练不稳定怎么办?

解决方案

  • 降低学习率(actor_lr, critic_lr
  • 增加熵系数(entropy_coef)鼓励探索
  • 减小裁剪系数(clip_epsilon)限制更新幅度
  • 增加 PPO 迭代次数(ppo_epochs
  • 检查奖励函数是否合理

Q2: 如何调整智能体数量?

修改环境配置即可,系统会自动适配:

# config/config.yaml
environment:
  server:
    num_servers: 10  # 改为10台服务器
  drone:
    num_drones: 5    # 改为5架无人机

Q3: 模型加载失败?

检查以下几点:

  1. 模型文件路径是否正确
  2. 网络结构是否与训练时一致
  3. PyTorch 版本兼容性
  4. 使用 map_location='cpu' 加载 GPU 训练的模型
checkpoint = torch.load(model_path, map_location='cpu')

Q4: 如何添加新的队形?

在无人机环境中添加新队形配置:

# environments/multi_agent_drone_env.py
self.formations = {
    'triangle': [(0, 0, 0), (-10, -10, 0), (10, -10, 0)],
    'line': [(0, 0, 0), (10, 0, 0), (20, 0, 0)],
    'circle': [  # 新增圆形队形
        (10 * np.cos(2 * np.pi * i / 3), 
         10 * np.sin(2 * np.pi * i / 3), 0)
        for i in range(3)
    ]
}

Q5: API 服务器无法启动?

排查步骤:

  1. 检查端口 5003 是否被占用
  2. 确认 Flask 已安装:pip install flask
  3. 查看日志文件 logs/backend.log
  4. 尝试更换端口:修改 run_ui.py 中的端口号

Q6: 如何进行算法对比?

使用自动化评估模块进行对比:

from api.evaluation_api import EvaluationAPI

eval_api = EvaluationAPI()

# 评估 MAPPO
mappo_result = eval_api.run_evaluation({
    'name': 'mappo_eval',
    'strategy': 'mappo_strategy',
    'episodes': 100
})

# 评估 MADDPG
maddpg_result = eval_api.run_evaluation({
    'name': 'maddpg_eval',
    'strategy': 'maddpg_strategy',
    'episodes': 100
})

# 对比结果
print(f"MAPPO 平均奖励: {mappo_result['avg_reward']:.2f}")
print(f"MADDPG 平均奖励: {maddpg_result['avg_reward']:.2f}")

引用与致谢

如果您在研究中使用了本项目,请引用:

@software{multi_agent_scheduler,
  title = {Multi-Agent Collaborative Task Scheduling System},
  author = {Your Name},
  year = {2026},
  url = {https://github.com/your-repo/multi-agent-scheduler}
}

相关论文

  • Lowe, R., et al. "Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments." NeurIPS 2017.
  • Yu, C., et al. "The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games." NeurIPS 2022.

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件


贡献指南

欢迎提交 Issue 和 Pull Request!

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

联系方式


如果这个项目对您有帮助,请给个 Star!

Made with love by Your Team


English Version

Project Overview

This project implements a general-purpose multi-agent reinforcement learning framework with decentralized architecture and plugin-based design. The system achieves implicit coordination between agents through carefully designed reward mechanisms and environmental coupling, without requiring explicit communication.

Key Features

  • Plugin Architecture - Dynamic loading of environments and strategies
  • Out-of-the-Box - Single command to start the complete system
  • Real-time Monitoring - Dual monitoring via PyQt6 GUI and Web console
  • Dual Algorithm Support - MAPPO (decentralized) and MADDPG (centralized training)
  • Highly Configurable - YAML configuration for all parameters
  • Automated Evaluation - Batch testing, report generation, performance comparison

Quick Start

# Install dependencies
pip install -r requirements.txt

# Start the system
python run_ui.py

# Access web console at http://127.0.0.1:5003/

Training Examples

# Train server scheduling with MAPPO
python train/server/train_mappo_server.py --episodes 600

# Train drone formation
python train/drone/train_mappo_formation.py --formation triangle --episodes 600

# Train logistics scheduling
python train/logistics/train_mappo_logistics.py --episodes 2000

For detailed documentation, please refer to the Chinese version above or check the code comments.


Last Updated: 2026-04-13

About

基于深度强化学习的多智能体协作任务调度系统

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors