def solve(self, solver_setup, specs, dump=None, nmodels=0, timers=False, stats=False, tests=False):
    timer = spack.util.timer.Timer()
    self.control = clingo.Control()
    self.control.configuration.solve.models = nmodels
    self.control.configuration.asp.trans_ext = 'all'
    self.control.configuration.asp.eq = '5'
    self.control.configuration.configuration = 'tweety'
    self.control.configuration.solve.parallel_mode = '2'
    self.control.configuration.solver.opt_strategy = 'usc,one'
    self.assumptions = []
    with self.control.backend() as backend:
        self.backend = backend
        solver_setup.setup(self, specs, tests=tests)
    timer.phase('setup')
    parent_dir = os.path.dirname(__file__)
    self.control.load(os.path.join(parent_dir, 'concretize.lp'))
    self.control.load(os.path.join(parent_dir, 'display.lp'))
    timer.phase('load')
    self.control.ground([('base', [])])
    timer.phase('ground')
    result = Result(specs)
    models = []
    cores = []

    def on_model(model):
        models.append((model.cost, model.symbols(shown=True, terms=True)))
    solve_kwargs = {'assumptions': self.assumptions, 'on_model': on_model, 'on_core': cores.append}
    if clingo_cffi:
        solve_kwargs['on_unsat'] = cores.append
    solve_result = self.control.solve(**solve_kwargs)
    timer.phase('solve')
    result.satisfiable = solve_result.satisfiable

    def stringify(x):
        if clingo_cffi:
            try:
                return x.string
            except RuntimeError:
                return str(x)
        else:
            return (x.string or str(x))
    if result.satisfiable:
        builder = SpecBuilder(specs)
        (min_cost, best_model) = min(models)
        tuples = [(sym.name, [stringify(a) for a in sym.arguments]) for sym in best_model]
        answers = builder.build_specs(tuples)
        result.answers.append((list(min_cost), 0, answers))
        criteria = [(int(args[0]), args[1]) for (name, args) in tuples if (name == 'opt_criterion')]
        result.criteria = [t[1] for t in sorted(criteria, reverse=True)]
        result.nmodels = len(models)
    elif cores:
        symbols = dict(((a.literal, a.symbol) for a in self.control.symbolic_atoms))
        for core in cores:
            core_symbols = []
            for atom in core:
                sym = symbols[atom]
                if (sym.name == 'rule'):
                    sym = sym.arguments[0].string
                core_symbols.append(sym)
            result.cores.append(core_symbols)
    if timers:
        timer.write_tty()
        print()
    if stats:
        print('Statistics:')
        pprint.pprint(self.control.statistics)
    return result
def solve(self, solver_setup, specs, dump=None, nmodels=0, timers=False, stats=False, tests=False):
    timer = spack.util.timer.Timer()
    self.control = clingo.Control()
    self.control.configuration.solve.models = nmodels
    self.control.configuration.asp.trans_ext = 'all'
    self.control.configuration.asp.eq = '5'
    self.control.configuration.configuration = 'tweety'
    self.control.configuration.solve.parallel_mode = '2'
    self.control.configuration.solver.opt_strategy = 'usc,one'
    self.assumptions = []
    with self.control.backend() as backend:
        self.backend = backend
        solver_setup.setup(self, specs, tests=tests)
    timer.phase('setup')
    parent_dir = os.path.dirname(__file__)
    self.control.load(os.path.join(parent_dir, 'concretize.lp'))
    self.control.load(os.path.join(parent_dir, 'display.lp'))
    timer.phase('load')
    self.control.ground([('base', [])])
    timer.phase('ground')
    result = Result(specs)
    models = []
    cores = []

    def on_model(model):
        models.append((model.cost, model.symbols(shown=True, terms=True)))
    solve_kwargs = {'assumptions': self.assumptions, 'on_model': on_model, 'on_core': cores.append}
    if clingo_cffi:
        solve_kwargs['on_unsat'] = cores.append
    solve_result = self.control.solve(**solve_kwargs)
    timer.phase('solve')
    result.satisfiable = solve_result.satisfiable

    def stringify(x):
        if clingo_cffi:
            try:
                return x.string
            except RuntimeError:
                return str(x)
        else:
            return (x.string or str(x))
    if result.satisfiable:
        builder = SpecBuilder(specs)
        (min_cost, best_model) = min(models)
        tuples = [(sym.name, [stringify(a) for a in sym.arguments]) for sym in best_model]
        answers = builder.build_specs(tuples)
        result.answers.append((list(min_cost), 0, answers))
        criteria = [(int(args[0]), args[1]) for (name, args) in tuples if (name == 'opt_criterion')]
        result.criteria = [t[1] for t in sorted(criteria, reverse=True)]
        result.nmodels = len(models)
    elif cores:
        symbols = dict(((a.literal, a.symbol) for a in self.control.symbolic_atoms))
        for core in cores:
            core_symbols = []
            for atom in core:
                sym = symbols[atom]
                if (sym.name == 'rule'):
                    sym = sym.arguments[0].string
                core_symbols.append(sym)
            result.cores.append(core_symbols)
    if timers:
        timer.write_tty()
        print()
    if stats:
        print('Statistics:')
        pprint.pprint(self.control.statistics)
    return result