Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.problem_upd_z = problem
self._lineq_updz = lineq_updz
return 0.
# check if we have linear equality constraints
self._lineq_updz, A, b = self._check_for_lineq()
if not self._lineq_updz:
raise ValueError('For now, only equality constrained QP ' +
'z-updates are allowed!')
x_i = struct_symMX(self.q_i_struct)
x_j = struct_symMX(self.q_ij_struct)
l_i = struct_symMX(self.q_i_struct)
l_ij = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
rho = MX.sym('rho')
par = struct_symMX(self.par_global_struct)
inp = [x_i.cat, l_i.cat, l_ij.cat, x_j.cat, t, T, rho, par.cat]
t0 = t/T
# put symbols in MX structs (necessary for transformation)
x_i = self.q_i_struct(x_i)
x_j = self.q_ij_struct(x_j)
l_i = self.q_i_struct(l_i)
l_ij = self.q_ij_struct(l_ij)
# transform spline variables: only consider future piece of spline
tf = lambda cfs, basis: shift_knot1_fwd(cfs, basis, t0)
self._transform_spline([x_i, l_i], tf, self.q_i)
self._transform_spline([x_j, l_ij], tf, self.q_ij)
# fill in parameters
A = A(par.cat)
b = b(par.cat)
# build KKT system and solve it via schur complement method
l, x = vertcat(l_i.cat, l_ij.cat), vertcat(x_i.cat, x_j.cat)
def construct_upd_res(self, problem=None):
if problem is not None:
self.problem_upd_res = problem
return 0.
# create parameters
x_i = struct_symMX(self.q_i_struct)
z_i = struct_symMX(self.q_i_struct)
z_i_p = struct_symMX(self.q_i_struct)
z_ij = struct_symMX(self.q_ij_struct)
z_ij_p = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
t0 = t/T
rho = MX.sym('rho')
inp = [x_i, z_i, z_i_p, z_ij, z_ij_p, x_j, t, T, rho]
# put symbols in MX structs (necessary for transformation)
x_i = self.q_i_struct(x_i)
z_i = self.q_i_struct(z_i)
z_i_p = self.q_i_struct(z_i_p)
z_ij = self.q_ij_struct(z_ij)
z_ij_p = self.q_ij_struct(z_ij_p)
x_j = self.q_ij_struct(x_j)
def construct_upd_l(self, problem=None):
if problem is not None:
self.problem_upd_l = problem
return 0.
# create parameters
x_i = struct_symMX(self.q_i_struct)
z_i = struct_symMX(self.q_i_struct)
z_ij = struct_symMX(self.q_ij_struct)
l_i = struct_symMX(self.q_i_struct)
l_ij = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
rho = MX.sym('rho')
inp = [x_i, z_i, z_ij, l_i, l_ij, x_j, rho]
# update lambda
l_i_new = self.q_i_struct(l_i.cat + rho*(x_i.cat - z_i.cat))
l_ij_new = self.q_ij_struct(l_ij.cat + rho*(x_j.cat - z_ij.cat))
out = [l_i_new, l_ij_new]
# create problem
prob, buildtime = create_function('upd_l_'+str(self._index), inp, out, self.options)
self.problem_upd_l = prob
return buildtime
def construct_upd_res(self, problem=None):
if problem is not None:
self.problem_upd_res = problem
return 0.
# create parameters
x_i = struct_symMX(self.q_i_struct)
z_i = struct_symMX(self.q_i_struct)
z_i_p = struct_symMX(self.q_i_struct)
z_ij = struct_symMX(self.q_ij_struct)
z_ij_p = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
t0 = t/T
rho = MX.sym('rho')
inp = [x_i, z_i, z_i_p, z_ij, z_ij_p, x_j, t, T, rho]
# put symbols in MX structs (necessary for transformation)
x_i = self.q_i_struct(x_i)
z_i = self.q_i_struct(z_i)
z_i_p = self.q_i_struct(z_i_p)
z_ij = self.q_ij_struct(z_ij)
z_ij_p = self.q_ij_struct(z_ij_p)
x_j = self.q_ij_struct(x_j)
def construct_upd_l(self, problem=None):
if problem is not None:
self.problem_upd_l = problem
return 0.
# create parameters
x_i = struct_symMX(self.q_i_struct)
z_i = struct_symMX(self.q_i_struct)
z_ij = struct_symMX(self.q_ij_struct)
l_i = struct_symMX(self.q_i_struct)
l_ij = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
rho = MX.sym('rho')
inp = [x_i, z_i, z_ij, l_i, l_ij, x_j, rho]
# update lambda
l_i_new = self.q_i_struct(l_i.cat + rho*(x_i.cat - z_i.cat))
l_ij_new = self.q_ij_struct(l_ij.cat + rho*(x_j.cat - z_ij.cat))
out = [l_i_new, l_ij_new]
# create problem
prob, buildtime = create_function('upd_l_'+str(self._index), inp, out, self.options)
self.problem_upd_l = prob
return buildtime
def construct_upd_l(self, problem=None):
if problem is not None:
self.problem_upd_l = problem
return 0.
# create parameters
z_ij = struct_symMX(self.q_ij_struct)
l_ij = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
rho = MX.sym('rho')
inp = [x_j, z_ij, l_ij, t, T, rho]
# update lambda
l_ij_new = self.q_ij_struct(l_ij.cat + rho*(x_j.cat - z_ij.cat))
out = [l_ij_new]
# create problem
prob, buildtime = create_function('upd_l_'+str(self._index), inp, out, self.options)
self.problem_upd_l = prob
return buildtime
def construct_upd_z(self, problem=None, lineq_updz=True):
if problem is not None:
self.problem_upd_z = problem
self._lineq_updz = lineq_updz
return 0.
# check if we have linear equality constraints
self._lineq_updz, A, b = self._check_for_lineq()
if not self._lineq_updz:
raise ValueError('For now, only equality constrained QP ' +
'z-updates are allowed!')
x_i = struct_symMX(self.q_i_struct)
x_j = struct_symMX(self.q_ij_struct)
l_i = struct_symMX(self.q_i_struct)
l_ij = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
rho = MX.sym('rho')
par = struct_symMX(self.par_global_struct)
inp = [x_i.cat, l_i.cat, l_ij.cat, x_j.cat, t, T, rho, par.cat]
t0 = t/T
# put symbols in MX structs (necessary for transformation)
x_i = self.q_i_struct(x_i)
x_j = self.q_ij_struct(x_j)
l_i = self.q_i_struct(l_i)
l_ij = self.q_ij_struct(l_ij)
# transform spline variables: only consider future piece of spline
tf = lambda cfs, basis: shift_knot1_fwd(cfs, basis, t0)
def construct_upd_res(self, problem=None):
if problem is not None:
self.problem_upd_res = problem
return 0.
# create parameters
x_i = struct_symMX(self.q_i_struct)
z_i = struct_symMX(self.q_i_struct)
z_i_p = struct_symMX(self.q_i_struct)
z_ij = struct_symMX(self.q_ij_struct)
z_ij_p = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
t0 = t/T
rho = MX.sym('rho')
inp = [x_i, z_i, z_i_p, z_ij, z_ij_p, x_j, t, T, rho]
# put symbols in MX structs (necessary for transformation)
x_i = self.q_i_struct(x_i)
z_i = self.q_i_struct(z_i)
z_i_p = self.q_i_struct(z_i_p)
z_ij = self.q_ij_struct(z_ij)
z_ij_p = self.q_ij_struct(z_ij_p)
x_j = self.q_ij_struct(x_j)
# transform spline variables: only consider future piece of spline
tf = lambda cfs, basis: shift_knot1_fwd(cfs, basis, t0)
self._transform_spline([x_i, z_i, z_i_p], tf, self.q_i)
def construct_variables(self):
entries = []
for label, child in self.children.items():
entries_child = []
for name, var in child._variables.items():
entries_child.append(entry(name, shape=var.shape))
entries.append(entry(label, struct=struct(entries_child)))
self._var_struct = struct(entries)
return struct_symMX(self._var_struct)
def construct_upd_l(self, problem=None):
if problem is not None:
self.problem_upd_l = problem
return 0.
# create parameters
z_ij = struct_symMX(self.q_ij_struct)
l_ij = struct_symMX(self.q_ij_struct)
x_j = struct_symMX(self.q_ij_struct)
t = MX.sym('t')
T = MX.sym('T')
rho = MX.sym('rho')
inp = [x_j, z_ij, l_ij, t, T, rho]
# update lambda
l_ij_new = self.q_ij_struct(l_ij.cat + rho*(x_j.cat - z_ij.cat))
out = [l_ij_new]
# create problem
prob, buildtime = create_function('upd_l_'+str(self._index), inp, out, self.options)
self.problem_upd_l = prob
return buildtime