def intersect(file1,type1,file2,type2):
	p1l1=extractpath(file1,type1)
	p1l2=[-1]+(p1l1)
	p1=zip(p1l1,p1l2)
	p1s=set([frozenset(i)for i in p1])

	p2l1=extractpath(file2,type2)
	p2l2=[-1]+(p2l1)
	p2=zip(p2l1,p2l2)
	p2s=set([frozenset(i)for i in p2])
	return list(p1s.intersection(p2s))
def run():			
	for c in range(gridsize):
		for d in range(gridsize):
			problem=str(c)+"_"+str(d)
			
			#Read coords
			coords=[]
			with open("../LKH/temp/"+adjust+"cut"+problem+".csv", "rb") as f:
			    for i in csv.reader(f):
			        coords.append([int(j) for j in i[1:]])
			print len(coords)
			ans=[]
			#Create distance matrix
			ans=(pdist(coords,"euclidean"))
			sans2=[]
			sans2=[int(b) for b in ans]
			mapper={}
			
			#Read mapper
			with open("../LKH/temp/"+adjust+"mapper"+problem+".csv", "rb") as f:
				for i in csv.reader(f):
					mapper[int(i[1])]=int(i[0])
			
			print problem
			width=len(coords)
			
			if secondpath:
				fans1l1=extractpath("../LKH/s"+aset+"path1/besttour_totcut"+problem+".tsp","tsp")
				fans1l2=[-1]+(fans1l1)

				fans1=zip(fans1l1,fans1l2)
				#print fans1[1:5]
				sans2=makeinf(fans1,sans2,width)
	
			fans=[]
			fans=createdm(sans2,width)
			#Write distance matrix
			with open("../LKH/dm"+problem+".tsp","wb") as ff:
				ff.write("NAME : cutter\n"+\
						"TYPE : TSP\n"+\
						"DIMENSION : "+str(len(coords))+"\n"+\
						"EDGE_WEIGHT_TYPE : EXPLICIT\n"+\
						"EDGE_WEIGHT_FORMAT : UPPER_ROW\n"+\
						"NODE_COORD_TYPE : NO_COORDS\n"+\
						"EDGE_WEIGHT_SECTION\n")
			
				csv.writer(ff,delimiter=" ").writerows(fans)