# Regular Graph
# author: Pedro Garcia Lopez
# 


def toPajek(graph, filename):
    f = open(filename,'w')
    size = len(graph)
    f.write('*Vertices '+str(size)+'\n')
    for i in range(1,size+1):
        f.write(' '+str(i)+' "'+str(i)+'"\n')
    f.write('*Edges\n')
    for i in range(1,size+1):
        for conn in graph[i]:
            f.write(' '+str(i)+' '+str(conn)+' 1\n')
    f.close()

def show(graph):
    size = len(graph)
    print '-------REGULAR GRAPH-------'
    for x in range(1,size+1):
        print x,conns[x]
        
            


size = 12
k = 4
conns = {}
for i in range(1,size+1):
    conns[i] = []
    for conn in range(1,k/2+1):
            newcon = ((i+conn)%size)
            if newcon==0:
            	newcon = size
            conns[i].append(newcon)
            newcon2 = ((i-conn)%size)
            if newcon2==0:
            	newcon2 = size
            conns[i].append(newcon2)


show(conns)
toPajek(conns,'regular.net')



