13sys.path.append(
'../common/')
33 adding the variables and constraints to the model
34 @ingroup PYTHON1THREAD_QP3
37 for i
in range(self.
NN):
42 varidx = list(range(self.
NN))
45 self.
addConstraint(pyconopt.ConstraintType_Free, 0.0, varidx, zeros,
49 self.
addConstraint(pyconopt.ConstraintType_Eq, 1.0, varidx, ones,
63 @ingroup PYTHON1THREAD_QP3
65 hessianrow = [f
for x
in range(self.
NN - 1)
for f
in [x, x + 1]] \
67 hessiancol = [f
for x
in range(self.
NN - 1)
for f
in [x, x]] \
74 @ingroup PYTHON1THREAD_QP3
80 g += sum([(x[i] - self.
target[i])*q*(x[i] - self.
target[i])
81 for i, q
in enumerate(self.
Qdiag)])
82 g += 2*sum([(x[i + 1] - self.
target[i + 1])*q*(x[i] - self.
target[i])
89 @ingroup PYTHON1THREAD_QP3
93 for i
in range(self.
NN):
104 @ingroup PYTHON1THREAD_QP3
106 hessian = [x*u[0]
for i
in range(self.
NN - 1) \
108 + [self.
Qdiag[-1]*u[0]]
113if __name__ ==
"__main__":
114 name = os.path.basename(__file__)[:-3]
117 model = QPModelData()
122 conopt.loadModel(model)
123 conopt.setMessageHandler(msghdlr)
126 license_int_1 = os.environ.get(
'LICENSE_INT_1',
None)
127 license_int_2 = os.environ.get(
'LICENSE_INT_2',
None)
128 license_int_3 = os.environ.get(
'LICENSE_INT_3',
None)
129 license_text = os.environ.get(
'LICENSE_TEXT',
None)
130 if license_int_1
is not None and license_int_2
is not None \
131 and license_int_3
is not None and license_text
is not None:
132 conopt.setLicense(int(license_int_1), int(license_int_2),
133 int(license_int_3), license_text)
135 coi_error = conopt.solve()
setOptimizationSense(self, sense)
sets the optimisation direction.
setObjectiveElement(self, elem, elemindex)
sets the index for the objective variable or constraint
setSDLagrangianStructure(self, rownum, colnum)
sets the structure of the second derivatives of the Lagrangian
addVariable(self, *args)
Overload 1: adds a variable to the model.
addConstraint(self, *args)
Overload 1: adds a constraint to the problem.
A class that can be extended to build and solve a model using Conopt.
static int checkSolve(String name, int model_status, int solution_status, double objective, double expected_objective, double tol)
evaluateSDLagrangian(self, x, u, hessianrow, hessiancol)
Computes and returns the numerical values of the Lagrangian of the Hessian.
setLagrangianStructure(self)
buildModel(self)
adding the variables and constraints to the model
evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread)
callback method for evaluating the jacobian for the nonlinear terms in a given row
evaluateNonlinearTerm(self, x, rowno, ignerr, thread)
callback method for evaluating the nonlinear terms in a given row