我试图在python中编写Quine-McCluskey algorithm,但我想查看是否有任何可用的替代版本。谷歌搜索显示了一些有用的结果。我正在寻找4x4地图缩减,而不是2x2或3x3。任何想法或参考?Python中的Quine-McCluskey算法
回答
在其中的你给的链接维基百科,还有一些“外部链接”在底部,其中有这些,有意思的相对到您的项目:
"Python Implementation by Robert Dick"
止跌”这是否满足您的需求?
“一系列描述R中实现的算法(一个或多个)两篇文章:。first article和second article将R实现是详尽的,它提供完整,准确的解决方案,它可以处理多达20个输入变量“
您可以使用rpy Python interface来R语言来运行Quine-McCluskey算法的R代码。请注意,有RPY的改写:rpy2
而且,为什么不自己写一个新的Python脚本,使用由阿德里安DUSA在2007年完成的算法的提升,趴在second article?
def combine(m, n):
a = len(m)
c = ''
count = 0
for i in range(a):
if(m[i] == n[i]):
c += m[i]
elif(m[i] != n[i]):
c += '-'
count += 1
if(count > 1):
return None
else:
return c
def find_prime_implicants(data):
newList = list(data)
size = len(newList)
IM = []
im = []
im2 = []
mark = [0]*size
m = 0
for i in range(size):
for j in range(i+1, size):
c = combine(str(newList[i]), str(newList[j]))
if c != None:
im.append(str(c))
mark[i] = 1
mark[j] = 1
else:
continue
mark2 = [0]*len(im)
for p in range(len(im)):
for n in range(p+1, len(im)):
if(p != n and mark2[n] == 0):
if(im[p] == im[n]):
mark2[n] = 1
for r in range(len(im)):
if(mark2[r] == 0):
im2.append(im[r])
for q in range(size):
if(mark[q] == 0):
IM.append(str(newList[q]))
m = m+1
if(m == size or size == 1):
return IM
else:
return IM + find_prime_implicants(im2)
minterms = set(['1101', '1100', '1110', '1111', '1010', '0011', '0111', '0110'])
minterms2 = set(['0000', '0100', '1000', '0101', '1100', '0111', '1011', '1111'])
minterms3 = set(['0001', '0011', '0100', '0110', '1011', '0000', '1000', '1010', '1100', '1101'])
print 'PI(s):', find_prime_implicants(minterms)
print 'PI2(s):', find_prime_implicants(minterms2)
print 'PI3(s):', find_prime_implicants(minterms3)
移植到JavaScript:https://gist.github.com/ysangkok/5707171#file-smallqm-js –
谢谢,也解决了我的问题:) – HighwayJohn
这个算法是否只计算主要暗示或也是必不可少的主要牵连? – HighwayJohn
- 1. python中的迭代算法
- 2. python中的min max算法
- 3. python中的Gauss-Legendre算法
- 4. Dijkstra在python中的算法
- 5. Python中的算法设计
- 6. Python中的BFS算法
- 7. Python中的Two's Complement算法
- 8. Python - Dijkstra的算法
- 9. Python Negamax算法
- 10. 算法python itertools.permutations
- 11. Python Dijkstra算法
- 12. Python算法问题
- 13. Python算法效率
- 14. 在Python中的差异算法实现
- 15. 试图解决Python中的PIN算法
- 16. Python中的s-t切割算法
- 17. Python中的列表乘法运算
- 18. Python中的匈牙利算法
- 19. 算法Scrypt和PBKDF2 - Python的
- 20. Python的乘法运算
- 21. 优化(python)算法的最佳方法?
- 22. 在python中计算体积或表面积的好算法
- 23. 使用Python计算图中连接组件的算法
- 24. 计算T(n)?算法效率(Python)
- 25. 算法在Python中被破解了吗?
- 26. Python在fractions.gcd()中使用什么算法?
- 27. 如何在Python中应用Viterbi算法
- 28. AdaBoost ML算法python实现
- 29. 洪水填充算法Python
- 30. Park Miller算法(python 3)
六升起来了,我编码我的心脏了,感谢参照该第二篇文章。谢谢! :) – eqb