當前位置: 首頁>>代碼示例>>Python>>正文


Python Net.set_options方法代碼示例

本文整理匯總了Python中net.Net.set_options方法的典型用法代碼示例。如果您正苦於以下問題:Python Net.set_options方法的具體用法?Python Net.set_options怎麽用?Python Net.set_options使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.Net的用法示例。


在下文中一共展示了Net.set_options方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: IscasOracle

# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import set_options [as 別名]
class IscasOracle(Description):
    
    def __init__(self, sisc_file, inputs, outputs, **options):
        super(IscasOracle, self).__init__([], **options)
        self.sisc_file = sisc_file
        self.comp_calls = 0
        self.check_calls = 0
        self.comp_time = 0
        self.check_time = 0
        self.scs = set()
        self.setup = False
        self.inputs = inputs
        self.outputs = outputs
        self.net = None
        
    def setup_net(self):
        if not self.setup:
            self.setup = True
            self.net = Net(*SimpleParser(open(self.sisc_file)).parse(), **self.options)
            for c,i in enumerate(self.net.inputs):
                self.net.inputs[i] = self.inputs[c] == 1
            for c,i in enumerate(self.net.outputs):
                self.net.outputs[i] = self.outputs[c] == 1
            self.components = TwoWayDict(dict(enumerate(self.net.gates.keys())))
            
    def set_options(self, **options):
        super(IscasOracle, self).set_options(**options)
        if self.net is not None:
            self.net.set_options(**options)
    
    def get_num_components(self):
        self.setup_net()
        return len(self.components)
        
    def get_conflict_set(self, h):
        self.setup_net()
        self.comp_calls += 1
        t0 = time.time()
        cs = self.net.calculate_conflicts(self.numbers_to_gates(h))
        t1 = time.time()
        self.comp_time += t1-t0
        if cs:
            self.scs.add(frozenset(cs))
            return self.gates_to_numbers(cs)
        else:
            return None
    
    def check_consistency(self, h):
        self.setup_net()
        self.check_calls += 1
        t0 = time.time()
        sat = self.net.check_consistency(self.numbers_to_gates(h))
        t1 = time.time()
        self.check_time += t1-t0
        return sat

    def get_next_diagnosis(self, previous_diagnoses, max_card=None):
        self.setup_net()
        self.comp_calls += 1
        t0 = time.time()
#        print "get_next_diagnosis(%s,%d)"%(previous_diagnoses, max_card)
        diag = self.net.calculate_next_diagnosis(map(self.numbers_to_gates,previous_diagnoses), max_card=max_card)
#        print "solution:", diag
        t1 = time.time()
        self.comp_time += t1-t0
        if diag:
            return self.gates_to_numbers(diag)
        else:
            return None
        
    def get_all_diagnoses(self, previous_diagnoses, max_card=None, max_solutions=None):
        self.setup_net()
        self.comp_calls += 1
        t0 = time.time()
        diag = self.net.calculate_next_diagnosis(map(self.numbers_to_gates,previous_diagnoses), max_card=max_card, find_all_sols=True)
        t1 = time.time()
        self.comp_time += t1-t0
        if diag:
            return map(self.gates_to_numbers, diag)
        else:
            return None
        

    def finished(self):
        self.net.finished()
        
    def gates_to_numbers(self, gates):
        return frozenset(map(lambda g: self.components.key(g), gates))
        
    def numbers_to_gates(self, numbers):
        return frozenset(map(lambda n: self.components[n], numbers))
開發者ID:zhoujh5510,項目名稱:myProject,代碼行數:93,代碼來源:oracle.py


注:本文中的net.Net.set_options方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。