def __init__(self, n, k): if n <= 0 or k <= 0: print "N and K must be integers > 0." exit_program() self.N = n self.K = k self.k_extend = 1 self.functions = Functions() self.classes = {} self.correlation = {} self.solution = {} self.partialClass = {} self.pedigree = {} self.allCalculated = {} self.start_time = 0 MB = 1024 * 1024 self.limit_of_partial_in_memory = 1024 # xMB self.batch_length = 100 self.db = DB() self.init_classes() try: self.functions.save(1, 1, self.k_extend, self.correlation, self.solution, self.classes, self.partialClass, self.allCalculated, self.db) self.functions.save_pedigree(self.pedigree, self.db) except: print 'The info its already saved'
def calculate_extended_classes(self, class_to_extend, n_of_the_class, extend_from, extend_to, print_results=True, pedigreeStruct=None, classesStruct=None, partialClassStruct=None): from src.database.databaseSol import DB db = DB() results = {} self.extend_class(self.hash(class_to_extend), n_of_the_class, extend_to, extend_from, db, pedigreeStruct, classesStruct, partialClassStruct) for current_hash in classesStruct[n_of_the_class][extend_to][ class_to_extend[0]]: for current_class, current_count in classesStruct[n_of_the_class][ extend_to][class_to_extend[0]][current_hash].items(): results[current_class] = current_count if pedigreeStruct is not None: #save correlations classes db.save(n=n_of_the_class, k=extend_from, k_extend=extend_to, w=class_to_extend[0], objects=classesStruct[n_of_the_class][extend_to][ class_to_extend[0]], type='correlation') #end of save correlations self.save_classes(classesStruct, n_of_the_class, extend_to, db, False) self.save_pedigree(pedigreeStruct, db) self.save_partial_class(partialClassStruct, n_of_the_class, extend_to, db, False) '''for r_aux in results: if self.is_correlation_immune(r_aux, n_of_the_class, extend_from): try: result[r_aux] += 1 except: result[r_aux] = 1''' if print_results: print '#####' * 15 print 'Original class: %s' % str(class_to_extend) print '#####' * 15 print 'Extending the class from k=%s to k=%s' % (extend_from, extend_to) print '\n'.join( [str(k) + ': ' + str(v) for k, v in results.items()]) print 'Total: %s classes' % len(results) print '#####' * 15 else: return results.items()
def __init__(self, n, k, i): self.N = n self.K = k self.I = i self.db = DB() self.functions = Functions() self.boolean_functions = { self.functions.hash((0, 0)): [0, 0], self.functions.hash((1, -1)): [0, 1], self.functions.hash((1, 1)): [1, 0], self.functions.hash((2, 0)): [1, 1] }
print '(n, k) = (%s,%s)' % (n, k) sleep(2) BooleanFunction(n, k, None).solve() elif option == 3: try: n = input('Select N: ') k = input('Select K: ') except: print 'N and K must be integers > 0.' continue print '(n, k) = (%s,%s)' % (n, k) sleep(2) functions = Functions() solutions = {} db = DB() functions.load_solution(n, k, solutions, db) functions.print_results(n, k, time.time(), None, solutions, True) if option == 31: try: n = input('Select N: ') k = input('Select K: ') k_extend = input('Select K_extend: ') w = input('Select W: ') class_tree = raw_input('Class (-1 no class): ') class_tree = tuple([int(e) for e in class_tree.split(',')]) except: print 'N, K, K_extend, W must be integers > 0' continue print '(n, k, k_extend, w) = (%s,%s,%s,%s)' % (n, k, k_extend, w) sleep(2)