| | |
| | | package com.algo.service; |
| | | |
| | | import com.algo.config.EnvDataConfig; |
| | | import com.algo.model.AGVStatus; |
| | | import com.algo.model.BackpackData; |
| | | import com.algo.model.TaskAssignment; |
| | | import com.algo.model.TaskData; |
| | | import com.algo.util.JsonUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | |
| | | /** |
| | | * 任务分配服务类 |
| | | */ |
| | | @Service |
| | | public class TaskAllocationService { |
| | | |
| | | private Map<String, Map<String, Integer>> pathMapping; |
| | | private Map<String, Object> environmentConfig; |
| | | @Autowired |
| | | private EnvDataConfig envDataConfig; |
| | | |
| | | /** |
| | | * 构造函数 |
| | | * |
| | | * @param pathMapping 路径映射信息 |
| | | * @param environmentConfig 环境配置信息 |
| | | */ |
| | | public TaskAllocationService(Map<String, Map<String, Integer>> pathMapping, |
| | | Map<String, Object> environmentConfig) { |
| | | this.pathMapping = pathMapping; |
| | | this.environmentConfig = environmentConfig; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 执行任务分配 |
| | |
| | | System.out.println("开始任务分配,AGV数量: " + agvStatusList.size() + ", 任务数量: " + taskList.size()); |
| | | |
| | | // 输出环境信息 |
| | | System.out.println("环境信息:宽度=" + environmentConfig.get("width") + |
| | | ", 高度=" + environmentConfig.get("height") + |
| | | ", 工作站数量=" + environmentConfig.get("stationCount")); |
| | | System.out.println("环境信息:宽度=" + envDataConfig.getEnvironmentConfig().get("width") + |
| | | ", 高度=" + envDataConfig.getEnvironmentConfig().get("height") + |
| | | ", 工作站数量=" + envDataConfig.getEnvironmentConfig().get("stationCount")); |
| | | |
| | | List<TaskAssignment> assignments = new ArrayList<>(); |
| | | |
| | |
| | | System.out.println("处理起点 " + startLocation + " 的任务,数量: " + locationTasks.size()); |
| | | |
| | | // 检查是否为工作站 |
| | | if (JsonUtils.isStation(startLocation, environmentConfig)) { |
| | | Map<String, Object> stationInfo = JsonUtils.getStationInfo(startLocation, environmentConfig); |
| | | if (JsonUtils.isStation(startLocation, envDataConfig.getEnvironmentConfig())) { |
| | | Map<String, Object> stationInfo = JsonUtils.getStationInfo(startLocation, envDataConfig.getEnvironmentConfig()); |
| | | if (stationInfo != null) { |
| | | Integer capacity = (Integer) stationInfo.get("capacity"); |
| | | System.out.println("工作站 " + startLocation + " 容量: " + capacity); |
| | |
| | | AGVStatus bestAgv = null; |
| | | double minDistance = Double.MAX_VALUE; |
| | | |
| | | int[] targetCoord = JsonUtils.getCoordinate(targetLocation, pathMapping); |
| | | int[] targetCoord = JsonUtils.getCoordinate(targetLocation, envDataConfig.getPathMapping()); |
| | | if (targetCoord == null) { |
| | | System.out.println("无法获取目标位置 " + targetLocation + " 的坐标"); |
| | | return availableAgvs.isEmpty() ? null : availableAgvs.get(0); |
| | |
| | | continue; |
| | | } |
| | | |
| | | int[] agvCoord = JsonUtils.getCoordinate(agv.getPosition(), pathMapping); |
| | | int[] agvCoord = JsonUtils.getCoordinate(agv.getPosition(), envDataConfig.getPathMapping()); |
| | | if (agvCoord != null) { |
| | | double distance = JsonUtils.calculateManhattanDistance(agvCoord, targetCoord); |
| | | |