コード例 #1
0
ファイル: ReferenceGraphComplex.py プロジェクト: sibrun/GH
    def _load_basis_g6(self):
        """Load the reference basis list from the reference file.

        :Note: The implementation depends on the reference data.

        :return: List of graph6 strings representing the reference basis.
        :rtype: list(str)
        :raise StoreLoad.FileNotFoundError: If the reference basis file is not found.
        """
        if not self.exists_basis_file():
            raise StoreLoad.FileNotFoundError(
                "%s: Reference basis file not found" % str(self))
        return StoreLoad.load_string_list(self.basis_file_path)
コード例 #2
0
    def _load_basis_g6(self):
        """Load the basis from the basis file.

        Raises an exception if no basis file found or if the dimension in the header of the basis file doesn't
        correspond to the dimension of the basis.

        :return: List of graph6 strings of canonically labeled graphs building a basis of the
            vector space.
        :rtype: list(str)
        :raise StoreLoad.FileNotFoundError: Raised if no basis file found.
        :raise ValueError: Raised if dimension in header doesn't correspond to the basis dimension.
        """
        if not self.exists_basis_file():
            raise StoreLoad.FileNotFoundError(
                "Cannot load basis, No basis file found for %s: " % str(self))
        basis_list = StoreLoad.load_string_list(self.get_basis_file_path())
        dim = int(basis_list.pop(0))
        if len(basis_list) != dim:
            raise ValueError("Basis read from file %s has wrong dimension" %
                             str(self.get_basis_file_path()))
        return basis_list
コード例 #3
0
ファイル: ReferenceGraphComplex.py プロジェクト: sibrun/GH
    def _load_matrix(self):
        """ Load the reference matrix list from the reference file.

        The implementation depends on the reference data.

        :return: (matrix_list = list((domain index, target index, value), shape = (domain dimension, target dimension))
        :rtype: tuple(list(tuple(int, int, int)), tuple(int, int))
        :raise StoreLoad.FileNotFoundError: If the reference matrix file is not found.
        :raise: ValueError: Raised in the following cases:
                End line missing.
                Negative matrix index.
                Matrix index too large.
        """
        if not self.exists_matrix_file():
            raise StoreLoad.FileNotFoundError(
                "%s: Reference basis file not found" % str(self))
        stringList = StoreLoad.load_string_list(self.matrix_file_path)
        entriesList = []
        if len(stringList) == 0:
            return ([], None)
        else:
            (d, t, z) = map(int, stringList.pop().split(" "))
            if z != 0:
                raise ValueError("End line in reference file %s is missing" %
                                 str(self))
            shape = (d, t)
            for line in stringList:
                (i, j, v) = map(int, line.split(" "))
                if i < 0 or j < 0:
                    raise ValueError("%s: Negative matrix index" % str(self))
                if i > d or j > t:
                    raise ValueError("%s Matrix index outside matrix size" %
                                     str(self))
                if i == 0 or j == 0:
                    continue
                entriesList.append((i - 1, j - 1, v))
        return (entriesList, shape)