def primaryLoop(self): if not self.startNodeEdit.text(): startNode = self.items[0][0].data(0) else: startNode = int(self.startNodeEdit.text().strip('V')) paths = self.__graph.findPrimaryLoop(startNode) if len(paths) == 0: self.dataModel.clear() QMessageBox.information( None, self._tr("BezierShowDataWidget", "对不起"), self._tr("BezierShowDataWidget", "没有符合条件的回路")) return False self.rowCount = len(paths) self.dataModel.setRowCount(self.rowCount) self.dataModel.setColumnCount(self.columnCount) self.dataModel.clear() for i in range(self.rowCount): for j in range(len(paths[i])): if str(type(paths[i][j])).find("Edge") >= 0: item = QStandardItem(f'e{paths[i][j].id()}') self.dataModel.setItem(i, j, item) item.setFlags(Qt.NoItemFlags) elif str(type(paths[i][j])).find("Vertex") >= 0: item = QStandardItem(f'V{paths[i][j].id()}') item.setFlags(Qt.NoItemFlags) self.dataModel.setItem(i, j, item) return True
def shortestPath(self): if not self.startNodeEdit.text(): startNode = self.items[0][0].data(0) else: startNode = int(self.startNodeEdit.text().strip('V')) paths = [] for node in self.scene.singleItems(BezierNode): path = self.__graph.shortestPath(startNode, node.data(0)) if path is not None and len(path) > 2 and path not in paths: paths.append(path) if len(paths) == 0: self.dataModel.clear() QMessageBox.information( None, self._tr("BezierShowDataWidget", "对不起"), self._tr("BezierShowDataWidget", "没有符合条件的路径")) return False self.rowCount = len(paths) self.dataModel.setRowCount(self.rowCount) self.dataModel.setColumnCount(self.columnCount) self.dataModel.clear() for i in range(self.rowCount): for j in range(len(paths[i])): if str(type(paths[i][j])).find("Edge") >= 0: item = QStandardItem(f'e{paths[i][j].id()}') item.setFlags(Qt.NoItemFlags) self.dataModel.setItem(i, j, item) elif str(type(paths[i][j])).find("Vertex") >= 0: item = QStandardItem(f'V{paths[i][j].id()}') item.setFlags(Qt.NoItemFlags) self.dataModel.setItem(i, j, item) return True
def easyPath(self): if not self.startNodeEdit.text(): startNode = self.iniStartEnd(self.items)[0] else: startNode = int(self.startNodeEdit.text().strip('V')) if not self.endNodeEdit.text(): endNode = self.iniStartEnd(self.items)[1] else: endNode = int(self.endNodeEdit.text().strip('V')) paths = self.__graph.findSimplePathway(startNode, endNode) if len(paths) == 0: self.dataModel.clear() QMessageBox.information( None, "Sorry", self._tr("BezierShowDataWidget", "没有符合条件的通路")) return False self.rowCount = len(paths) self.dataModel.setRowCount(self.rowCount) self.dataModel.setColumnCount(self.columnCount) self.dataModel.clear() for i in range(self.rowCount): for j in range(len(paths[i])): if str(type(paths[i][j])).find("Edge") >= 0: item = QStandardItem(f'e{paths[i][j].id()}') item.setFlags(Qt.NoItemFlags) self.dataModel.setItem(i, j, item) elif str(type(paths[i][j])).find("Vertex") >= 0: item = QStandardItem(f'V{paths[i][j].id()}') item.setFlags(Qt.NoItemFlags) self.dataModel.setItem(i, j, item) return True
def do_searchBtnShortestPath(self): start = int(self.startNodeEdit.text().strip('V')) if start > self.__graph.nodeNumber() - 1: QMessageBox.information(None, self._tr("BezierShowDataWidget", "对不起"), self._tr("BezierShowDataWidget", "超出上限")) return self.shortestPath()