File:Critical 1000-vertex Erdős–Rényi–Gilbert graph.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 1,000 × 1,000 pixels, file size: 79 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: An Erdős–Rényi–Gilbert random graph with 1000 vertices at the critical edge probability p=1/(n−1), showing the largest connected component in the center.
    Date
    Source Own work
    Author David Eppstein
    SVG development
    InfoField
     The SVG code is valid.
     This vector image was created with Python.

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Source code

    from PADS.SVG import *
    from PADS.StrongConnectivity import *
    from random import random
    from sys import stdout
    
    # ===================================================
    # Generate a random graph and random layout
    # ===================================================
    
    n = 1000
    vertices = range(n)
    edgeprob = 1./(n-1)
    
    halfG = {v : set(w for w in vertices if v<w and random() < edgeprob) for v in vertices}
    G = {v : set(w for w in vertices if v in halfG[w] or w in halfG[v]) for v in vertices}
    
    # ===================================================
    # Pull giant component in and push all the rest out
    # ===================================================
    weight = {}
    SCC = StronglyConnectedComponents(G)
    giant = max(len(C) for C in SCC)
    for C in StronglyConnectedComponents(G):
        for v in C:
            if len(C) == giant:
                weight[v] = giant
            else:
                weight[v] = -1
    
    # ===================================================
    # Social gravity
    # ===================================================
    
    D = {v : (random()-0.5) + 1j* (random()-0.5) for v in vertices}
    natlength = n**(-0.5)
    iterations = 150
    increment = 0.01
    
    for i in range(iterations):
        social = 0.25
        forces = {v : -D[v]*social for v in vertices}
    
        for v in vertices:
            for w in vertices:
                if v != w:
                    forces[v] += (natlength/abs(D[v]-D[w]))**2*(D[v]-D[w])
    
        for v in vertices:
            for w in G[v]:
                forces[v] += abs(D[v]-D[w])*(D[w]-D[v])/natlength
    
        for v in vertices:
            D[v] += increment * forces[v]
    
    # ===================================================
    # Renormalize
    # ===================================================
    
    minx = min(D[v].real for v in vertices)
    miny = min(D[v].imag for v in vertices)
    offset = minx + 1j*miny
    for v in vertices:
        D[v] -= offset
    
    maxx = max(D[v].real for v in vertices)
    maxy = max(D[v].imag for v in vertices)
    rescale = 1./max(maxx,maxy)
    for v in vertices:
        D[v] *= rescale
    
    # ===================================================
    # Turn layout into drawing
    # ===================================================
    
    scale = 1000
    radius = 6
    margin = 9
    bbox = scale*(1+1j)
    
    def place(v):
        return D[v]*(scale-2*margin) + margin*(1+1j)
    
    drawing = SVG(bbox,stdout)
    
    drawing.group(style={"stroke":"#000","stroke-width":"2"})
    for v in vertices:
        for w in halfG[v]:
            drawing.segment(place(v),place(w))
    drawing.ungroup()
    
    drawing.group(fill=colors.red,stroke=colors.black)
    for v in vertices:
        drawing.circle(place(v),radius)
    drawing.ungroup()
    
    drawing.close()
    

    Captions

    An Erdős–Rényi–Gilbert graph with 1000 vertices at the critical edge probability

    Items portrayed in this file

    depicts

    8 February 2022

    image/svg+xml

    2bab09c61e6c052133f6acc2c459b2c2dc18eedf

    80,529 byte

    1,000 pixel

    1,000 pixel

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current08:33, 9 February 2022Thumbnail for version as of 08:33, 9 February 20221,000 × 1,000 (79 KB)wikimediacommons>David EppsteinUploaded own work with UploadWizard

    There are no pages that use this file.