Example #1
0
def run(csv_file, solvers_dir, input_file, option_file):
    FileManager.write_to_file(csv_file, 'a', input_file, True, True)

    for solver in Solver.get_solvers():
        if not FileManager.solver_present(solvers_dir,
                                          solver.value + '.solver'):
            continue

        answer_sets = []
        input_program = ASPInputProgram()
        handler = DesktopHandler(solver.get_service(solvers_dir))
        option_id = handler.add_option(
            OptionDescriptor(solver.get_output_option()))

        if option_file is not None and option_file != "" and option_file.lower(
        ) != "-no-option-file":
            for _filter in FileManager.read_filters(option_file, solver):
                handler.add_option(OptionDescriptor(' ' + _filter))

        handler.add_program(input_program)
        input_program.add_files_path(input_file)

        sorted_output = OutputManager.process_raw_output(
            solver.value,
            handler.start_sync().get_answer_sets_string())

        handler.remove_option_from_id(option_id)

        start_time = time.time()

        for answer_set in handler.start_sync().get_answer_sets():
            answer_sets.append(answer_set.get_atoms())

        end_time = time.time()

        FileManager.write_to_file(
            csv_file, 'a', solver.value + ':' + str(end_time - start_time),
            None, True)

        if answer_sets:
            for answer_set in answer_sets:
                tmp = ' '.join(sort_facts(answer_set))

                if tmp not in sorted_output:
                    print('ERROR! Original ' + solver.value +
                          ' output does not contain:\n' + tmp + '\n')

    print('END')
Example #2
0
    def start_sync(self, programs, options):
        """Calls start_sync method of a superclass and returns its output
        object."""

        new_options = list(options)
        new_options.append(OptionDescriptor("--t"))
        return super(IDLVDesktopService,
                     self).start_sync(programs, new_options)
Example #3
0
    def start_sync(self, programs, options):
        """Start a new process for the _exe_path and starts solving
        syncronously."""
        option = ""
        for o in options:
            if o is not None:
                option += o.get_options()
                option += o.get_separator()
            else:
                print("Warning : wrong " +
                      str(OptionDescriptor().__class__.__name__))
        files_paths = ""
        final_program = ""
        for p in programs:
            if p is not None:
                final_program += p.get_programs()
                program_file = p.get_string_of_files_paths()
                if program_file is not None:
                    files_paths += program_file
            else:
                print("Warning : wrong " +
                      str(InputProgram().__class__.__name__))

        if self._exe_path is None:
            return Output("", "Error: executable not found")

        exep = str(self._exe_path)

        opt = str(option)

        lis = list()
        lis.append(exep)
        if opt != "":
            lis.append(opt)
        lis.append(files_paths[:-1])
        if self._load_from_stdin_option != "":
            lis.append(self._load_from_stdin_option)

        print(exep + " " + opt + " " + files_paths +
              self._load_from_stdin_option)

        start = int(time.time() * 1e+9)

        proc = subprocess.Popen(
            lis,
            universal_newlines=True,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
        )

        output, error = proc.communicate(final_program)

        end = int(time.time() * 1e+9)

        print("Total time : " + str(end - start))
        print("")

        return self._get_output(output, error)
Example #4
0
 def __init__(self, exe_path):
     super(DLV2DesktopService, self).__init__(exe_path)
     self._load_from_stdin_option = "--"
     self.competition_output_option = OptionDescriptor(
         "--competition-output")