Esempio n. 1
0
def instal_query():
    argparser = buildargparser()
    # additional parameters for instalquery
    argparser.add_argument(
        '-a', '--answer-set', type=int, default=0,
        help='choose an answer set (default all)')
    argparser.add_argument(
        '-l', '--length', type=int, default=1,
        help='length of trace (default 1)')
    argparser.add_argument(
        '-n', '--number', type=int, default=1,
        help='compute at most <n> models (default 1, 0 for all)')
    args,unk = argparser.parse_known_args()
    check_args(args,unk)
    model_files = instal_compile(args)
    initial_state = instal_state_facts(args)
    domain_facts = instal_domain_facts(args)
    oracle = Oracle(initial_state,model_files,domain_facts,args)
    # delete temporary files
    if os.path.dirname(args.output_file)=='/tmp': 
        if os.path.isdir(args.output_file):
            shutil.rmtree(args.output_file)
        else:
            os.remove(args.output_file)
    observed = []
    # enumerate the events in the query file
    for i,e in enumerate(fileinput.input(args.query)):
        observed += [Fun('observed',[parse_term(e).args()[0],i])]
    # note: events is a list of Fun not strings
    oracle.solve_iter(observed)
    # print("occurred = ",oracle.occurred)
    # print("holdsat = ",oracle.holdsat)
    # write LaTeX visualizations
    if args.trace_file:
        instal_trace(args,oracle.answersets)
    if args.gantt_file:
        instal_gantt(args,oracle.answersets)
    if args.text_file:
        instal_text(args,oracle.answersets)