def run_dtproblog(node_size): model_text = generate_program(node_size) print(model_text) program = PrologString(model_text) decisions, score, statistics = dtproblog(program) print("++++++++ Program for node size = "+ str(node_size)+"++++++++") for name, value in decisions.items(): print ('%s: %s' % (name, value))
def decidi(self, prolog): '''prende la decisione''' temp = self.conoscenza evidence = self.get_used_card_evidence(prolog) for ev in evidence: temp += ev utilities = self.get_utility(prolog) for ut in utilities: temp += ut program = PrologString(temp) decisions, _, _ = dtproblog(program) for _, value in decisions.items(): if value == 1: return True print('STO\n') return False
def run_dtproblog(node_size, model_path, output_file): text = '' model_text = get_program(model_path, node_size) print(model_text) program = PrologString(model_text) current_milli_time = lambda: int(round(time.time() * 1000)) decisions, score, statistics = dtproblog(program) after_milli_time = lambda: int(round(time.time() * 1000)) processing_time = after_milli_time - current_milli_time text+="++++++++ Program for node size = "+ str(node_size)+"++++++++"+'\n' text+= '+ statistics: '+str(statistics)+'\n' text+= '+ score: '+str(score)+'\n' text+= '+ processing time: '+str(processing_time)+'\n' print("++++++++ Program for node size = "+ str(node_size)+"++++++++") for name, value in decisions.items(): print ('%s: %s' % (name, value)) text+= str(name)+'\t'+str(value)+'\n' save_file(output_file, text)
def generate_offer(self) -> Offer: if not self.offer_queue: program = PrologString(self._compile_dtproblog_model()) query_output, score, _ = dtproblog(program) # score of offers are now below acceptability threshold # so we should terminate if score < self.acceptability_threshold: self.active = False raise StopIteration() cleaned_query_output = self._clean_query_output(query_output) extended_offers = self._extend_partial_offer(cleaned_query_output) for offer in extended_offers: if offer not in self.generated_offers: self.generated_offers[offer.get_sparse_repr()] = score self.offer_queue.append(offer) if not self.offer_queue: raise RuntimeError() return self.offer_queue.pop()
from problog.tasks.dtproblog import dtproblog from problog.program import PrologString from problog.program import PrologFile program = PrologFile("models/poicarp.pl") decisions, score, statistics = dtproblog(program) for name, value in decisions.items(): print ('%s: %s' % (name, value)) print score print statistics