Ejemplo n.º 1
0
    def test_snap(self):
        """Test that snap.py installed correctly.
        """
        import snap
        num_nodes = 20

        # Generate different undirected graphs
        full_graph = snap.GenFull(snap.PUNGraph, num_nodes)
        star_graph = snap.GenStar(snap.PUNGraph, num_nodes)
        random_graph = snap.GenRndGnm(snap.PUNGraph, num_nodes, num_nodes * 3)

        # Basic statistics on the graphs
        self.assertEqual(snap.CntInDegNodes(full_graph, num_nodes - 1), num_nodes)
        self.assertEqual(snap.CntOutDegNodes(full_graph, num_nodes - 1), num_nodes)
        self.assertEqual(snap.GetMxInDegNId(star_graph), 0)
        self.assertEqual(snap.GetMxOutDegNId(star_graph), 0)

        # Iterator
        degree_to_count = snap.TIntPrV()
        snap.GetInDegCnt(full_graph, degree_to_count)
        # There should be only one entry (num_nodes - 1, num_nodes)
        for item in degree_to_count:
            self.assertEqual(num_nodes - 1, item.GetVal1())
            self.assertEqual(num_nodes, item.GetVal2())

        # Rewiring
        rewired_graph = snap.GenRewire(random_graph)
        for n1 in random_graph.Nodes():
            for n2 in rewired_graph.Nodes():
                if n1.GetId() == n2.GetId():
                    self.assertEqual(n1.GetOutDeg() + n1.GetInDeg(),
                                     n2.GetOutDeg() + n2.GetInDeg())
Ejemplo n.º 2
0
    def draw(self):
        self.read_nodes()
        self.Network = self.var_network.get()
        self.nPoints = sum(int(i) for i in self.lst_Nodes)

        if self.Network == "GenStar":
            print "GenStar is the network with points ", self.nPoints
            self.graph = snap.GenStar(snap.PNGraph, self.nPoints, True)

        if self.Network == "GenRndGnm":
            print "GenRndGnm is the network with points ", self.nPoints
            self.graph = snap.GenRndGnm(snap.PNGraph, self.nPoints,
                                        self.nPoints)

        if self.Network == "GenForestFire":
            print "GenForestFire is the network with points ", self.nPoints
            self.graph = snap.GenForestFire(self.nPoints, 0.5, 0.5)

        if self.Network == "GenFull":
            print "GenFull is the network with points ", self.nPoints
            self.graph = snap.GenFull(snap.PNGraph, self.nPoints)

        if self.Network == "GenCircle":
            print "GenCircle is the network with points ", self.nPoints
            self.graph = snap.GenCircle(snap.PNGraph, self.nPoints, 10, 10)

        self.create_nodes(self.graph)
Ejemplo n.º 3
0
    def base_graph(self):
        G = None
        if self.graph_type == 'star':
            G = snap.GenStar(snap.PUNGraph, self.nnodes, False)
        elif self.graph_type == 'full':
            G = snap.GenFull(snap.PUNGraph, self.nnodes)
        elif self.graph_type == 'circle':
            G = snap.GenCircle(snap.PUNGraph, self.nnodes, False)
        elif self.graph_type == 'tree':
            G = snap.GenTree(snap.PUNGraph, Fanout=2, Levels=10, IsDir=False)
        elif self.graph_type == 'erdos-renyi' or self.graph_type == 'er':
            G = snap.GenRndGnm(snap.PUNGraph, self.nnodes, self.nnodes * 5,
                               False)
        elif self.graph_type == 'barabasi-albert' or self.graph_type == 'ba':
            G = snap.GenPrefAttach(self.nnodes, 10)
        else:
            print "> Defaulting to full mode"
            G = snap.GenFull(snap.PUNGraph, self.nnodes)

        return G
Ejemplo n.º 4
0
def generateGplus():
    G = snap.GenFull(snap.PUNGraph, n)
    Gsigns = [[1 for x in xrange(n)] for x in xrange(n)]

    for i in xrange(n - 1):
        for j in xrange(i + 1, n):
            randomValue = random.random()
            if randomValue >= 0.5:
                Gsigns[i][j] = -1
                Gsigns[j][i] = -1

    return (G, Gsigns)
Ejemplo n.º 5
0
def countSubgraphs(G):
    total = 0.0
    results = []
    estCount = 3200
    H = snap.GenFull(snap.PUNGraph, 3)
    for i in range(estCount):
        est = Estimator(G, H, G.GetNodes())
        for e in G.Edges():
            est.updateZ(e)
        results.append(est.subgraphCount())
        #print i, results[-1]
    return sum(results) / estCount
Ejemplo n.º 6
0
def createCompleteNetwork(networkSize):
    """
  :param - networkSize: Desired number of nodes in network

  return type: Graph
  return: Returns complete network on networkSize
  """
    completeNetwork = None
    ############################################################################
    completeNetwork = snap.GenFull(snap.PUNGraph, networkSize)
    ############################################################################
    return completeNetwork
Ejemplo n.º 7
0
def countTriangles(G):
  H = snap.GenFull(snap.PUNGraph, 3)
  hashFnSel = HashFuncSelector(H, 2**16)
  total = 0.0
  results = []
  estCount = 1
  for i in range(estCount):
    est = Estimator(H, hashFnSel)
    for e in G.Edges():
      est.updateZ(e)
    results.append(est.subgraphCount())
    print i, results[-1]
  return results, sum(results)/estCount
Ejemplo n.º 8
0
    def genGraph(self, nodes):
        print "Generating random graph..."
        genFileName = 'random5000by6.txt'
        nodesV = snap.TIntV()
        for i in range(nodes):
            if (i % 6 != 0):
                nodesV.Add(i)

        comG = snap.GenFull(snap.PUNGraph, nodes)
        snap.DelNodes(comG, nodesV)

        snap.SaveEdgeList(comG, genFileName)
        return genFileName
Ejemplo n.º 9
0
def loadDNCNetwork(filename, p_infect, p_infect_hardened, t_recover,
                   hardened_ids):
    print 'Loading DNC Network'

    Network = snap.GenFull(snap.PNEANet, 0)
    print Network.GetNodes(), Network.GetEdges()
    with open(filename, 'rb') as tsvin:
        tsvin = csv.reader(tsvin, delimiter='\t')
        i = 0  # Ignore header
        maxID = 0
        for row in tsvin:
            if i > 0:
                srcID = int(row[0])
                dstID = int(row[1])
                timestamp = int(row[3])
                if srcID > maxID:
                    maxID = srcID
                if dstID > maxID:
                    maxID = dstID

                # Add nodes to network if not already there
                if not Network.IsNode(srcID):
                    Network.AddNode(srcID)
                if not Network.IsNode(dstID):
                    Network.AddNode(dstID)

                # Add edge attributes (Note, multi edges allowed)
                eid = Network.AddEdge(srcID, dstID)
                Network.AddIntAttrDatE(eid, timestamp, 'timestamp')
                Network.AddIntAttrDatE(eid, t_recover, 't_recover')
                if dstID in hardened_ids:
                    Network.AddIntAttrDatE(eid, p_infect_hardened,
                                           'p_infect_hardened')
                else:
                    Network.AddIntAttrDatE(eid, p_infect, 'p_infect')

                # Infected = 1, Susceptible (not infected) = 0
                Network.AddIntAttrDatE(eid, 0, 'infected')

            i += 1

    # Add any disjoint nodes (nodes without entries in the tsv file)
    for nID in range(maxID):
        if nID > 0 and not Network.IsNode(nID):
            Network.AddNode(nID)

    print 'NUM NODES: ' + str(Network.GetNodes())
    print 'NUM EDGES: ' + str(Network.GetEdges())
    return Network
Ejemplo n.º 10
0
def countTriangles(G):
    H = snap.GenFull(snap.PUNGraph, 3)
    N = 2**16
    assert (G.GetNodes() <= N)
    hashFnSel = HashFuncSelector(H, N)
    total = 0.0
    results = []
    estCount = 3000
    for i in range(estCount):
        est = Estimator(G, H, hashFnSel)
        for e in G.Edges():
            est.updateZ(e)
        results.append(est.subgraphCount())
        print i, results[-1]
    return int(sum(results) / estCount), results
Ejemplo n.º 11
0
    def setUp(self):
        # Defaults for creating graphs
        self.num_nodes = 10

        # Full Graphs
        self.DirGraphFull = snap.GenFull(snap.PNGraph, self.num_nodes)
        self.UnDirGraphFull = snap.GenFull(snap.PUNGraph, self.num_nodes)
        self.NetFull = snap.GenFull(snap.PNEANet, self.num_nodes)

        # Star Graphs
        self.DirGraphStar = snap.GenStar(snap.PNGraph, self.num_nodes)
        self.UnDirGraphStar = snap.GenStar(snap.PUNGraph, self.num_nodes)
        self.NetStar = snap.GenStar(snap.PNEANet, self.num_nodes)

        # Graph With Self Edges
        self.DirGraphSelfEdge = snap.GenRndGnm(snap.PNGraph, 10, 20)
        self.DirGraphSelfEdge.AddEdge(0, 0)
        self.UnDirGraphSelfEdge = snap.GenRndGnm(snap.PUNGraph, 10, 20)
        self.UnDirGraphSelfEdge.AddEdge(0, 0)
        self.NetSelfEdge = snap.GenRndGnm(snap.PNEANet, 10, 20)
        self.NetSelfEdge.AddEdge(0, 0)

        # Graph With Multiple Zero-Degree Nodes
        self.DirGraphZeroDegree = snap.GenRndGnm(snap.PNGraph, 10, 1)
        self.UnDirGraphZeroDegree = snap.GenRndGnm(snap.PUNGraph, 10, 1)
        self.NetZeroDegree = snap.GenRndGnm(snap.PNEANet, 10, 1)

        # Trees
        self.DirTree = snap.GenTree(snap.PNGraph, 3, 3)
        self.UnDirTree = snap.GenTree(snap.PUNGraph, 3, 3)
        self.NetTree = snap.GenTree(snap.PNEANet, 3, 3)

        # Random
        self.DirRand = snap.GenRndGnm(snap.PNGraph, 10, 20)
        self.UnDirRand = snap.GenRndGnm(snap.PUNGraph, 10, 20)
        self.NetRand = snap.GenRndGnm(snap.PNEANet, 10, 20)
Ejemplo n.º 12
0
    def __init__(self, beta, delta, graphType, rewireProbInput, numNodes,
                 scalingFactor):
        self.graphType = graphType
        self.numNodes = numNodes

        # initialize snap.py graph: self.G

        # for degree, use reproductive number 1.5 = degree * beta: on avg, ebola patient should infect 1.5 other people
        # nodeDeg = math.ceil((1.5 / beta) / scalingFactor)

        nodeDeg = math.ceil(
            10.0 /
            scalingFactor)  # most real world graphs have node degree 2~15

        if graphType == 'small world':
            rewireProb = rewireProbInput  # probability that an edge will be rewired in Watts-Strogatz model
            self.G = snap.GenSmallWorld(
                numNodes, int(nodeDeg / 2),
                rewireProb)  # for snap function, must divide degree by 2
        elif graphType == 'random':
            numEdges = numNodes * nodeDeg / 2
            self.G = snap.GenRndGnm(snap.PUNGraph, numNodes, numEdges)
        elif graphType == 'complete':
            self.G = snap.GenFull(snap.PUNGraph, numNodes)
        elif graphType == 'scale free':
            self.G = snap.GenPrefAttach(numNodes, nodeDeg)
        else:
            raise NotImplementedError(
                "graphType argument must be in {'random', 'small world', 'complete', 'scale free}"
            )

        # initialize variables for SIR model
        self.beta, self.delta = beta, delta
        self.state = dict.fromkeys(
            xrange(numNodes), SUSCEPTIBLE
        )  # dict: int nodeID => string SUSCEPTIBLE or INFECTED or RECOVERED
        self.countyHasBeenInfected = False
 def SimpleNetworkGenerator(self, params):
     #print params
     Rnd = snap.TRnd(1, 0)
     G = None
     try:
         if params[0] == GlobalParameters.NetworkType[0]:
             G = snap.GenSmallWorld(int(params[1]), int(params[2]),
                                    float(params[3]), Rnd)
         if params[0] == GlobalParameters.NetworkType[1]:
             G = snap.GenPrefAttach(int(params[1]), int(params[2]), Rnd)
         if params[0] == GlobalParameters.NetworkType[2]:
             G = snap.GenForestFire(int(params[1]), float(params[2]),
                                    float(params[3]))
         if params[0] == GlobalParameters.NetworkType[3]:
             G = snap.GenRndGnm(snap.PUNGraph, int(params[1]),
                                int(params[2]), False, Rnd)
         if params[0] == GlobalParameters.NetworkType[4]:
             G = snap.GenCircle(snap.PUNGraph, int(params[1]),
                                int(params[2]), False)
         if params[0] == GlobalParameters.NetworkType[5]:
             G = snap.GenFull(snap.PUNGraph, int(params[1]))
         return G
     except:
         return None
Ejemplo n.º 14
0
if len(sys.argv) < 5:
    print('Incorrect number of arguments. Way of usage:')
    print(
        'python ' + sys.argv[0] +
        ' <p of infection> <# of initial infected> <time infected> <time removed>'
    )
    exit(1)

MainGraph = snap.LoadEdgeList(snap.PNEANet, "./soc-Epinions1.txt", 0, 1)

#creation of various graphs
#Low Clustering Coefficient
LowClusterGraph = snap.GenRndGnm(snap.PNEANet, 1000, 3000)

#High Clustering Coefficient
HighClusterGraph = snap.GenFull(snap.PNEANet, 1000)

#Random subgraph
NIdV = snap.TIntV()
rangList = random.sample(range(MainGraph.GetNodes()), 7000)

for i in range(1, 7000):
    NIdV.Add(rangList[i])

subGraph = snap.GetSubGraph(MainGraph, NIdV)

# Initial parameters of the model
init_infected = random.sample(range(1,
                                    MainGraph.GetNodes() + 1),
                              int(sys.argv[2]))
p = float(sys.argv[1])
import snap

G1 = snap.GenFull(snap.PNEANet, 5)

G1.AddStrAttrE("sign1")

for EI in G1.Edges():
    EId = G1.GetEId(EI.GetSrcNId(), EI.GetDstNId())
    G1.AddStrAttrDatE(EId, "+", 'sign1')

G1.AddStrAttrE("sign2")

# why it works with edge_Id, but does not work with edge
for EI in G1.Edges():
    G1.AddStrAttrDatE(EI, "+", 'sign2')
Ejemplo n.º 16
0
def full():
    G = snap.GenFull(snap.PUNGraph, nodes)
    snap.SaveEdgeList(G, args.type + '.txt')
from save_Gephi import saveGephi
import os
import snap
import sys
sys.path.append("../..")
sys.path.append("/courses/tsks11/ht2019/data_and_fcns/")
sys.path.append("/courses/tsks11/ht2019/snap-4.1.0-4.1-centos6.5-x64-py2.6/")

TPATH = "/courses/tsks11/ht2019/data_and_fcns/session1/"

# PNGraph, a directed graph;
# PUNGraph, an undirected graph;
# PNEANet, a directed network;

# Generate a complete graph with 5 nodes (K5) and look at it via Graphviz
G = snap.GenFull(GraphType=snap.PUNGraph, Nodes=5)
# for EI in G.Edges():
#    print "link from %d to %d" % (EI.GetSrcNId(), EI.GetDstNId())

# Saves Graph to the .DOT file format used by GraphViz
snap.SaveGViz(Graph=G,
              OutFNm="_undirected-completely-connected.dot",
              Desc="Undirected Completely Connected Network",
              NodeLabels=True)
# Draws undirected graphs using the generated .dot file
os.system(
    "neato -Tpdf _undirected-completely-connected.dot >_undirected-completely-connected.pdf"
)

# Generate a star graph and visualize in Graphviz
G = snap.GenStar(GraphType=snap.PNGraph, Nodes=10, IsDir=True)
    def drawNode(self):

        global GNodesItemNo

        if self.Network == "GenStar":
            print "GenStar is the network with points ",self.nPoints
            Graph = snap.GenStar(snap.PNGraph, self.nPoints, True)

        if self.Network == "GenRndGnm":
            print "GenRndGnm is the network with points ",self.nPoints
            Graph = snap.GenRndGnm(snap.PNGraph,self.nPoints, self.nPoints)

        if self.Network == "GenForestFire":
            print "GenForestFire is the network with points ",self.nPoints
            Graph = snap.GenForestFire(self.nPoints, 0.5,0.5)

        if self.Network == "GenFull":
            print "GenFull is the network with points ",self.nPoints
            Graph = snap.GenFull(snap.PNGraph,self.nPoints)

        if self.Network == "GenCircle":
            print "GenCircle is the network with points ",self.nPoints
            Graph = snap.GenCircle(snap.PNGraph,self.nPoints,10,10)

        shape = 0
        self.dnodes.reverse()
        nodeCounter = self.dnodes.pop()

        for i in Graph.Nodes():
            self.node = Node()
            self.node.id = i.GetId()

            for EI in Graph.Edges():
                if EI.GetSrcNId() == i.GetId():
                    if EI.GetSrcNId() <> EI.GetDstNId() :
                        self.node.follower.append(EI.GetDstNId())

            if shape ==0:
                self.node.shape = "oval"
            if shape ==1:
                self.node.shape = "triangle"
            if shape ==2:
                self.node.shape = "rectangle"
            if shape ==3:
                self.node.shape = "circle"

            nodeCounter = nodeCounter - 1
            if nodeCounter <=0:
                if len(self.dnodes)<> 0:
                    nodeCounter = self.dnodes.pop()
                    print "Completed Community: ",shape
                shape = shape + 1

            self.CoordinateSelection()
            self.Radius = 5
##            if len(self.node.follower) <> 0:
##                self.Radius = len(self.node.follower)

            if self.node.shape == "oval":
                _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius,
                                            self.node.y+self.Radius,outline="#ff00ff",fill="white", width=2)

            if self.node.shape == "triangle":
                traingle = [self.node.x,self.node.y,self.node.x+self.Radius,self.node.y+self.Radius]
                _Oval = Gcanvas.create_oval(traingle,outline="#252568",fill="white", width=2)

            if self.node.shape == "rectangle":
                _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius,
                                            self.node.y+self.Radius,outline="#474bcc",fill="white", width=2)

            if self.node.shape == "circle":
                _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius,
                                            self.node.y+self.Radius,outline="#364949",fill="white", width=2)

            self.OvalNo[_Oval]=self.node.id#[self.node.x,self.node.y]
            Gcanvas.tag_bind( _Oval, '<ButtonPress-1>', self.__showAttriInfo)
            self.itemNo.append(_Oval)
            self.pAll.append(self.node)


        GNodesItemNo = self.itemNo
Ejemplo n.º 19
0
import snap

Graph = snap.GenFull(snap.PNEANet, 10)
print Graph.GetEI(0, 5).GetId()

Src = 0
Dst = 5
EI = Graph.GetEI(Src, Dst)
Src1 = EI.GetSrcNId()
Dst1 = EI.GetDstNId()
EI1 = Graph.GetEI(Src1, Dst1)

if Src != Src1 or Dst != Dst1:
    print "*** Error1"

if EI.GetId() != EI1.GetId():
    print "*** Error2"

Graph = snap.GenFull(snap.PUNGraph, 10)
print Graph.GetEI(0, 5).GetId()

Src = 0
Dst = 5
EI = Graph.GetEI(Src, Dst)
Src1 = EI.GetSrcNId()
Dst1 = EI.GetDstNId()
EI1 = Graph.GetEI(Src1, Dst1)

if Src != Src1 or Dst != Dst1:
    print "*** Error1"
Ejemplo n.º 20
0
def loadDNCNetwork(filename, p_infect, p_infect_hardened, t_recover, detector_ids, hardened_ids):
	print 'Loading DNC Network'
	added = 0

	Network = snap.GenFull(snap.PNEANet, 0)
	print Network.GetNodes(), Network.GetEdges()
	with open(filename,'rb') as tsvin:
		tsvin = csv.reader(tsvin, delimiter='\t')
		i = 0 # Ignore header
		maxID = 0
		for row in tsvin:
			if i > 0:
				srcID = int(row[0])
				dstID = int(row[1])
				timestamp = int(row[3])
				if srcID > maxID:
					maxID = srcID
				if dstID > maxID:
					maxID = dstID
				
				# Add nodes to network if not already there
				if not Network.IsNode(srcID):
					added+=1
					Network.AddNode(srcID)
					# normal user or detector
					if srcID in detector_ids:
						Network.AddStrAttrDatN(srcID, 'detector', 'type')
					else:
						Network.AddStrAttrDatN(srcID, 'user', 'type')

				if not Network.IsNode(dstID):
					Network.AddNode(dstID)
					# normal user or detector
					if dstID in detector_ids:
						Network.AddStrAttrDatN(dstID, 'detector', 'type')
					else:
						Network.AddStrAttrDatN(dstID, 'user', 'type')

				# Add edge attributes (Note, multi edges allowed)
				eid = Network.AddEdge(srcID, dstID)
				Network.AddIntAttrDatE(eid, timestamp, 'timestamp')
				Network.AddIntAttrDatE(eid, t_recover, 't_recover')
				if dstID in hardened_ids:
					Network.AddFltAttrDatE(eid, p_infect_hardened, 'p_infect') #TODO: Do we need to distinguish between hardened/de
				else:
					Network.AddFltAttrDatE(eid, p_infect, 'p_infect')

				# state: infected or susceptible
				Network.AddStrAttrDatN(srcID, 'susceptible', 'state')
				Network.AddStrAttrDatN(dstID, 'susceptible', 'state')

			i+=1

	# Add any disjoint nodes (nodes without entries in the tsv file)
	for nID in range(maxID):
		if nID > 0 and not Network.IsNode(nID):
			Network.AddNode(nID)
			Network.AddStrAttrDatN(nID, 'susceptible', 'state')
			if nID in detector_ids:
				Network.AddStrAttrDatN(nID, 'detector', 'type')
			else:
				Network.AddStrAttrDatN(nID, 'user', 'type')


	print 'NUM NODES: ' + str(Network.GetNodes())
	print 'NUM EDGES: ' + str(Network.GetEdges())
	print 'NODES WITH OUTGOING EDGES: ' + str(added)
	return Network
Ejemplo n.º 21
0
import snap

G = snap.GenFull(snap.PNEANet, 100)

Rnd = snap.TRnd(0)

for i in range(0, 10):
    NId = G.GetRndNId(Rnd)
    print NId

    # result is not well formed, the following statement fails
    #print NI.GetId()
Ejemplo n.º 22
0
import snap

Graph = snap.GenFull(snap.PNEANet, 10)

NIdV = snap.TIntV()
Graph.GetNIdV(NIdV)
for i in NIdV:
    print("node", i)

EIdV = snap.TIntV()
Graph.GetEIdV(EIdV)
for i in EIdV:
    print("edge", i)

Ejemplo n.º 23
0
def generate_complete_graph(n=100, directed=False):
    if directed:
        g = snap.GenFull(snap.PNGraph, n)
    else:
        g = snap.GenFull(snap.PUNGraph, n)
Ejemplo n.º 24
0
import snap

nodes = 10
G = snap.GenFull(snap.PNEANet, nodes)

# define int, float and str attributes on nodes
G.AddIntAttrN("NValInt", 0)
G.AddFltAttrN("NValFlt", 0.0)
G.AddStrAttrN("NValStr", "0")

# define an int attribute on edges
G.AddIntAttrE("EValInt", 0)

# add attribute values, node ID for nodes, edge ID for edges

for NI in G.Nodes():
    nid = NI.GetId()
    val = nid
    G.AddIntAttrDatN(nid, val, "NValInt")
    G.AddFltAttrDatN(nid, float(val), "NValFlt")
    G.AddStrAttrDatN(nid, str(val), "NValStr")

    for nid1 in NI.GetOutEdges():
        eid = G.GetEId(nid, nid1)
        val = eid
        G.AddIntAttrDatE(eid, val, "EValInt")

# print out attribute values

for NI in G.Nodes():
    nid = NI.GetId()
Ejemplo n.º 25
0
import snap


def rewire(G_in):
    G = G_in.ConvertGraph(snap.TUNGraph)
    G_rewire = snap.GenRewire(G, 1000)
    return G_rewire


G_in = snap.GenFull(snap.TNGraph, 572)
for i in range(500):
    G_rewired = rewire(G_in)
    print(i, G_rewired.GetNodes(), G_rewired.GetEdges())
Ejemplo n.º 26
0
    def genPoints_Snap(self, Community_Coordinate):
        """
        gen n Points
        """

        #GenFull
        #GenCircle
        #GenGrid
        #GenStar
        #GenTree
        #GenRndGnm
        #GenPrefAttach
        #GenGeoPrefAttach
        #GenForestFire
        #GenSmallWorld
        #GenBaraHierar
        #GenConfModel
        #GenConfModel
        #GenCopyModel
        #GenDegSeq
        #GenRewire
        #GenRndDegK
        #GenRndPowerLaw
        #GenRMat
        #GenRMatEpinions

        Graph = snap.GenFull(snap.PNGraph, self.nPoints)
        #Graph = snap.GenFull(snap.PUNGraph, 5)
        #Graph = snap.GenFull(snap.PNEANet, 5)

        #Graph = snap.GenCircle(snap.PNGraph, 5, 5)
        #Graph = snap.GenCircle(snap.PUNGraph, 5, 5)
        #Graph = snap.GenCircle(snap.PNEANet, 5, 5)

        #Graph = snap.GenGrid(snap.PNGraph, 5, 5, False)

        #Graph = snap.GenStar(snap.PNGraph, self.nPoints, True)
        #Graph = snap.GenStar(snap.PUNGraph, self.nPoints, True)
        #Graph = snap.GenStar(snap.PNEANet, self.nPoints, True)

        #Graph = snap.GenTree(snap.PNGraph, self.nPoints, self.nPoints)
        #Graph = snap.GenTree(snap.PUNGraph, self.nPoints, self.nPoints)
        #Graph = snap.GenTree(snap.PNEANet, self.nPoints, self.nPoints)

        #Graph = snap.GenRndGnm(snap.PNGraph, self.nPoints, self.nPoints)
        #Graph = snap.GenRndGnm(snap.PUNGraph, self.nPoints, self.nPoints)

        for i in Graph.Nodes():

            XmaxNo = max(Community_Coordinate[1])
            XminNo = min(Community_Coordinate[1])
            YmaxNo = max(Community_Coordinate[2])
            YminNo = min(Community_Coordinate[2])

            node = Node()
            node.id = i.GetId()

            r = lambda: random.randint(0, 255)
            rColor = '#%02X%02X%02X' % (r(), r(), r())
            node.color = rColor

            node.x = random.randrange(XminNo + 1, XmaxNo - 20)
            node.y = random.randrange(YminNo + 1, YmaxNo - 20)

            #self.pAll.append(node)

            for EI in Graph.Edges():
                if EI.GetSrcNId() == i.GetId():
                    print "edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())

                    if EI.GetSrcNId() <> EI.GetDstNId():
                        node.follower.append(EI.GetDstNId())

            self.pAll.append(node)
Ejemplo n.º 27
0
import snap

Graph = snap.GenFull(snap.PNGraph, 5)

for EI in Graph.Nodes():
        #print EI.GetId(),EI.GetOutDeg()
  
        for j in Graph.Edges():
             
                if j.GetSrcNId() == EI.GetId():
                        print "edge: (%d, %d)" % (j.GetSrcNId(), j.GetDstNId())
  
        
print  "*" * 50
##for EI in Graph.Edges():
##        print i
##        print "edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())
##        i = i + 1

UGraph = snap.GenFull(snap.PUNGraph, 5)
for EI in UGraph.Edges():
    print "edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())

print  "*" * 50
Network = snap.GenFull(snap.PNEANet, 5)
for EI in Network.Edges():
    print "edge: (%d, %d)" % (EI.GetSrcNId(), EI.GetDstNId())
Ejemplo n.º 28
0
def getGlobalEfficiency(Graph):
    E_G = getAvgEfficiency(Graph)
    num_nodes = Graph.GetNodes()
    G_ideal = snap.GenFull(snap.PUNGraph, num_nodes)
    E_G_ideal = getAvgEfficiency(G_ideal)
    return E_G / float(E_G_ideal)