Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tksaha authored Apr 3, 2018
1 parent 8af1013 commit 0821ac2
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
37 changes: 37 additions & 0 deletions check_undirected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
@author: mmrahman,tksaha
'''
import sys
if len(sys.argv) != 2: #program name and 1 arg
sys.exit("usage: check_undirected in")

f_in=open(sys.argv[1]+'.txt','r')
f_out=open(sys.argv[1]+'UND.txt','w')
#f_dup=open(sys.argv[1]+'DUP.txt','w')

edges=set()
for line in f_in:
splits=line.split()
#print(line)
if len(splits)==0:
continue
v1=int(splits[0])
v2=int(splits[1])
if v1<v2:
e=str(v1)+'\t'+str(v2)
elif v2<v1:
e=str(v2)+'\t'+str(v1)
else:
print(str(v1)+' '+str(v2))
continue
if e not in edges:
edges.add(e)
f_out.write(e)
f_out.write('\n')
#else:
# f_dup.write(e)
# f_dup.write('\n')



86 changes: 86 additions & 0 deletions make_connected_BFS_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!usr/bin/python
#input graph must be in edge list. No duplicate edge. No self edge.
import sys
import queue
import operator

def BFS():
while vc.empty()==False:
u=vc.get_nowait()
#print('out:')
#print(u)

for y in adj[u]:
if v[y]==0:
v[y]=1
con.add(y)
vc.put(y)
#print('in:')
#print(y)
v[u]=2


if len(sys.argv) != 2: #program name and infile
sys.exit("usage: check_undirected in")

f_in=open(sys.argv[1],'r')
f_out=open(sys.argv[1]+'BFSCON','w')

v={}
adj={}
vc=queue.Queue()

con=set()

t=0
for line in f_in:
t+=1
#if operator.mod(t,100000) == 0:
# print(t)

splits=line.split()
if (len(splits)==0):
continue;
if splits[0] not in v:
v[splits[0]]=0
adj[splits[0]]=set()
if splits[1] not in v:
v[splits[1]]=0
adj[splits[1]]=set()
adj[splits[0]].add(splits[1])
adj[splits[1]].add(splits[0])

print('graph loaded')

for x in v:
if v[x]==1:
print('error')
if v[x]==2:
#vc=set()
continue
if v[x]==0:
con.clear()
con.add(x)
vc=queue.Queue()
vc.put(x)
v[x]=1
BFS()
print(len(con))
print(len(v))
if len(con) > len(v)/2:
break
f_in.close()
f_in=open(sys.argv[1],'r')

for line in f_in:
splits=line.split()
if (len(splits)==0):
continue;
if splits[0] not in con:
continue
if splits[1] not in con:
continue
f_out.write(line)
#print(len(con))

print('connect largest ready')
48 changes: 48 additions & 0 deletions make_proper_input_file_for_mcmc_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os;
import sys;

# @author: Tanay Kumar Saha
# @email: [email protected]


# Parameter 1: input file (graph file)
# Each line contains a pair (st tab end);
inputfile = open (sys.argv[1]);

#Output file:
output_file = open (sys.argv[1]+"-mcmc-format","w");
input_mapping_file = open (sys.argv[1]+"-mappings","w");

node_list=[];

# read the file for the first pass
for line in inputfile:
lineelems = line.strip().split("\t");
node_list.append (int(lineelems[0]));
node_list.append (int(lineelems[1]));


uniq_nodeid_list = list (sorted(set (node_list)));


# read the input file for the second pass, build the correct input file
# write the mapping

inputfile = open (sys.argv[1]);
inputfile_mappings ={};

#populate the mapping

for pos in range (0,len(uniq_nodeid_list)):
inputfile_mappings [ uniq_nodeid_list[pos]]= pos;
input_mapping_file.write (str(uniq_nodeid_list[pos])+"\t"+str(pos)+os.linesep);



for line in inputfile:
lineelems = line.strip().split("\t");
st = inputfile_mappings[int(lineelems[0])];
end = inputfile_mappings [int (lineelems [1])];
output_file.write (str(st)+"\t"+str(end)+"\t"+"1"+"\t"+"1"+"\t"+"1"+os.linesep);


0 comments on commit 0821ac2

Please sign in to comment.