ExampleΒΆ

Here we present one simple example of executing the solver with model from MINLPlib:

 1import os
 2import sys
 3from pyomo.environ import *
 4
 5# add Decogo source files to path
 6# very important to do it before importing Decogo
 7path = os.path.dirname(os.getcwd())
 8while os.path.basename(path) != 'decogo':
 9    path = os.path.dirname(path)
10sys.path.insert(0, path)
11
12from decogo.solver.decogo import DecogoSolver
13
14
15if __name__ == '__main__':
16    # define Pyomo model
17    model = m = ConcreteModel()
18
19    m.x1 = Var(within=Reals, bounds=(0, None), initialize=0.302884615384618)
20    m.x2 = Var(within=Reals, bounds=(0, None), initialize=0.0865384615384593)
21    m.x3 = Var(within=Reals, bounds=(0, None), initialize=0.504807692307693)
22    m.x4 = Var(within=Reals, bounds=(0, None), initialize=0.10576923076923)
23    m.b6 = Var(within=Binary, bounds=(0, 1), initialize=0)
24    m.b7 = Var(within=Binary, bounds=(0, 1), initialize=0)
25    m.b8 = Var(within=Binary, bounds=(0, 1), initialize=0)
26    m.b9 = Var(within=Binary, bounds=(0, 1), initialize=0)
27
28    m.obj = Objective(expr=m.x1 * (4 * m.x1 + 3 * m.x2 - m.x3) + m.x2 * (
29                3 * m.x1 + 6 * m.x2 + m.x3) + m.x3 * (m.x2 - m.x1 + 10 * m.x3)
30                      , sense=minimize)
31
32    m.c1 = Constraint(expr=m.x1 + m.x2 + m.x3 + m.x4 == 1)
33
34    m.c2 = Constraint(expr=8 * m.x1 + 9 * m.x2 + 12 * m.x3 + 7 * m.x4 == 10)
35
36    m.c4 = Constraint(expr=m.x1 - m.b6 <= 0)
37
38    m.c5 = Constraint(expr=m.x2 - m.b7 <= 0)
39
40    m.c6 = Constraint(expr=m.x3 - m.b8 <= 0)
41
42    m.c7 = Constraint(expr=m.x4 - m.b9 <= 0)
43
44    m.c8 = Constraint(expr=m.b6 + m.b7 + m.b8 + m.b9 <= 3)
45
46    with open('decogo.set', 'w') as file:
47        file.write('strategy = CG\n')
48        file.write('maxtime = 1000\n')
49        file.write('cg_max_iter = 5\n')
50        file.write('cg_sub_gradient_max_iter = 3\n')
51        file.write('decomp_estimate_var_bounds = False\n')
52        file.write('cg_normalize_duals = False\n')
53        file.write('cg_max_main_iter = 20\n')  # main iteration limit
54        # ========================= primal heuristics =========================
55        file.write('cg_find_solution = True\n')
56        # ===================================================================
57        file.write('cg_fast_fw = False\n')  # switch off fast CG
58        file.write('cg_fast_approx = True\n')  # using exact problem
59        # solving in fast CG
60
61        file.close()
62
63    # create solver instance
64    solver = DecogoSolver()
65
66    # solve the model
67    solver.optimize(model)