| | |
| | | package com.zy.asrs.wcs.core.utils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.system.entity.Dict; |
| | | import com.zy.asrs.wcs.system.service.DictService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | */ |
| | | public class NavigateSolution { |
| | | |
| | | // -1 -> 墙壁, 1 -> 起点 2 -> 终点 3-> 母轨 4->站点 |
| | | // -1 -> 墙壁, 0 -> 货位, 1 -> 起点 2 -> 终点 3-> 母轨 4->站点 |
| | | |
| | | int[][] map = {{}}; |
| | | |
| | | public NavigateSolution() { |
| | | //载入地图 |
| | | NavigateMapData mapData = new NavigateMapData(); |
| | | NavigateMapData mapData = SpringUtils.getBean(NavigateMapData.class); |
| | | mapData.setLev(1); |
| | | int[][] data = mapData.getData(); |
| | | this.map = data; |
| | | } |
| | | |
| | | public NavigateSolution(Integer mapType, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) { |
| | | //载入地图指定层高地图 |
| | | NavigateMapData mapData = new NavigateMapData(lev); |
| | | NavigateMapData mapData = SpringUtils.getBean(NavigateMapData.class); |
| | | mapData.setLev(lev); |
| | | int[][] data = mapData.getDataFromRedis(mapType, whitePoints, shuttlePoints); |
| | | if (data == null) { |
| | | data = mapData.getData(mapType, whitePoints, shuttlePoints); |
| | |
| | | |
| | | |
| | | public ArrayList<NavigateNode> extend_current_node(NavigateNode current_node) { |
| | | //默认地图母轨方向x |
| | | String mapDirection = "x"; |
| | | DictService dictService = SpringUtils.getBean(DictService.class); |
| | | if (dictService != null) { |
| | | Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>() |
| | | .eq(Dict::getFlag, "direction_map") |
| | | .eq(Dict::getStatus, 1)); |
| | | if (dict != null) { |
| | | mapDirection = dict.getValue(); |
| | | } |
| | | } |
| | | |
| | | //获取当前结点的x, y |
| | | int x = current_node.getX(); |
| | | int y = current_node.getY(); |
| | |
| | | // neighbour_node.add(node); |
| | | // } |
| | | // } |
| | | if (map[x][y] == 3) { |
| | | //母轨才能进行左右移动 |
| | | if (is_valid(x, y + 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y + 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | if (is_valid(x, y - 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y - 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | } |
| | | |
| | | if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) { |
| | | //子轨和母轨、输送线、充电桩才能进行上下移动 |
| | | if (is_valid(x + 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x + 1, y); |
| | | neighbour_node.add(node); |
| | | if (mapDirection.equals("x")) {//母轨x方向 |
| | | if (map[x][y] == 3) { |
| | | //母轨才能进行上下移动 |
| | | if (is_valid(x + 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x + 1, y); |
| | | neighbour_node.add(node); |
| | | } |
| | | if (is_valid(x - 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x -1, y); |
| | | neighbour_node.add(node); |
| | | } |
| | | } |
| | | if (is_valid(x - 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x -1, y); |
| | | neighbour_node.add(node); |
| | | |
| | | if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) { |
| | | //子轨和母轨、输送线、充电桩才能进行左右移动 |
| | | if (is_valid(x, y + 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y + 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | if (is_valid(x, y - 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y - 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | } |
| | | }else if (mapDirection.equals("y")) {//母轨y方向 |
| | | if (map[x][y] == 3) { |
| | | //母轨才能进行左右移动 |
| | | if (is_valid(x, y + 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y + 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | if (is_valid(x, y - 1)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x, y - 1); |
| | | neighbour_node.add(node); |
| | | } |
| | | } |
| | | |
| | | if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) { |
| | | //子轨和母轨、输送线、充电桩才能进行上下移动 |
| | | if (is_valid(x + 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x + 1, y); |
| | | neighbour_node.add(node); |
| | | } |
| | | if (is_valid(x - 1, y)) |
| | | { |
| | | NavigateNode node = new NavigateNode(x -1, y); |
| | | neighbour_node.add(node); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | public boolean is_valid(int x, int y) { |
| | | // 如果结点的位置小于0,则不合法 |
| | | if (map[x][y] < 0) return false; |
| | | for (NavigateNode node : Exist) { |
| | | //如果结点出现过,不合法 |
| | | if (node.getX() == x && node.getY() == y) { |
| | | return false; |
| | | try { |
| | | // 如果结点的位置小于0,则不合法 |
| | | if (map[x][y] < 0) return false; |
| | | for (NavigateNode node : Exist) { |
| | | //如果结点出现过,不合法 |
| | | if (node.getX() == x && node.getY() == y) { |
| | | return false; |
| | | } |
| | | if (is_exist(new NavigateNode(x, y))) { |
| | | return false; |
| | | } |
| | | } |
| | | if (is_exist(new NavigateNode(x, y))) { |
| | | return false; |
| | | } |
| | | //以上情况都没有则合法 |
| | | return true; |
| | | } catch (Exception e) { |
| | | return false; |
| | | } |
| | | //以上情况都没有则合法 |
| | | return true; |
| | | } |
| | | |
| | | public boolean is_exist(NavigateNode node) |