2011-09-24 41 views

回答

4

在其中的你給的鏈接維基百科,還有一些「外部鏈接」在底部,其中有這些,有意思的相對到您的項目:

  • "Python Implementation by Robert Dick"

    止跌」這是否滿足您的需求?

  • 一系列描述R中實現的算法(一個或多個)兩篇文章:。first articlesecond article將R實現是詳盡的,它提供完整,準確的解決方案,它可以處理多達20個輸入變量

    您可以使用rpy Python interface來R語言來運行Quine-McCluskey算法的R代碼。請注意,有RPY的改寫:rpy2

    而且,爲什麼不自己寫一個新的Python腳本,使用由阿德里安DUSA在2007年完成的算法的提升,趴在second article

+0

六升起來了,我編碼我的心臟了,感謝參照該第二篇文章。謝謝! :) – eqb

5
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) 
+0

移植到JavaScript:https://gist.github.com/ysangkok/5707171#file-smallqm-js –

+0

謝謝,也解決了我的問題:) – HighwayJohn

+0

這個算法是否只計算主要暗示或也是必不可少的主要牽連? – HighwayJohn