def solve(self, formula_wrapper): dimacs, clauses, num_to_name, quantifiers = get_qcnf(formula_wrapper) is_sat, certificate = pydepqbf.solve(quantifiers, clauses) if is_sat == QDPLL_RESULT_UNSAT: return unsat, False model = MyModel({num_to_name[abs(val)]: BoolVal(True) if val > 0 else BoolVal(False) for val in certificate}) return sat, model
def generalize_cube(z3_formula, model, all_vars): assigned_vars = set([_v for _v in all_vars if model[_v] is not None]) my_model = MyModel({v: model[v] for v in assigned_vars}) go_over_vars = list(assigned_vars) for _var in go_over_vars: model_tag = MyModel(dict(my_model.assignment)) model_tag[_var] = BoolVal(is_false(my_model[_var])) z3_assigned = simplify( substitute(z3_formula, *[(_v, model_tag[_v]) for _v in assigned_vars])) if is_false(z3_assigned): continue s = SatSolverSelector.SatSolverCtor() res = s.add(z3_assigned) if res and s.check(): assigned_vars -= {_var} my_model.unassign(_var) return my_model
def solve(self, formula): dimacs, clauses, num_to_name, quantifiers = get_qcnf(formula) print 'BEFORE CAEQ' qdimacs = to_qdimacs(dimacs, quantifiers) path = '__qdimacs.txt' to_file(path, qdimacs) out_path = 'qdimacs_out.txt' cmd_do_caqe = '{caqe} {input} --qdo > {out}'.format(caqe=CAQE_PATH, input=path, out=out_path) os.system(cmd_do_caqe) is_sat, certificate = time_me(pydepqbf.solve, [quantifiers, clauses], 'QBF:: ') print 'CAQE ', is_sat, certificate del_file(path) del_file(out_path) if is_sat == QDPLL_RESULT_UNSAT: return unsat, False model = MyModel({num_to_name[abs(val)]: BoolVal(True) if val > 0 else BoolVal(False) for val in certificate}) return sat, model
width_shift_range=0.1, height_shift_range=0.1, zoom_range=(0.9, 1.1), rescale=1.0/255.0 ) validation_generator = validation_datagen.flow_from_directory( directory=validation_data_dir, target_size=(Common.IMG_HEIGHT, Common.IMG_WIDTH), classes=Common.CLASSES, class_mode='categorical', batch_size=batch_size, shuffle=True ) model = MyModel.get_model() model.compile( loss='categorical_crossentropy', optimizer=optimizers.Adagrad(), metrics=['accuracy'] ) model.summary() if train_weights_file is not None: model.load_weights(train_weights_file) print('load_weights:', train_weights_file) checkpoint = ModelCheckpoint( epoch_weights_file, save_weights_only=True, verbose=1
def model(self): raw_model = self._solver.get_model() model = MyModel({self._num_to_name[val]: BoolVal(val > 0) for val in raw_model}) return model