RMG-Py icon indicating copy to clipboard operation
RMG-Py copied to clipboard

Check isomorphism of lists with 4+ species

Open zhaoyangwx opened this issue 3 years ago • 0 comments

Motivation or Problem

Sometimes need to compare reaction with 4+ reactants/products.

Description of Changes

Added checking for list with 4+ reactants/products. Added limitation of list length to prevent too long input causing hanging. Improved performance by adjusting sequence to avoid unnecessary calculation of list length.

Testing

Tested with simplified program:

list1 = [1,2,3,4,6,5]
list2 = [6,5,2,4,1,3]
list3 = [6,2,3,1,1,4]
list4 = [7,2,3,1,5,4]
def same(x,y):
	return (x==y)
def issamelist(l1,l2):
	l1=l1[:]
	l2=l2[:]
	x=0
	while x<len(l1):
		found_y = False
		for y in range(len(l2)):
			if same(l1[x],l2[y]):
				found_y = True
				del l1[x]
				x-=1
				del l2[y]
				break
		if not(found_y):
			return False
		x+=1
	return (len(l1)==0) and (len(l2)==0)
print(issamelist(list1,list2))
print(issamelist(list1,list3))
print(issamelist(list1,list4))
print(list1)

######output######
True
False
False
[1, 2, 3, 4, 6, 5]

Reviewer Tips

maximum_length may be adjusted

zhaoyangwx avatar May 09 '22 13:05 zhaoyangwx