-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
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
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') | ||
|
||
|
||
|
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
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') |
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
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); | ||
|
||
|