docs: def generate_mediation_matrix(dsm):
          """
          Generate the mediation matrix of the given matrix.
  
          Rules for mediation matrix generation:
  
          Set -1 for items NOT to be considered
          Set 0 for items which MUST NOT be present
          Set 1 for items which MUST be present
  
          Each module has optional dependencies to itself.
  
          - Framework has optional dependency to all framework items (-1),
            and to nothing else.
          - Core libraries have dependencies to framework.
            Dependencies to other core libraries are tolerated.
          - Application libraries have dependencies to framework.
            Dependencies to other core or application libraries are tolerated.
            No dependencies to application modules.
          - Application modules have dependencies to framework and libraries.
            Dependencies to other application modules
            should be mediated over a broker.
            Dependencies to data are tolerated.
          - Data have no dependencies at all
            (but framework/libraries would be tolerated).
  
          Args:
              dsm (:class:`DesignStructureMatrix`): the DSM to generate
                  the mediation matrix for.
          """
          cat = dsm.categories
          ent = dsm.entities
          size = dsm.size[0]
  
          if not cat:
              cat = ['appmodule'] * size
  
          packages = [e.split('.')[0] for e in ent]
  
          # define and initialize the mediation matrix
          mediation_matrix = [[0 for _ in range(size)]
                              for _ in range(size)]
  
          for i in range(0, size):
              for j in range(0, size):
                  if cat[i] == 'framework':
                      if cat[j] == 'framework':
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  elif cat[i] == 'corelib':
                      if (cat[j] in ('framework', 'corelib') or
                              ent[i].startswith(packages[j] + '.') or
                              i == j):
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  elif cat[i] == 'applib':
                      if (cat[j] in ('framework', 'corelib', 'applib') or
                              ent[i].startswith(packages[j] + '.') or
                              i == j):
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  elif cat[i] == 'appmodule':
                      # we cannot force an app module to import things from
                      # the broker if the broker itself did not import anything
                      if (cat[j] in ('framework', 'corelib',
                                     'applib', 'broker', 'data') or
                              ent[i].startswith(packages[j] + '.') or
                              i == j):
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  elif cat[i] == 'broker':
                      # we cannot force the broker to import things from
                      # app modules if there is nothing to be imported.
                      # also broker should be authorized to use third apps
                      if (cat[j] in (
                              'appmodule', 'corelib', 'framework') or
                              ent[i].startswith(packages[j] + '.') or
                              i == j):
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  elif cat[i] == 'data':
                      if (cat[j] == 'framework' or
                              i == j):
                          mediation_matrix[i][j] = -1
                      else:
                          mediation_matrix[i][j] = 0
                  else:
                      # mediation_matrix[i][j] = -2  # errors in the generation
                      raise DesignStructureMatrixError(
                          'Mediation matrix value NOT generated for %s:%s' % (
                              i, j))
  
          return mediation_matrix