0% found this document useful (0 votes)
14 views5 pages

Sombor Index Calculation in Graphs

The document contains code to calculate the Sombor index of graphs of cyclic groups Z_n. The code takes in an integer n, constructs the adjacency matrix of Z_n, calculates the degree of each vertex, and sums the square root of the degree products for all edges to obtain the Sombor index.

Uploaded by

skupar7302
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Sombor Index Calculation in Graphs

The document contains code to calculate the Sombor index of graphs of cyclic groups Z_n. The code takes in an integer n, constructs the adjacency matrix of Z_n, calculates the degree of each vertex, and sums the square root of the degree products for all edges to obtain the Sombor index.

Uploaded by

skupar7302
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

from math import sqrt

from operator import mod


import numpy as np
from scipy import io, integrate, linalg, signal
from [Link] import eigs
def main():
    n=int(input("Enter n for Z_n:"))
    vert=[]
    i=0
    while i<n-2:
        [Link]("")
        i=i+1
    print(vert)
    adj=[Link]((n-2,n-2))
    print(adj)
    Deg=[Link]((1,n-2))
    for i in range(1,n-1):
        vert[i-1]=f"{i+1}"
        print(vert)
        for j in range(1,n-1):
            if (i+1)==(j+1):
                continue
            if ((i+1)*(j+1))%n==0:
                #print (i)
                adj[i-1][j-1]=1
                Deg[0][i-1]=Deg[0][i-1]+1
       
    print(vert)
    print(adj)
    print(Deg)
    s_i=0
    for i in range(0,n-3):
        for j in range(i+1,n-2):
            if adj[i][j]==1:
                print("print adj",adj[i][j])
                s_i=s_i+sqrt(Deg[0][i]**2+Deg[0][j]**2)
                print(s_i)

    print(f"Sombor Index of Graph of Z_n: {s_i}")


'''
for i in range(n-4,1,-1):
        print("np",n-4)
        if Deg[0][i]==0:
            adj=[Link](adj,i,0)
            adj=[Link](adj,i,1)
            #vert=[Link](vert,i)
            #print(vert)
            #[Link](Deg,i)
    print(vert)
    print(adj)
    print(Deg)
'''
if __name__ =="__main__":
        main()

Enter n for Z_n:6

['', '', '', '']

[[0. 0. 0. 0.]

[0. 0. 0. 0.]

[0. 0. 0. 0.]

[0. 0. 0. 0.]]

['2', '', '', '']

['2', '3', '', '']

['2', '3', '4', '']

['2', '3', '4', '5']

[[0. 1. 0. 0.]

[1. 0. 1. 0.]

[0. 1. 0. 0.]

[0. 0. 0. 0.]]

[[1. 2. 1. 0.]]

print adj 1.0

2.23606797749979

print adj 1.0

4.47213595499958

Sombor Index of Graph of Z_n: 4.47213595499958

PS C:\Users\[Link]> &
C:/Users/[Link]/AppData/Local/Programs/Python/Python310/[Link]
d:/Python-project/[Link]

Enter n for Z_n:9

['', '', '', '', '', '', '']

[[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]]

['2', '', '', '', '', '', '']

['2', '3', '', '', '', '', '']

['2', '3', '4', '', '', '', '']

['2', '3', '4', '5', '', '', '']

['2', '3', '4', '5', '6', '', '']

['2', '3', '4', '5', '6', '7', '']

['2', '3', '4', '5', '6', '7', '8']

[[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 1. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 1. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0.]]

[[0. 1. 0. 0. 1. 0. 0.]]

print adj 1.0

1.4142135623730951

Sombor Index of Graph of Z_n: 1.4142135623730951

PS C:\Users\[Link]> &
C:/Users/[Link]/AppData/Local/Programs/Python/Python310/[Link]
d:/Python-project/[Link]

Enter n for Z_n:10

['', '', '', '', '', '', '', '']

[[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]]

['2', '', '', '', '', '', '', '']

['2', '3', '', '', '', '', '', '']

['2', '3', '4', '', '', '', '', '']

['2', '3', '4', '5', '', '', '', '']

['2', '3', '4', '5', '6', '', '', '']

['2', '3', '4', '5', '6', '7', '', '']

['2', '3', '4', '5', '6', '7', '8', '']

['2', '3', '4', '5', '6', '7', '8', '9']

['2', '3', '4', '5', '6', '7', '8', '9']

[[0. 0. 0. 1. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 1. 0. 0. 0. 0.]

[1. 0. 1. 0. 1. 0. 1. 0.]

[0. 0. 0. 1. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]

[0. 0. 0. 1. 0. 0. 0. 0.]

[0. 0. 0. 0. 0. 0. 0. 0.]]

[[1. 0. 1. 4. 1. 0. 1. 0.]]

print adj 1.0

4.123105625617661

print adj 1.0

8.246211251235321

print adj 1.0

12.36931687685298

print adj 1.0

16.492422502470642

Sombor Index of Graph of Z_n: 16.492422502470642


PS C:\Users\[Link]>

You might also like