| | |
| | | package com.zt.life.modules.mainPart.taskReliability.service; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.zt.common.service.BaseService; |
| | |
| | | import com.zt.common.utils.UUIDUtil; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.ParamDataDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ParamData; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ProductImg; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel; |
| | | import com.zt.life.modules.mainPart.taskReliability.dao.*; |
| | | import com.zt.life.modules.mainPart.taskReliability.dto.ModelLinePairDto; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.*; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.dom4j.Element; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | /** |
| | | * model_line |
| | | * |
| | | * @author zt generator |
| | | * @author zt generator |
| | | * @since 1.0.0 2024-02-28 |
| | | */ |
| | | @Service |
| | | public class ModelLineService extends BaseService<ModelLineDao, ModelLine> { |
| | | public class ModelLineService extends BaseService<ModelLineDao, ModelLine> { |
| | | private static final Logger logger = LoggerFactory.getLogger(ModelLineService.class); |
| | | |
| | | // 运算 |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void insert(ModelRbd modelRbd) { |
| | | if (modelRbd==null) return; |
| | | if (modelRbd.getId()==null) return; |
| | | if (modelRbd == null) return; |
| | | if (modelRbd.getId() == null) return; |
| | | Long modelId = modelRbd.getId(); |
| | | |
| | | // 删除既有数据 |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(ModelRbd modelRbd) { |
| | | if (modelRbd==null) return; |
| | | if (modelRbd.getId()==null) return; |
| | | if (modelRbd == null) return; |
| | | if (modelRbd.getId() == null) return; |
| | | Long modelId = modelRbd.getId(); |
| | | |
| | | // 删除既有数据 |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean layout(ModelRbd modelRbd) { |
| | | boolean result = true; |
| | | if (modelRbd==null) return result; |
| | | if (modelRbd == null) return result; |
| | | Long modelId = modelRbd.getId(); |
| | | result = layoutRbd(modelRbd); |
| | | return result; |
| | |
| | | |
| | | // 1. 解析出节点与边 |
| | | getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList); |
| | | // 2. 对于有多根入口线的产品节点,将其上的表决、旁联关系剥离成运算符节点,添加到该节点的前面,并添加相应的边 |
| | | peelOperationFromProductNode(modelRbd.getId(), modelNodeList, modelLineList); |
| | | // 3. 计算所有节点的入口线数及出口线数 |
| | | // 2. 计算所有节点的入口线数及出口线数 |
| | | calcInOutLineNumAllNode(modelNodeList, modelLineList); |
| | | // 4. 复制产品节点(node)到list |
| | | |
| | | RbdTreeNode root = recognizeRbd(modelNodeList, modelLineList); |
| | | |
| | | /* |
| | | // 3. 复制产品节点(node)到list |
| | | List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item -> |
| | | "node".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | // 5. 不断将基本模型(串联、并联、旁联、表决、桥联)替换为虚节点而简化图形,直至无法简化为止。 |
| | | result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | // 4. 不断将基本模型(串联、并联、旁联、表决、桥联)替换为虚节点而简化图形,直至无法简化为止。 |
| | | // result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | // 6. 递归计算RBD的布局空间大小 |
| | | calcLayoutSize(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | Collections.reverse(algorithmList); |
| | | RbdTreeNode root2 = listToTree(algorithmList.get(0).getComputerList(), algorithmList, modelNodeAndVnodeList); |
| | | |
| | | RbdTreeNode root = new RbdTreeNode(); |
| | | |
| | | root.setId(Convert.toLong("20000")); |
| | | |
| | | root.setName("end"); |
| | | root.setNodeType("vnode"); |
| | | root.setAlgorithmType("parallel"); |
| | | root.setPicId("20000"); |
| | | root.setPairStartNodeId("10000"); |
| | | |
| | | root.setBlockWidthNum(root2.getBlockWidthNum() + 2); |
| | | root.setBlockHeightNum(root2.getBlockHeightNum()); |
| | | root.getChildren().add(root2); |
| | | |
| | | // 7. 递归计算RBD的布局空间参数(x、y坐标) |
| | | calcLayoutPosition(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | root.setBlockX(0); |
| | | root.setBlockY(0); |
| | | |
| | | Map<String, RbdTreeNode> nodeMap = new HashMap<>(); |
| | | calcPosition(rbdJsonArray, root, nodeMap); |
| | | setEdgeRouter(rbdJsonArray, nodeMap); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("cells", rbdJsonArray); |
| | | modelRbd.setContent(jsonObject.toString()); |
| | | // calcLayoutPosition(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | |
| | | // 8. 保存自动布局模型 |
| | | // 更新RBD数据 |
| | | // modelRbd.setAutoLayoutContent("测试文字"); |
| | | modelRbdDao.updateById(modelRbd); |
| | | // modelRbdDao.updateById(modelRbd); |
| | | */ |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private RbdTreeNode recognizeRbd(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | Map<String, Integer> vnodeCounter = new HashMap<>(); |
| | | vnodeCounter.put("vnodeCounter", 0); |
| | | RbdTreeNode root = new RbdTreeNode(); |
| | | root.setAlgorithmType("series"); |
| | | root.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | root.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | root.setNodeType("vnode"); |
| | | |
| | | ModelNode end = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode endNode = new RbdTreeNode(); |
| | | endNode.setId(end.getId()); |
| | | endNode.setName("end"); |
| | | endNode.setNodeType("end"); |
| | | endNode.setPicId(end.getPicId()); |
| | | endNode.setPairStartNodeId(end.getPairStartNodeId()); |
| | | endNode.setMyWidth(end.getWidth()); |
| | | endNode.setMyHeight(end.getHeight()); |
| | | root.getChildren().add(endNode); |
| | | ModelLine lineRight = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0); |
| | | recognizeOneBranch(root, |
| | | lineRight, |
| | | null, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | |
| | | return root; |
| | | } |
| | | |
| | | private void recognizeOneBranch(RbdTreeNode parent, |
| | | ModelLine lineRight, // 串联的起始线(右边) |
| | | ModelLine lineLeft, // 串联的结束线(左边) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | ModelLine inLine = lineRight; |
| | | for (;;) { |
| | | ModelLine searchLine = inLine; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | searchLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getName()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | } else if ("start".equals(node.getNodeType())) { |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | parent.getChildren().add(treeNode); |
| | | break; |
| | | } else if ("connect".equals(node.getNodeType())) { |
| | | break; |
| | | } else if ("parallel,vote,switch,bridge".contains(node.getNodeType())) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | ModelNode connect = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | RbdTreeNode treeNode = new RbdTreeNode(); |
| | | treeNode.setId(connect.getId()); |
| | | treeNode.setName(connect.getNodeType()); |
| | | treeNode.setNodeType(connect.getNodeType()); |
| | | treeNode.setPicId(connect.getPicId()); |
| | | treeNode.setMyWidth(connect.getWidth()); |
| | | treeNode.setMyHeight(connect.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | RbdTreeNode subNodeOpe = new RbdTreeNode(); |
| | | subNodeOpe.setAlgorithmType(node.getNodeType()); |
| | | subNodeOpe.setId(UUIDUtil.generateId()); |
| | | counter = vnodeCounter.get("vnodeCounter"); |
| | | subNodeOpe.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNodeOpe.setNodeType("vnode"); |
| | | subNode.getChildren().add(subNodeOpe); |
| | | treeNode = new RbdTreeNode(); |
| | | treeNode.setId(node.getId()); |
| | | treeNode.setName(node.getNodeType()); |
| | | treeNode.setNodeType(node.getNodeType()); |
| | | treeNode.setPicId(node.getPicId()); |
| | | treeNode.setPairStartNodeId(node.getPairStartNodeId()); |
| | | treeNode.setMyWidth(node.getWidth()); |
| | | treeNode.setMyHeight(node.getHeight()); |
| | | subNode.getChildren().add(treeNode); |
| | | recognizeOpeBlock(subNodeOpe, |
| | | node, |
| | | modelNodeList, |
| | | modelLineList, |
| | | vnodeCounter); |
| | | inLine = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(connect.getPicId())).collect(Collectors.toList()).get(0); |
| | | } |
| | | |
| | | if (null != lineLeft) { |
| | | if (inLine.getPicId().equals(lineLeft.getPicId())) break; |
| | | } |
| | | } |
| | | if ("series".equals(parent.getAlgorithmType())) Collections.reverse(parent.getChildren()); |
| | | } |
| | | |
| | | private void recognizeOpeBlock(RbdTreeNode parent, |
| | | ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | Map<String, Integer> vnodeCounter) { |
| | | if ("parallel,vote,switch".contains(parent.getAlgorithmType())) { |
| | | ModelNode searchNode = rightNode; |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(searchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> sortedLines = sortLine(lines, modelNodeList); |
| | | for (ModelLine line : sortedLines) { |
| | | boolean isSeries = isSeriesBranch(rightNode, line, modelNodeList, modelLineList); |
| | | if (isSeries) { |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setAlgorithmType("series"); |
| | | subNode.setId(UUIDUtil.generateId()); |
| | | int counter = vnodeCounter.get("vnodeCounter"); |
| | | subNode.setName("v" + counter); |
| | | counter++; |
| | | vnodeCounter.put("vnodeCounter", counter); |
| | | subNode.setNodeType("vnode"); |
| | | parent.getChildren().add(subNode); |
| | | recognizeOneBranch(subNode, line, null, modelNodeList, modelLineList, vnodeCounter); |
| | | } else { |
| | | recognizeOneBranch(parent, line,null, modelNodeList, modelLineList, vnodeCounter); |
| | | } |
| | | } |
| | | } else if ("bridge".contains(parent.getAlgorithmType())) { |
| | | // 将桥联看成2支路并联+桥接支路的组合 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 按自上而下的顺序排序 |
| | | */ |
| | | private List<ModelLine> sortLine(List<ModelLine> lines, |
| | | List<ModelNode> modelNodeList) { |
| | | for (ModelLine line : lines) { |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | line.setBeginY(node.getPositionY()); |
| | | } |
| | | lines.sort(Comparator.comparing(ModelLine::getBeginY)); |
| | | |
| | | return lines; |
| | | } |
| | | |
| | | private boolean isSingleNode(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode start = modelNodeList.stream().filter(item -> |
| | | "start".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | ModelNode end = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(start.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | line1.getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node2 = modelNodeList.stream().filter(item -> |
| | | line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node1.getPicId().equals(node2.getPicId()) && "node".equals(node1.getNodeType())) result = true; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private boolean isSeriesBranch(ModelNode rightNode, // rbd中的右节点(包括end及4种运算符) |
| | | ModelLine line, // 右节点的入口线 |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList) { |
| | | boolean result = false; |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | ModelLine line1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node1 = modelNodeList.stream().filter(item -> |
| | | line1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node1.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | } else { |
| | | ModelNode node2 = modelNodeList.stream().filter(item -> |
| | | node.getPairStartNodeId().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelLine line2 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node2.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node3 = modelNodeList.stream().filter(item -> |
| | | line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | result = !node3.getPicId().equals(rightNode.getPairStartNodeId()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void setEdgeRouter(JSONArray rbdJsonArray, Map<String, RbdTreeNode> nodeMap) { |
| | | for (int i = 0; i < rbdJsonArray.size(); i++ |
| | | ) { |
| | | JSONObject jsonObject = rbdJsonArray.getJSONObject(i); |
| | | if (jsonObject.get("shape").equals("edge")) { |
| | | String sourceId = JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString(); |
| | | String targetId = JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString(); |
| | | RbdTreeNode sourceNode = nodeMap.get(sourceId); |
| | | RbdTreeNode targetNode = nodeMap.get(targetId); |
| | | if (sourceNode != null) { |
| | | if ("connect".equals(sourceNode.getNodeType()) && !"10000".equals(sourceId)){ |
| | | if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(",")); |
| | | }else{ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"top,bottom".split(",")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(",")); |
| | | } |
| | | } |
| | | } |
| | | if (targetNode != null) { |
| | | if ("parallel,vote".contains(targetNode.getNodeType())){ |
| | | if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split("")); |
| | | }else{ |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split("")); |
| | | JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"top,bottom".split("")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void setNodePositionXY(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | Double x = block.getBlockX() + (block.getBlockWidth() - block.getMyWidth()) / 2; |
| | | Double y = block.getBlockY() + (block.getBlockHeight() - block.getMyHeight()) / 2; |
| | | block.setX(x); |
| | | block.setY(y); |
| | | nodeMap.put(block.getPicId(),block); |
| | | setRbdNodePosition(rbdJsonArray, block.getPicId(), x, y); |
| | | } |
| | | |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) { |
| | | if (block.getNodeType().equals("node")) { |
| | | setNodePositionXY(rbdJsonArray, block,nodeMap); |
| | | } else { |
| | | double blockWidth = block.getBlockWidthNum() * LAYOUT_CELL_SIZE_X; |
| | | double blockHeight = block.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | |
| | | Double descentWidth = block.getDescentWidth(); |
| | | if (descentWidth == null || descentWidth == 0.0) { |
| | | descentWidth = blockWidth; |
| | | } |
| | | Double descentHeight = block.getDescentHeight(); |
| | | if (descentHeight == null || descentHeight == 0.0) { |
| | | descentHeight = blockHeight; |
| | | } |
| | | |
| | | block.setBlockWidth(blockWidth); |
| | | block.setBlockHeight(blockHeight); |
| | | List<RbdTreeNode> children = block.getChildren(); |
| | | |
| | | if (OPE_TYPE_SERIES.equals(block.getAlgorithmType())) { |
| | | Double subBlockX = block.getBlockX(); |
| | | for (RbdTreeNode child : children) { |
| | | |
| | | child.setDescentWidth(blockWidth); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | double selfWidth = child.getBlockWidthNum() * LAYOUT_CELL_SIZE_X * descentWidth / blockWidth; |
| | | child.setBlockWidth(selfWidth); |
| | | child.setBlockHeight(blockHeight); |
| | | |
| | | child.setBlockY(block.getBlockY()); |
| | | child.setBlockX(subBlockX); |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | subBlockX = subBlockX + selfWidth; |
| | | |
| | | } |
| | | } else { |
| | | |
| | | Double subBlockY = block.getBlockY() + (descentHeight - blockHeight) / 2; |
| | | Double firstSubBlockY = subBlockY; |
| | | |
| | | // 设置connect的位置 |
| | | RbdTreeNode connectBlock = new RbdTreeNode(); |
| | | connectBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/width")); |
| | | connectBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/height")); |
| | | connectBlock.setNodeType("connect"); |
| | | connectBlock.setPicId(block.getPairStartNodeId()); |
| | | connectBlock.setBlockX(block.getBlockX()); |
| | | connectBlock.setBlockY(firstSubBlockY); |
| | | connectBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | connectBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, connectBlock, nodeMap); |
| | | |
| | | for (RbdTreeNode child : children) { |
| | | child.setDescentWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setDescentHeight(blockHeight); |
| | | |
| | | child.setBlockWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X); |
| | | child.setBlockHeight(child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y); |
| | | |
| | | child.setBlockX(block.getBlockX() + LAYOUT_CELL_SIZE_X); |
| | | child.setBlockY(subBlockY); |
| | | subBlockY = subBlockY + child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y; |
| | | calcPosition(rbdJsonArray, child, nodeMap); |
| | | } |
| | | |
| | | // 设置运算符的位置 |
| | | RbdTreeNode opeBlock = new RbdTreeNode(); |
| | | |
| | | opeBlock.setPicId(block.getPicId()); |
| | | opeBlock.setNodeType("parallel"); |
| | | opeBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/width")); |
| | | opeBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/height")); |
| | | opeBlock.setBlockX(block.getBlockX() + blockWidth - LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockY(firstSubBlockY); |
| | | opeBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | opeBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, opeBlock, nodeMap); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private RbdTreeNode listToTree(String id, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | |
| | | List<Algorithm> algos = algorithmList.stream().filter(item -> |
| | | id.equals(item.getId().toString())).collect(Collectors.toList()); |
| | | |
| | | RbdTreeNode subNode = new RbdTreeNode(); |
| | | subNode.setId(Convert.toLong(id)); |
| | | ModelNode nd = modelNodeAndVnodeList.stream().filter(item -> |
| | | id.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | subNode.setName(nd.getName()); |
| | | subNode.setNodeType(nd.getNodeType()); |
| | | subNode.setPicId(nd.getPicId()); |
| | | |
| | | if (!"vnode".equals(nd.getNodeType())) { |
| | | subNode.setMyWidth(nd.getWidth()); |
| | | subNode.setMyHeight(nd.getHeight()); |
| | | } |
| | | subNode.setBlockWidthNum(nd.getVnodeCellNumX()); |
| | | subNode.setBlockHeightNum(nd.getVnodeCellNumY()); |
| | | subNode.setPairStartNodeId(nd.getPairStartNodeId()); |
| | | subNode.setPairEndNodeId(nd.getPairEndNodeId()); |
| | | if (algos.size() > 0) { |
| | | Algorithm algo = algos.get(0); |
| | | subNode.setAlgorithmType(algo.getAlgorithmType()); |
| | | String str = algo.getComputerList(); |
| | | String[] ids = str.split(","); |
| | | for (String subId : ids) { |
| | | subNode.getChildren().add(listToTree(subId, algorithmList, modelNodeAndVnodeList)); |
| | | } |
| | | } |
| | | return subNode; |
| | | } |
| | | |
| | | /* |
| | | */ |
| | | |
| | | /** |
| | | * 根据顶层RBD的位置(x,y),自顶向下递归计算各个节点的位置(x,y) |
| | | * |
| | | * @param modelRbd |
| | | * @param algorithmList |
| | | * @param modelNodeAndVnodeList |
| | | */ |
| | | *//* |
| | | |
| | | private void calcLayoutPosition(ModelRbd modelRbd, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | String rbdsonStr = modelRbd.getContent(); |
| | | JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells"); |
| | | Algorithm endAlgo = algorithmList.stream().filter(item -> |
| | |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm topAlgo = algorithmList.stream().filter(item -> |
| | | endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | // 将toNode的中心坐标定为(0,0),反算所有节点的坐标 |
| | | // 1. 计算并设置start的位置 |
| | | double x = -topNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2 - LAYOUT_START_END_SIZE_X; |
| | | double y = -LAYOUT_START_END_SIZE_Y/2; |
| | | setRbdNodePosition(rbdJsonArray, "10000", x, y); |
| | | // 2. 计算并设置节点的位置 |
| | | calcNodeLayoutPosition(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0); |
| | | // 3. 计算并设置end的位置 |
| | | x = topNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2; |
| | | setRbdNodePosition(rbdJsonArray, "20000", x ,y); |
| | | // 将topNode的坐标定为Cell(0,0),反算所有节点的坐标 |
| | | // 1. 计算节点的Cell位置 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0, |
| | | topNode.getVnodeCellNumX(), topNode.getVnodeCellNumY()); |
| | | // 2. 计算节点的x,y坐标位置 |
| | | calcNodeLayoutPosition(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo); |
| | | // 3. 设置start的位置 |
| | | double distance = 200.0; |
| | | double y = (topNode.getPositionCellY() + topNode.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_START_END_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, "10000", 0 - distance, y); |
| | | // 4. 设置end的位置 |
| | | double x = topNode.getVnodeCellNumX() * LAYOUT_CELL_SIZE_X + distance - LAYOUT_START_END_SIZE_X; |
| | | setRbdNodePosition(rbdJsonArray, "20000", x, y); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("cells", rbdJsonArray); |
| | | modelRbd.setContent(jsonObject.toString()); |
| | | } |
| | | */ |
| | | |
| | | // 递归函数 |
| | | /* |
| | | // 递归函数(计算各节点的x,y坐标位置) |
| | | private void calcNodeLayoutPosition(JSONArray rbdJsonArray, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo, |
| | | double x, |
| | | double y) { |
| | | Algorithm algo) { |
| | | // 未使用设备的实际宽、高 |
| | | double x; |
| | | double y; |
| | | if ("node".equals(node.getNodeType())) { |
| | | //设置node(设备节点)布局信息 |
| | | node.setPositionX(x - node.getCellNumX()*LAYOUT_CELL_SIZE_X/2); |
| | | node.setPositionY(y - node.getCellNumY()*LAYOUT_CELL_SIZE_Y/2); |
| | | setRbdNodePosition(rbdJsonArray, node.getPicId().toString(), node.getPositionX(), node.getPositionY()); |
| | | x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_DEVICE_NODE_SIZE_X) / 2; |
| | | y = node.getPositionCellY() * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_DEVICE_NODE_SIZE_Y) / 2; |
| | | node.setPositionX(x); |
| | | node.setPositionY(y); |
| | | setRbdNodePosition(rbdJsonArray, node.getPicId(), node.getPositionX(), node.getPositionY()); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | int sumCellNumX = 0; |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | sumCellNumX += childNode.getVnodeCellNumX(); |
| | | } |
| | | for (int i=0; i<computerNodeListStr.length; i++) { |
| | | int idx = i; |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idx].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | if (0==i) { |
| | | double childNodeX = x - sumCellNumX * LAYOUT_CELL_SIZE_X / 2; |
| | | double childNodeY = y - childNode.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2; |
| | | if ("node".equals(childNode.getNodeType())) { |
| | | childNode.setPositionX(childNodeX); |
| | | childNode.setPositionY(childNodeY); |
| | | setRbdNodePosition(rbdJsonArray, childNode.getPicId().toString(), childNode.getPositionX(), childNode.getPositionY()); |
| | | } else { |
| | | Algorithm childAlgo = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | childNodeX, |
| | | childNodeY); |
| | | } |
| | | } else { |
| | | int idxPre = i - 1; |
| | | ModelNode childNodePre = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idxPre].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | int idxMe = i; |
| | | double childNodeX = childNodePre.getPositionX() + childNodePre.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X; |
| | | double childNodeY = y - childNode.getVnodeCellNumY()*LAYOUT_CELL_SIZE_Y/2; |
| | | if ("node".equals(childNode.getNodeType())) { |
| | | childNode.setPositionX(childNodeX); |
| | | childNode.setPositionY(childNodeY); |
| | | setRbdNodePosition(rbdJsonArray, childNode.getPicId().toString(), childNode.getPositionX(), childNode.getPositionY()); |
| | | } else { |
| | | ModelNode childNodeMe = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idxMe].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | Algorithm childAlgoMe = algorithmList.stream().filter(item -> |
| | | childNodeMe.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgoMe, |
| | | childNodePre.getPositionX() + childNodePre.getVnodeCellNumX() * LAYOUT_CELL_SIZE_X, |
| | | y - childNodeMe.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | int sumCellNumY = 0; |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | sumCellNumY += childNode.getVnodeCellNumY(); |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo); |
| | | } |
| | | for (int i=0; i<computerNodeListStr.length; i++) { |
| | | int idx = i; |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idx].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | if (0==i) { |
| | | double childNodeX = x - childNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2; |
| | | double childNodeY = y - sumCellNumY*LAYOUT_CELL_SIZE_Y/2; |
| | | if ("node".equals(childNode.getNodeType())) { |
| | | childNode.setPositionX(childNodeX); |
| | | childNode.setPositionY(childNodeY); |
| | | setRbdNodePosition(rbdJsonArray, childNode.getPicId(), childNode.getPositionX(), childNode.getPositionY()); |
| | | } else { |
| | | Algorithm childAlgo = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | childNodeX, |
| | | childNodeY); |
| | | } |
| | | } else { |
| | | int idxPre = i - 1; |
| | | ModelNode childNodePre = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idxPre].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | int idxMe = i; |
| | | ModelNode childNodeMe = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[idxMe].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | double childNodeX = x - childNodeMe.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2; |
| | | double childNodeY = childNodePre.getPositionY() + childNodePre.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y; |
| | | if ("node".equals(childNodeMe.getNodeType())) { |
| | | childNodeMe.setPositionX(childNodeX); |
| | | childNodeMe.setPositionY(childNodeY); |
| | | setRbdNodePosition(rbdJsonArray, childNodeMe.getPicId(), childNodeMe.getPositionX(), childNodeMe.getPositionY()); |
| | | } else { |
| | | Algorithm childAlgoMe = algorithmList.stream().filter(item -> |
| | | childNodeMe.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNodeMe, |
| | | childAlgoMe, |
| | | childNodeX, |
| | | childNodeY); |
| | | } |
| | | } |
| | | if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) { |
| | | // 设置connect的位置 |
| | | x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_CONNECT_SIZE_X) / 2; |
| | | y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_CONNECT_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, node.getPairStartNodeId(), x, y); |
| | | // 设置运算符的位置 |
| | | x = (node.getPositionCellX() + node.getVnodeCellNumX() - 1) * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_OPE_NODE_SIZE_X) / 2; |
| | | y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_OPE_NODE_SIZE_Y) / 2; |
| | | setRbdNodePosition(rbdJsonArray, node.getPicId(), x, y); |
| | | } |
| | | break; |
| | | case OPE_TYPE_BRIDGE: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 递归函数(计算各节点的Cell位置,以左上角为Cell位置0,0) |
| | | private void calcNodeLayoutPositionCell(JSONArray rbdJsonArray, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo, |
| | | double originCellX, |
| | | double originCellY, |
| | | double maxX, |
| | | double maxY) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | //设置node(设备节点)Cell位置 |
| | | double width = LAYOUT_DEVICE_NODE_SIZE_X * maxX; |
| | | double hight = LAYOUT_DEVICE_NODE_SIZE_Y * maxY; |
| | | double x = originCellX + (width - LAYOUT_DEVICE_NODE_SIZE_X) / 2; |
| | | double y = originCellY + (hight - LAYOUT_DEVICE_NODE_SIZE_Y) / 2; |
| | | node.setPositionCellX(x); |
| | | node.setPositionCellY(y); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | double preNodeCellX = 0.0; |
| | | double preNodeCellY = 0.0; |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) { |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | originCellX + preNodeCellX, |
| | | originCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY() |
| | | ); |
| | | preNodeCellX += childNode.getVnodeCellNumX(); |
| | | } else { |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo, |
| | | originCellX + 1, |
| | | originCellY + preNodeCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY()); |
| | | preNodeCellY += childNode.getVnodeCellNumY(); |
| | | } |
| | | } |
| | | */ |
| | | /* |
| | | // 设置运算符的Cell位置 |
| | | if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) { |
| | | node.setPositionCellX(originCellX); |
| | | } else { |
| | | node.setPositionCellX(originCellX + node.getVnodeCellNumX() - 1); |
| | | } |
| | | node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2); |
| | | *//* |
| | | |
| | | // 需节点代表整个逻辑单元,因此其坐标为originCellX和originCellX |
| | | node.setPositionCellX(originCellX); |
| | | node.setPositionCellY(originCellX); |
| | | break; |
| | | case OPE_TYPE_BRIDGE: |
| | | */ |
| | | /* |
| | | ModelNode node1 = modelNodeAndVnodeList.stream().filter(item -> |
| | | computerNodeListStr[0].equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | ModelNode node2 = modelNodeAndVnodeList.stream().filter(item -> |
| | |
| | | int secondRowCellNumY = node3.getVnodeCellNumY(); |
| | | // 1.3 计算第三行两个节点的高度 |
| | | int thirdRowCellNumY = Math.max(node4.getVnodeCellNumY(), node5.getVnodeCellNumY()); |
| | | int totalCellNumY = firstRowCellNumY + secondRowCellNumY + thirdRowCellNumY; |
| | | // int totalCellNumY = firstRowCellNumY + secondRowCellNumY + thirdRowCellNumY; |
| | | // 2. 计算三行各节点的坐标 |
| | | // 2.1 计算第一行两个节点的坐标 |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node1, |
| | | algo1, |
| | | x - (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2, |
| | | y - (totalCellNumY-firstRowCellNumY+node1.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | originCellX + 1, |
| | | originCellY); |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node2, |
| | | algo2, |
| | | x + (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2, |
| | | y - (totalCellNumY-firstRowCellNumY+node2.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2); |
| | | originCellX + 1 + node1.getPositionCellX(), |
| | | originCellY); |
| | | // 2.2 计算第二行桥联节点的坐标 |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node2, |
| | | algo2, |
| | | x - node3.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2, |
| | | y - (totalCellNumY/2-firstRowCellNumY)*LAYOUT_CELL_SIZE_Y); |
| | | node3, |
| | | algo3, |
| | | originCellX + 1, |
| | | originCellY + firstRowCellNumY); |
| | | // 2.3 计算第三行两个节点的坐标 |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node1, |
| | | algo1, |
| | | x - (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2, |
| | | y - (totalCellNumY-firstRowCellNumY+node1.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2); |
| | | calcNodeLayoutPosition(rbdJsonArray, |
| | | node4, |
| | | algo4, |
| | | originCellX + 1, |
| | | originCellY + firstRowCellNumY + secondRowCellNumY); |
| | | calcNodeLayoutPositionCell(rbdJsonArray, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | node2, |
| | | algo2, |
| | | x + (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2, |
| | | y - (totalCellNumY-firstRowCellNumY+node2.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2); |
| | | node5, |
| | | algo5, |
| | | originCellX + 1 + node4.getPositionCellX(), |
| | | originCellY + firstRowCellNumY + secondRowCellNumY); |
| | | // 2.4 计算桥联运算符的坐标 |
| | | // 2.5 计算左侧配对的connect的坐标 |
| | | node.setPositionCellX(originCellX + 1); |
| | | node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2); |
| | | *//* |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | */ |
| | | private void setRbdNodePosition(JSONArray rbdJsonArray, |
| | | String id, |
| | | double x, |
| | |
| | | } |
| | | } |
| | | |
| | | private Double getRbdNodeInfo(JSONArray rbdJsonArray, |
| | | String picId, |
| | | String path) { |
| | | for (int i = 0; i < rbdJsonArray.size(); i++) { |
| | | JSONObject jsonObject = rbdJsonArray.getJSONObject(i); |
| | | if (picId.equals(jsonObject.get("id").toString())) { |
| | | return Convert.toDouble(JsonUtils2.getJsonValueByPath(jsonObject, path.split("/"))); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 自底向上递归合计出整个RBD的大小(横向及纵向所占单元格的数量) |
| | | * |
| | | * @param modelRbd |
| | | * @param algorithmList |
| | | * @param modelNodeAndVnodeList |
| | |
| | | |
| | | // 递归函数 |
| | | private void calcNodeLayoutSize(List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo) { |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode node, |
| | | Algorithm algo) { |
| | | if ("node".equals(node.getNodeType())) { |
| | | //设置node(设备节点)布局信息 |
| | | node.setWidth(LAYOUT_DEVICE_NODE_SIZE_X); |
| | | node.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y); |
| | | // node.setWidth(LAYOUT_DEVICE_NODE_SIZE_X); |
| | | // node.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y); |
| | | node.setCellNumX(LAYOUT_CELL_NUM_NODE_X); |
| | | node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y); |
| | | node.setVnodeCellNumX(node.getCellNumX()); |
| | | node.setVnodeCellNumY(node.getCellNumY()); |
| | | } else if ("vnode".equals(node.getNodeType())) { |
| | | // 1. 设置vnode(运算节点)布局信息(其实串联没有运算符,不需要设置,但是设置了也没有坏处,所有不作区分) |
| | | node.setWidth(LAYOUT_OPE_NODE_SIZE_X); |
| | | node.setHeight(LAYOUT_OPE_NODE_SIZE_Y); |
| | | // 1. 设置vnode(运算节点)布局信息(其实串联没有运算符,不需要设置,但是设置了也没有坏处,所以不作区分) |
| | | // node.setWidth(LAYOUT_OPE_NODE_SIZE_X); |
| | | // node.setHeight(LAYOUT_OPE_NODE_SIZE_Y); |
| | | node.setCellNumX(LAYOUT_CELL_NUM_NODE_X); |
| | | node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y); |
| | | |
| | |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode childNode = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | if ("node".equals(childNode.getNodeType())) { |
| | | childNode.setWidth(LAYOUT_DEVICE_NODE_SIZE_X); |
| | | childNode.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y); |
| | | childNode.setCellNumX(LAYOUT_CELL_NUM_NODE_X); |
| | | childNode.setCellNumY(LAYOUT_CELL_NUM_NODE_Y); |
| | | childNode.setVnodeCellNumX(node.getCellNumX()); |
| | | childNode.setVnodeCellNumY(node.getCellNumY()); |
| | | } else { |
| | | Algorithm childAlgo = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | calcNodeLayoutSize(algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo); |
| | | } |
| | | List<Algorithm> childAlgos = algorithmList.stream().filter(item -> |
| | | childNode.getId().equals(item.getId())).collect(Collectors.toList()); |
| | | Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null; |
| | | calcNodeLayoutSize(algorithmList, |
| | | modelNodeAndVnodeList, |
| | | childNode, |
| | | childAlgo); |
| | | } |
| | | // 2.2 设置虚节点总的布局信息到运算节点中 |
| | | setVnodeLayoutNum(computerNodeListStr, modelNodeAndVnodeList, node, algo); |
| | |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | switch (algo.getAlgorithmType()) { |
| | | case OPE_TYPE_SERIES: |
| | | numX += childNode.getCellNumX(); |
| | | numY = childNode.getCellNumY() > numY ? childNode.getCellNumY() : numY; |
| | | numX += childNode.getVnodeCellNumX(); |
| | | numY = childNode.getVnodeCellNumY() > numY ? childNode.getVnodeCellNumY() : numY; |
| | | break; |
| | | case OPE_TYPE_PARALLEL: |
| | | case OPE_TYPE_SWITCH: |
| | | case OPE_TYPE_VOTE: |
| | | numX = childNode.getCellNumX() > numX ? childNode.getCellNumX() : numX; |
| | | numY += childNode.getCellNumY(); |
| | | numX = childNode.getVnodeCellNumX() > numX ? childNode.getVnodeCellNumX() : numX; |
| | | numY += childNode.getVnodeCellNumY(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) { |
| | | // 设置connect的大小 |
| | | ModelNode connect = modelNodeAndVnodeList.stream().filter(item -> |
| | | vnode.getPairStartNodeId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | connect.setWidth(LAYOUT_CONNECT_SIZE_X); |
| | | connect.setHeight(LAYOUT_CONNECT_SIZE_Y); |
| | | connect.setCellNumX(LAYOUT_CELL_NUM_CONNECT_X); |
| | | connect.setCellNumY(LAYOUT_CELL_NUM_CONNECT_Y); |
| | | numX += connect.getCellNumX(); |
| | | || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType()) |
| | | || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) { |
| | | // 加上connect的大小 |
| | | numX += LAYOUT_CELL_NUM_CONNECT_X; |
| | | numX += vnode.getCellNumX(); |
| | | } |
| | | // 2. 计算桥联 |
| | |
| | | int numY3 = node4.getCellNumY() > node5.getCellNumY() ? node4.getCellNumY() : node5.getCellNumY(); |
| | | numX = Math.max(Math.max(numX1, numX2), numX3); |
| | | numY = numY1 + numY2 + numY3; |
| | | // 2.4 设置connect的大小 |
| | | ModelNode connect = modelNodeAndVnodeList.stream().filter(item -> |
| | | vnode.getPairStartNodeId().equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | connect.setWidth(LAYOUT_CONNECT_SIZE_X); |
| | | connect.setHeight(LAYOUT_CONNECT_SIZE_Y); |
| | | connect.setCellNumX(LAYOUT_CELL_NUM_CONNECT_X); |
| | | connect.setCellNumY(LAYOUT_CELL_NUM_CONNECT_Y); |
| | | numX += connect.getCellNumX(); |
| | | // 2.4 加上connect的大小 |
| | | numX += LAYOUT_CELL_NUM_CONNECT_X; |
| | | numX += vnode.getCellNumX(); |
| | | } |
| | | vnode.setVnodeCellNumX(numX); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean analyze(ModelRbd modelRbd) { |
| | | boolean result = true; |
| | | if (modelRbd==null) return result; |
| | | if (modelRbd == null) return result; |
| | | Long modelId = modelRbd.getId(); |
| | | result = analyzeRbd(modelRbd, true); |
| | | return result; |
| | |
| | | List<ModelLine> modelLineList) { |
| | | List<ModelNode> nodesToAdd = new ArrayList<>(); |
| | | List<ModelLine> linesToAdd = new ArrayList<>(); |
| | | for (ModelNode node: modelNodeList) { |
| | | for (ModelNode node : modelNodeList) { |
| | | List<ModelLine> inLineList = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()); |
| | | if ("node".equals(node.getNodeType()) && |
| | | StringUtils.isNotBlank(node.getNodeTypeExt()) && |
| | | inLineList.size() > 1) { |
| | | // 旁联or表决 |
| | | ModelNode nodeNew = new ModelNode(); |
| | | ModelNode nodeNew = new ModelNode(); |
| | | Long nodeNewId = UUIDUtil.generateId(); |
| | | nodeNew.setId(nodeNewId); |
| | | nodeNew.setPicId(nodeNewId.toString()); |
| | |
| | | lineNew.setEndCell(node.getPicId()); |
| | | linesToAdd.add(lineNew); |
| | | |
| | | for(ModelLine line: inLineList){ |
| | | for (ModelLine line : inLineList) { |
| | | line.setEndCell(nodeNewId.toString()); |
| | | } |
| | | } |
| | |
| | | List<ModelNode> modelNodeAndVnodeList) { |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0); |
| | | if (endNode.getInLineNum()!=1) return false; |
| | | if (endNode.getInLineNum() != 1) return false; |
| | | |
| | | ModelLine lineToEnd = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(endNode.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode node = modelNodeList.stream().filter(item -> |
| | | lineToEnd.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node.getInLineNum()!=1 || node.getOutLineNum()!=1) return false; |
| | | if (node.getInLineNum() != 1 || node.getOutLineNum() != 1) return false; |
| | | |
| | | ModelLine lineToNode = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode startNode = modelNodeList.stream().filter(item -> |
| | | lineToNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!"start".equals(startNode.getNodeType()) || startNode.getOutLineNum()!=1) return false; |
| | | if (!"start".equals(startNode.getNodeType()) || startNode.getOutLineNum() != 1) return false; |
| | | |
| | | // 删除节点及连线 |
| | | modelLineList.remove(lineToEnd); |
| | |
| | | algorithm.setAlgorithmType(endNode.getNodeType()); |
| | | algorithm.setComputerList(node.getId().toString()); |
| | | algorithm.setObjectList(node.getName()); |
| | | algorithm.setStep(algorithmList.size()==0 ? 0 : algorithmList.get(algorithmList.size()-1).getStep()+1); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 新增结束的虚节点 |
| | |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | vnode.setName("v"+algorithm.getStep()); |
| | | vnode.setName("v" + algorithm.getStep()); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | |
| | | return true; |
| | |
| | | boolean hasSimplified) { |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size()==0) return hasSimplified; |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | if (startNode.getInLineNum()!=1) continue; |
| | | if (startNode.getInLineNum() != 1) continue; |
| | | |
| | | List<ModelNode> result = new ArrayList<>(); |
| | | if (!"end".equals(startNode.getNodeType())) result.add(startNode); |
| | | seekPathSeries(modelNodeList, modelLineList, startNode, result); |
| | | if (result.size()<2) continue; |
| | | if (result.size() < 2) continue; |
| | | |
| | | ModelNode endNode = result.get(result.size()-1); |
| | | if ("start,parallel,switch,vote,bridge".contains(endNode.getNodeType()) || endNode.getOutLineNum()!=1) { |
| | | ModelNode endNode = result.get(result.size() - 1); |
| | | if ("start,parallel,switch,vote,bridge".contains(endNode.getNodeType()) || endNode.getOutLineNum() != 1) { |
| | | result.remove(endNode); |
| | | } |
| | | List<ModelNode> realSeriesNodes = result.stream().filter(item -> |
| | | !"connect".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (realSeriesNodes.size()<1) { |
| | | if (realSeriesNodes.size() < 1) { |
| | | if (result.size() < 2) continue; |
| | | // 替换成连线 |
| | | replaceToLineSeries(modelNodeList, modelLineList, result); |
| | | } else if (realSeriesNodes.size()==1) { |
| | | } else if (realSeriesNodes.size() == 1) { |
| | | if (result.size() < 2) continue; // path上只有该产品节点(node/vnode)自己,无需做什么 |
| | | // 将path替换成该节点 |
| | | replaceToTheNodeSeries(modelNodeList, modelLineList, |
| | |
| | | List<ModelNode> path) { |
| | | // 获取path的起点的出口线 |
| | | ModelNode finalNodeStart = path.get(0); |
| | | ModelNode finalNodeEnd = path.get(path.size()-1); |
| | | ModelNode finalNodeEnd = path.get(path.size() - 1); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList()); |
| | | |
| | | // 删除path上的所有中间连线及path的结束点以外的节点 |
| | | for (int i=0; i<path.size(); i++) { |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i < path.size() - 1) { |
| | | // 将入口线删除 |
| | |
| | | } |
| | | |
| | | private void replaceToTheNodeSeries(List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<ModelNode> path, |
| | | ModelNode theNode) { |
| | | List<ModelLine> modelLineList, |
| | | List<ModelNode> path, |
| | | ModelNode theNode) { |
| | | // 获取path的起点的出口线 |
| | | ModelNode finalNodeStart = path.get(0); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList()); |
| | | // 获取path的结束点的入口线 |
| | | ModelNode finalNodeEnd = path.get(path.size()-1); |
| | | ModelNode finalNodeEnd = path.get(path.size() - 1); |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNodeEnd.getPicId())).collect(Collectors.toList()); |
| | | |
| | | // 删除path上的所有中间连线及theNode以外的节点 |
| | | for (int i=0; i<path.size(); i++) { |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i < path.size() - 1) { |
| | | // 将入口线删除 |
| | |
| | | algorithm.setAlgorithmType("series"); |
| | | algorithm.setComputerList(computerList.get(0)); |
| | | algorithm.setObjectList(computerList.get(1)); |
| | | algorithm.setStep(algorithmList.size()==0 ? 0 : algorithmList.get(algorithmList.size()-1).getStep()+1); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 新增虚节点 |
| | |
| | | vnode.setPicId(id.toString()); |
| | | vnode.setModelId(modelId); |
| | | vnode.setNodeType("vnode"); |
| | | vnode.setName("v"+algorithm.getStep()); |
| | | vnode.setName("v" + algorithm.getStep()); |
| | | vnode.setPositionX(path.get(0).getPositionX()); |
| | | vnode.setPositionY(path.get(0).getPositionY()); |
| | | modelNodeList.add(vnode); |
| | | modelNodeAndVnodeList.add(vnode); |
| | | |
| | | // 将path替换为该虚节点 |
| | | for (int i=0; i<path.size(); i++) { |
| | | for (int i = 0; i < path.size(); i++) { |
| | | ModelNode finalNode = path.get(i); |
| | | if (i==0) { |
| | | if (i == 0) { |
| | | // 将该节点的出口线改为连接到虚节点 |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(inLines); |
| | | } |
| | | if (i==path.size()-1) { |
| | | if (i == path.size() - 1) { |
| | | // 将该节点的入口线改为连接到虚节点 |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | |
| | | if (isBridgeUpperLine(inLine, modelLineList) || isBridgeLowerLine(inLine, modelLineList)) return; |
| | | List<ModelNode> nodes = modelNodeList.stream().filter(item -> |
| | | inLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()); |
| | | if (0==nodes.size()) return; // 到桥联中间节点的线的起点不是Node,而是Line,所以获取的起点数可能为0 |
| | | if (0 == nodes.size()) return; // 到桥联中间节点的线的起点不是Node,而是Line,所以获取的起点数可能为0 |
| | | ModelNode pathNode = nodes.get(0); |
| | | result.add(pathNode); |
| | | if (pathNode.getOutLineNum()!=1 || pathNode.getInLineNum()!=1) return; |
| | | if (pathNode.getOutLineNum() != 1 || pathNode.getInLineNum() != 1) return; |
| | | if ("parallel,switch,vote,bridge".contains(pathNode.getNodeType())) return; |
| | | seekPathSeries(modelNodeList, modelLineList, pathNode, result); |
| | | } |
| | |
| | | boolean hasSimplifiedMe = false; |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size()==0) return hasSimplified; |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | if (startNode.getInLineNum()<2) continue; |
| | | if (startNode.getInLineNum() < 2) continue; |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()); |
| | | hasSimplifiedMe = simplifyParallelGroup(modelId, modelNodeList, modelLineList, |
| | |
| | | } |
| | | |
| | | private boolean simplifyParallelGroup(Long modelId, |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | List<ModelLine> lines) { |
| | | List<ModelNode> modelNodeList, |
| | | List<ModelLine> modelLineList, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | List<ModelLine> lines) { |
| | | boolean hasSimplified = false; |
| | | List<List<ModelNode>> pathList = new ArrayList<>(); |
| | | for (ModelLine line : lines) { |
| | |
| | | Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = groupingPathByEndNode(pathList); |
| | | for (Map.Entry<ModelNode, List<List<ModelNode>>> entry : endNodePathsMap.entrySet()) { |
| | | List<List<ModelNode>> pathOneGroup = entry.getValue(); |
| | | if (pathOneGroup.size()>1) { |
| | | if (pathOneGroup.size() > 1) { |
| | | List<ModelNode> branchNodeList = new ArrayList<>(); |
| | | ModelNode endNode = getBranchNodesOneParallel(pathOneGroup, branchNodeList); |
| | | if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size()==lines.size()) { |
| | | if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size() == lines.size()) { |
| | | // 替换成虚节点 |
| | | modelNodeAndVnodeList.add(startNode); |
| | | replaceToVnode("parallel", modelId, modelNodeList, modelLineList, |
| | |
| | | item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | if (inLines.size()!=1 || outLines.size()!=1) return path; |
| | | if (inLines.size() != 1 || outLines.size() != 1) return path; |
| | | ModelLine lineToBranchNode = inLines.get(0); |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | |
| | | private Map<ModelNode, List<List<ModelNode>>> groupingPathByEndNode(List<List<ModelNode>> pathList) { |
| | | Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = new HashMap<>(); |
| | | for (List<ModelNode> path : pathList) { |
| | | ModelNode endNode = path.get(path.size()-1); |
| | | ModelNode endNode = path.get(path.size() - 1); |
| | | if (endNodePathsMap.containsKey(endNode)) { |
| | | endNodePathsMap.get(endNode).add(path); |
| | | } else { |
| | |
| | | } |
| | | |
| | | private ModelNode getBranchNodesOneParallel(List<List<ModelNode>> paths, |
| | | List<ModelNode> branchNodeList) { |
| | | List<ModelNode> branchNodeList) { |
| | | ModelNode endNode = null; |
| | | for (List<ModelNode> path : paths) { |
| | | branchNodeList.add(path.get(0)); |
| | | endNode = path.get(path.size()-1); |
| | | endNode = path.get(path.size() - 1); |
| | | } |
| | | return endNode; |
| | | } |
| | |
| | | boolean hasSimplifiedMe = false; |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "bridge".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size()==0) return hasSimplified; |
| | | if (startNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode startNode : startNodes) { |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()); |
| | | if (lines.size()<2) continue; |
| | | if (lines.size() < 2) continue; |
| | | List<ModelLinePairDto> linePairs = getLinePairs(lines); |
| | | for (ModelLinePairDto linePair : linePairs) { |
| | | hasSimplifiedMe = simplifyBridgeOneLinePair(modelId, modelNodeList, modelLineList, |
| | |
| | | linePair.getLine1().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | ModelNode nodeTmp2 = modelNodeList.stream().filter(item -> |
| | | linePair.getLine2().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (nodeTmp1.getInLineNum()!=1 || nodeTmp1.getOutLineNum()!=1) return false; |
| | | if (nodeTmp2.getInLineNum()!=1 || nodeTmp2.getOutLineNum()!=1) return false; |
| | | if (nodeTmp1.getInLineNum() != 1 || nodeTmp1.getOutLineNum() != 1) return false; |
| | | if (nodeTmp2.getInLineNum() != 1 || nodeTmp2.getOutLineNum() != 1) return false; |
| | | ModelNode finalNode = nodeTmp1; |
| | | ModelLine lineToNodeTmp1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()).get(0); |
| | |
| | | finalLine3.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (!node3Candidate1.getId().equals(node3Candidate2.getId())) return false; |
| | | node3 = node3Candidate1; |
| | | if (node3.getInLineNum()!=1 || node3.getOutLineNum()!=1) return false; |
| | | if (node3.getInLineNum() != 1 || node3.getOutLineNum() != 1) return false; |
| | | ModelLine finalLine4 = line1To2; |
| | | node1 = modelNodeList.stream().filter(item -> |
| | | finalLine4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node1.getInLineNum()!=1 || node1.getOutLineNum()!=1) return false; |
| | | if (node1.getInLineNum() != 1 || node1.getOutLineNum() != 1) return false; |
| | | ModelLine finalLine5 = line4To5; |
| | | node4 = modelNodeList.stream().filter(item -> |
| | | finalLine5.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | if (node4.getInLineNum()!=1 || node4.getOutLineNum()!=1) return false; |
| | | if (node4.getInLineNum() != 1 || node4.getOutLineNum() != 1) return false; |
| | | ModelNode finalNode3 = node1; |
| | | ModelLine lineTo1 = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode3.getPicId())).collect(Collectors.toList()).get(0); |
| | |
| | | // 找出所有2根线的组合 |
| | | private List<ModelLinePairDto> getLinePairs(List<ModelLine> lines) { |
| | | List<ModelLinePairDto> linePairs = new ArrayList<>(); |
| | | for (int i=0; i<lines.size()-1; i++) { |
| | | for (int j=i+1; j<lines.size(); j++) { |
| | | for (int i = 0; i < lines.size() - 1; i++) { |
| | | for (int j = i + 1; j < lines.size(); j++) { |
| | | ModelLinePairDto linePair = new ModelLinePairDto(); |
| | | linePair.setLine1(lines.get(i)); |
| | | linePair.setLine2(lines.get(j)); |
| | |
| | | boolean hasSimplified) { |
| | | List<ModelNode> opNodes = modelNodeList.stream().filter(item -> |
| | | operator.equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (opNodes.size()==0) return hasSimplified; |
| | | if (opNodes.size() == 0) return hasSimplified; |
| | | |
| | | for (ModelNode opNode : opNodes) { |
| | | List<ModelLine> lines = modelLineList.stream().filter(item -> |
| | |
| | | algorithm.setComputerList(computerList.get(0)); |
| | | algorithm.setObjectList(computerList.get(1)); |
| | | if ("vote".equals(type)) algorithm.setVoteNum(startNode.getVoteNum()); |
| | | algorithm.setStep(algorithmList.size()==0 ? 0 : algorithmList.get(algorithmList.size()-1).getStep()+1); |
| | | algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1); |
| | | algorithmList.add(algorithm); |
| | | |
| | | // 替换为虚节点 |
| | |
| | | } |
| | | startNode.setId(id); |
| | | startNode.setNodeType("vnode"); |
| | | startNode.setName("v"+algorithm.getStep()); |
| | | startNode.setName("v" + algorithm.getStep()); |
| | | |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | |
| | | List<ModelLine> modelLineList, |
| | | ModelLine line, |
| | | List<ModelNode> branchNodeList |
| | | ) { |
| | | ) { |
| | | ModelNode branchNode = modelNodeList.stream().filter(item -> |
| | | line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList()); |
| | | if (inLines.size()!=1 || outLines.size()!=1) return null; |
| | | if (inLines.size() != 1 || outLines.size() != 1) return null; |
| | | ModelLine lineToBranchNode = inLines.get(0); |
| | | ModelNode endNode = modelNodeList.stream().filter(item -> |
| | | lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0); |
| | |
| | | modelLine.setBeginCell(JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString()); |
| | | modelLine.setEndCell(JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString()); |
| | | modelLineList.add(modelLine); |
| | | } else if ("image".equals(shape)){ |
| | | } else if ("image".equals(shape)) { |
| | | ModelNode modelNode = new ModelNode(); |
| | | modelNode.setId(UUIDUtil.generateId()); |
| | | modelNode.setModelId(modelId); |
| | |
| | | modelNode.setNodeType(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeType".split("/")).toString()); |
| | | modelNode.setPositionX(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")).toString())); |
| | | modelNode.setPositionY(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")).toString())); |
| | | modelNode.setWidth(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString())); |
| | | modelNode.setHeight(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString())); |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/voteNum".split("/")); |
| | | if (jsonValue!=null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | modelNode.setVoteNum(Integer.valueOf(jsonValue.toString())); |
| | | } |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/startNodeId".split("/")); |
| | | if (jsonValue!=null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | modelNode.setPairStartNodeId(jsonValue.toString()); |
| | | } |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/endNodeId".split("/")); |
| | | if (jsonValue!=null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | modelNode.setPairEndNodeId(jsonValue.toString()); |
| | | } |
| | | if ("node".equals(modelNode.getNodeType())) { |
| | | if ("dashedBox".equals(modelNode.getNodeType())) { |
| | | modelNode.setNodeType("node"); |
| | | } else if ("node".equals(modelNode.getNodeType())) { |
| | | ProductImg productImg = new ProductImg(); |
| | | String dataId = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString(); |
| | | modelNode.setDataId(Long.valueOf(dataId)); |
| | | modelNode.setNodeTypeExt(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeTypeExt".split("/")).toString()); |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")); |
| | | modelNode.setName(jsonValue==null ? "" : jsonValue.toString()); |
| | | modelNode.setName(jsonValue == null ? "" : jsonValue.toString()); |
| | | |
| | | productImg.setDataId(dataId); |
| | | String productType = JsonUtils2.getJsonValueByPath(jsonObject, "data/productType".split("/")).toString(); |
| | |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/reliabDistribType".split("/")); |
| | | if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) { |
| | | productImg.setReliabDistribType(Integer.valueOf(jsonValue.toString())); |
| | | if (3==productImg.getReliabDistribType()) { |
| | | if (3 == productImg.getReliabDistribType()) { |
| | | // 二项分布 |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/simulatTimes".split("/")); |
| | | if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) { |