Esempio n. 1
0
 def execute_with_model(self, model: pe.ConcreteModel, args):
     tables = [
         self._output_variables_information(model),
         self._output_objectives_information(model),
         self._output_constraints_information(model),
     ]
     print_output_table(tables, args)
Esempio n. 2
0
 def execute_with_problem(self, _model, problem, args):
     tables = [
         self._output_variables_information(problem),
         self._output_objectives_information(problem),
         self._output_constraints_information(problem),
     ]
     print_output_table(tables, args)
Esempio n. 3
0
 def execute_with_model(self, model, args):
     bounds = perform_fbbt(model, max_iter=100)
     mono, cvx = propagate_special_structure(model, bounds)
     tables = []
     tables.append(self._output_variables(model, bounds, mono, cvx))
     tables.append(self._output_objectives(model, bounds, mono, cvx))
     tables.append(self._output_constraints(model, bounds, mono, cvx))
     print_output_table(tables, args)
Esempio n. 4
0
    def execute_with_problem(self, _model, problem, args):
        ctx = detect_special_structure(problem, timelimit=300, maxiter=100)

        tables = []
        tables.append(self._output_variables(problem, ctx))
        tables.append(self._output_objectives(problem, ctx))
        tables.append(self._output_constraints(problem, ctx))
        print_output_table(tables, args)
Esempio n. 5
0
 def execute(self, args):
     method_name = self._methods.get(args.selection, None)
     method = getattr(self, method_name,
                      None) if method_name is not None else None
     if method is None:
         print('Callback for selection {} not found.'.format(
             args.selection))
         print(
             'This is a bug in GALINI. Please open an issue at https://github.com/cog-imperial/galini'
         )
         sys.exit(1)
     result = method()
     print_output_table(result, args)
     print()
Esempio n. 6
0
    def execute_with_model(self, model, args):
        galini = Galini()

        if args.config:
            galini.update_configuration(args.config)

        solution = galini.solve(
            model,
            args.algorithm,
            known_optimal_objective=args.known_optimal_objective)

        status_table = OutputTable('Solution', [{
            'id': 'status',
            'name': 'Status',
            'type': 't'
        }])

        if solution is None:
            status_table.add_row({'status': 'unboundedOrInfeasible'})
            print_output_table([status_table], args)
            return

        status_table.add_row({'status': solution.status.description()})

        obj_table = OutputTable('Objectives', [
            {
                'id': 'name',
                'name': 'Objective',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])

        obj_table.add_row({
            'name': 'objective',
            'value': solution.objective,
        })

        var_table = OutputTable('Variables', [
            {
                'id': 'name',
                'name': 'Variable',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])
        for var in solution.variables:
            var_table.add_row({
                'name': var.name,
                'value': var.value,
            })

        counter_table = OutputTable('Counters', [
            {
                'id': 'name',
                'name': 'Name',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])
        for counter in galini.telemetry.counters_values():
            counter_table.add_row(counter)

        print_output_table([status_table, obj_table, var_table, counter_table],
                           args)
Esempio n. 7
0
    def execute_with_problem(self, model, problem, args):
        galini = Galini()
        if args.config:
            galini.update_configuration(args.config)

        solver_cls = galini.get_solver(args.solver.lower())

        if solver_cls is None:
            available = ', '.join(solvers_reg.keys())
            print('Solver {} not available. Available solvers: {}'.format(
                args.solver, available))
            sys.exit(1)

        apply_logging_config(galini.get_configuration_group('logging'))
        solver = solver_cls(galini)

        galini_group = galini.get_configuration_group('galini')
        timelimit = galini_group.get('timelimit')
        elapsed_counter = galini.telemetry.create_gauge('elapsed_time', 0.0)

        set_timelimit(timelimit)
        start_timelimit()
        start_time = current_time()

        solver.before_solve(model, problem)

        solution = solver.solve(
            problem, known_optimal_objective=args.known_optimal_objective)

        elapsed_counter.set_value(seconds_elapsed_since(start_time))

        if solution is None:
            raise RuntimeError('Solver did not return a solution')

        obj_table = OutputTable('Objectives', [
            {
                'id': 'name',
                'name': 'Objective',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])

        value = solution.objective.value
        if not problem.objective.original_sense.is_minimization():
            if value is not None:
                value = -value

        obj_table.add_row({
            'name': solution.objective.name,
            'value': value,
        })

        var_table = OutputTable('Variables', [
            {
                'id': 'name',
                'name': 'Variable',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])
        for var in solution.variables:
            var_table.add_row({
                'name': var.name,
                'value': var.value,
            })

        counter_table = OutputTable('Counters', [
            {
                'id': 'name',
                'name': 'Name',
                'type': 't'
            },
            {
                'id': 'value',
                'name': 'Value',
                'type': 'f'
            },
        ])
        for counter in galini.telemetry.counters_values():
            counter_table.add_row(counter)

        print_output_table([obj_table, var_table, counter_table], args)