示例#1
0
    def _UpdateWeight(self, cord, colIndex, rowIndex, dim, xFactor, yFactor):
        newColIndex = colIndex + xFactor
        newRowIndex = rowIndex + yFactor

        if (newColIndex) >= dim.width:
            return
        if (newColIndex) < 0:
            return
        if (newRowIndex) >= dim.height:
            return
        if (newRowIndex) < 0:
            return
        # we try to go to Cover -not connected
        NextCord = Point.ToGridNode(newColIndex, newRowIndex, dim.height)
        if self._Csvreader.Matrix.item(
            (colIndex, rowIndex
             )) == self._Consts.SafePointValue or self._Csvreader.Matrix.item(
                 (newColIndex, newRowIndex)) == self._Consts.SafePointValue:
            # we set connectivity
            self._Graph.add_edge(
                NextCord, cord, weight=self._Consts.ConnectedGraphVertexWeight)
        else:
            # Alt Diff Issue
            AltDiff = abs(
                self._Csvreader.Matrix.item((colIndex, rowIndex)) -
                self._Csvreader.Matrix.item((newColIndex, newRowIndex)))
            if AltDiff >= self._Consts.MaximumAltDif:
                return

            # we set connectivity
            self._Graph.add_edge(
                NextCord, cord, weight=self._Consts.ConnectedGraphVertexWeight)
示例#2
0
    def _buildGraph(self):
        dim = self._getMapDim()
        labels = {}
        self._Graph = nx.Graph()
        for colIndex in range(0, dim.width):
            for rowIndex in range(0, dim.height):
                cord = Point.ToGridNode(colIndex, rowIndex, dim.height)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, 0, 0)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, 0, 1)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, 0, -1)

                self._UpdateWeight(cord, colIndex, rowIndex, dim, -1, 0)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, -1, 1)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, -1, -1)

                self._UpdateWeight(cord, colIndex, rowIndex, dim, 1, 0)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, 1, -1)
                self._UpdateWeight(cord, colIndex, rowIndex, dim, 1, 1)
                self._Graph.nodes[cord]["X"] = colIndex
                self._Graph.nodes[cord]["Y"] = rowIndex
                labels[cord] = "({0}-{1})".format(rowIndex, colIndex)
        nx.relabel_nodes(self._Graph, labels)