Last active
June 5, 2023 20:58
-
-
Save shakayami/04f592a5927e7833ca67c9e1e880003c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy import * | |
def lattice_graph(H,W): | |
N=H*W | |
G=[[] for i in range(N)] | |
for i in range(H-1): | |
for j in range(W): | |
x=i*W+j | |
y=(i+1)*W+j | |
G[x].append(y) | |
G[y].append(x) | |
for i in range(H): | |
for j in range(W-1): | |
x=i*W+j | |
y=i*W+j+1 | |
G[x].append(y) | |
G[y].append(x) | |
return G | |
def comb_resist(G,in_term=0,out_term=-1): | |
N=len(G) | |
A=[[0 for j in range(N+1)]for i in range(N)] | |
for i in range(N): | |
for j in G[i]: | |
A[i][i]+=1 | |
A[i][j]-=1 | |
A[in_term][N]+=1 | |
A[out_term][N]-=1 | |
A_mat=Matrix(A) | |
A_rref=A_mat.rref() | |
return A_rref[0][in_term,-1]-A_rref[0][out_term,-1] | |
#sample code | |
#cube | |
G=[[] for i in range(8)] | |
for i in range(8): | |
for x in [1,2,4]: | |
G[i].append(i^x) | |
print(comb_resist(G)) | |
#5/6 | |
print(comb_resist(G,in_term=0,out_term=3)) | |
#3/4 | |
G=[[1,1],[0,0,2],[1]] | |
print(comb_resist(G)) | |
#3/2 | |
G=lattice_graph(2,3) | |
print(comb_resist(G)) | |
#7/5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment