Exemplo n.º 1
0
	def bfsTree(self, root):
		"""
		calculates a breadth-first search tree from the edges in the
		passed HyGraph, starting from the root vertex.  "Breadth-first"
		in the sense that all vertices reachable in step i are added
		to the tree before any of the newly-reachable vertices' reachable
		vertices are explored.  The returned tree (implied in the parent
		relationships) consists of simple edges, not the original 
		hyperedges of the HyGraph instance.

		Input Arguments:
			root:  an integer denoting the root vertex for the tree

		Input Arguments:
			parents:  a ParVec instance of length equal to the number
			    of vertices in the HyGraph, with each element denoting 
			    the vertex number of that vertex's parent in the tree.
			    The root is its own parent.  Unreachable vertices
			    have a parent of -1. 

		SEE ALSO: isBfsTree 
		"""
		parents = pcb.pyDenseParVec(self.nvert(), -1)
		fringeV = pcb.pySpParVec(self.nvert())
		parents[root] = root
		fringeV[root] = root
		while fringeV.getnee() > 0:
			fringeV.setNumToInd()
			fringeE = self._spm.SpMV_SelMax(fringeV)
			fringeV = self._spmT.SpMV_SelMax(fringeE)
			pcb.EWiseMult_inplacefirst(fringeV, parents, True, -1)
			parents[fringeV] = 0
			parents += fringeV
		return ParVec.toParVec(parents)
Exemplo n.º 2
0
	def degree(self):
		"""
		calculates the degree of each vertex of the passed HyGraph instance.

		Input Arguments:
			self:  a HyGraph instance

		Output Argument:
			ret:  a ParVec instance with each element containing the
			    degree of the corresponding vertex.

		SEE ALSO:  sum 
		"""
		if self.nedge() == 0:
			return ParVec.zeros(self.nvert())
		ret = self._spm.Reduce(pcb.pySpParMat.Column(),pcb.plus(), pcb.ifthenelse(pcb.bind2nd(pcb.not_equal_to(), 0), pcb.set(1), pcb.set(0)))
		return ParVec.toParVec(ret)
Exemplo n.º 3
0
	def npin(self):
		"""
		calculates the cardinality of each edge of the passed HyGraph 
		instance.

		Input Arguments:
			self:  a HyGraph instance

		Output Argument:
			ret:  a ParVec instance with each element containing the
			    cardinality of the corresponding edge.

		SEE ALSO:  rank, antirank 
		"""
		if self.nedge() == 0:
			return ParVec.zeros(self.nedge())
		ret = self._spm.Reduce(pcb.pySpParMat.Row(),pcb.plus(), pcb.ifthenelse(pcb.bind2nd(pcb.not_equal_to(), 0), pcb.set(1), pcb.set(0)))
		return ParVec.toParVec(ret)