-
Notifications
You must be signed in to change notification settings - Fork 9
/
solver_definition.py
76 lines (54 loc) · 1.85 KB
/
solver_definition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy as np
import casadi as cd
def define_parameters(modules, params, settings):
# Define parameters for objectives and constraints (in order)
for module in modules.modules:
if module.type == "objective":
module.define_parameters(params)
for module in modules.modules:
if module.type == "constraint":
module.define_parameters(params)
return params
def objective(modules, z, p, model, settings, stage_idx):
cost = 0.0
params = settings["params"]
params.load(p)
model.load(z)
for module in modules.modules:
if module.type == "objective":
cost += module.get_value(model, params, settings, stage_idx)
# if stage_idx == 0:
# print(cost)
return cost
# lb <= constraints <= ub
def constraints(modules, z, p, model, settings, stage_idx):
constraints = []
params = settings["params"]
params.load(p)
model.load(z)
for module in modules.modules:
if module.type == "constraint":
for constraint in module.constraints:
constraints += constraint.get_constraints(model, params, settings, stage_idx)
return constraints
def constraint_upper_bounds(modules):
ub = []
for module in modules.modules:
if module.type == "constraint":
for constraint in module.constraints:
ub += constraint.get_upper_bound()
return ub
def constraint_lower_bounds(modules):
lb = []
for module in modules.modules:
if module.type == "constraint":
for constraint in module.constraints:
lb += constraint.get_lower_bound()
return lb
def constraint_number(modules):
nh = 0
for module in modules.modules:
if module.type == "constraint":
for constraint in module.constraints:
nh += constraint.nh
return nh