示例#1
0
def generate_graph(NNodes, NEdges, Model, Type, Rnd):

    if Model == 'rand_ungraph':
        # GnRndGnm returns error, so manually generate
        Graph = snap.GenRndGnm_PUNGraph(NNodes, NEdges, 0)

    elif Model == 'rand_ngraph':
        Graph = snap.GenRndGnm_PNGraph(NNodes, NEdges, 1)

    elif Model == 'rand_neanet':
        Graph = snap.GenRndGnm(NNodes, NEdges, 1)

    elif Model == 'syn_neanet':
        Graph = snap.GenSyntheticGraph(NNodes, NEdges / NNodes,
                                       SYNTHETIC_DELTA)

    elif Model == 'syn_ngraph':
        Graph = snap.GenSyntheticGraph_PNGraph(NNodes, NEdges / NNodes,
                                               SYNTHETIC_DELTA)

    elif Model == 'rmat':
        Graph = snap.GenRMat(NNodes, NEdges, 0.40, 0.25, 0.2, Rnd)

    elif Model == 'sw':
        Graph = snap.GenSmallWorld(NNodes, NNodes / NEdges, 0.1)

    elif Model == 'pref':
        Graph = snap.GenPrefAttach(NNodes, NNodes / NEdges)

    return Graph
示例#2
0
def generate_graph(NNodes, NEdges, Model, Rnd):
  
  Graph = None
  if Model == 'rand_ungraph':
    # GnRndGnm returns error, so manually generate
    Graph = snap.GenRndGnm_PUNGraph(NNodes, NEdges, 0)

  elif Model == 'rand_ngraph':
    Graph = snap.GenRndGnm_PNGraph(NNodes, NEdges, 1)
      
  elif Model == 'rand_neagraph':
    Graph = snap.GenRndGnm_PNEANet(NNodes, NEdges, 1)

  elif Model == 'syn_neagraph':
    Graph = snap.GenSyntheticGraph_PNEANet(NNodes, NEdges/NNodes,
                                             SYNTHETIC_DELTA)

  elif Model == 'syn_ngraph':
    Graph = snap.GenSyntheticGraph_PNGraph(NNodes, NEdges/NNodes,
                                             SYNTHETIC_DELTA)

  elif Model == 'rmat':
    Graph = snap.GenRMat(NNodes, NEdges, 0.40, 0.25, 0.2, Rnd)

  elif Model == 'sw':
    Graph = snap.GenSmallWorld(NNodes, NNodes/NEdges, 0.1)
  
  elif Model == 'pref':
    Graph = snap.GenPrefAttach(NNodes, NNodes/NEdges)

  else:
    print "Unknown model: %s" % Model
    sys.exit(1)

  return Graph
示例#3
0
def GenRndGnm():
    Graph = snap.GenRndGnm_PNGraph(1000,10000)
    print "Graph", str(type(Graph)), Graph.GetNodes(), Graph.GetEdges()

    # save the graph
    FName = "test2.graph"
    print "Save", FName

    FOut = snap.TFOut(snap.TStr(FName))
    Graph.Save(FOut)
    FOut.Flush()

    # load the graph
    print "Read", FName
    FIn = snap.TFIn(snap.TStr(FName))
    #Graph2 = snap.TNGraph(FIn)
    #Graph2 = snap.TNGraph.Load(FIn)
    Graph2 = snap.PNGraph.New()
    print "Graph2", str(type(Graph2))
    print str(dir(Graph2))
    Graph2.Load(FIn)