13sys.path.append(
'../common/')
33 adding the variables and constraints to the model
34 @ingroup PYTHON1THREAD_QP4
37 for i
in range(self.
NN):
38 self.addVariable(0.0, co.Conopt.Infinity)
42 varidx = list(range(self.
NN))
45 self.addConstraint(co.ConstraintType_Free, 0.0, varidx, zeros, ones)
48 self.addConstraint(co.ConstraintType_Eq, 1.0, varidx, ones, zeros)
51 self.setObjectiveElement(co.ObjectiveElement_Constraint, 0)
54 self.setOptimizationSense(co.Sense_Minimize)
57 self.setSDEvaluationType(co.SDEvaluationType_Constraint)
64 define the lagrangian structure and supplies it to CONOPT
66 @ingroup PYTHON1THREAD_QP4
68 hessianrow = [f
for x
in range(self.
NN - 1)
for f
in [x, x + 1]] + [
71 hessiancol = [f
for x
in range(self.
NN - 1)
for f
in [x, x]] + [
75 self.setSDLagrangianStructure(hessianrow, hessiancol)
79 @copydoc conopt.ModelData.evaluateNonlinearTerm
80 @ingroup PYTHON1THREAD_QP4
89 for i, q
in enumerate(self.
Qdiag)
94 (x[i + 1] - self.
target[i + 1]) * q * (x[i] - self.
target[i])
103 @copydoc conopt.ModelData.evaluateNonlinearJacobian
104 @ingroup PYTHON1THREAD_QP4
108 for i
in range(self.
NN):
118 @copydoc conopt.ModelData.evaluateDirectionalSD
119 @ingroup PYTHON1THREAD_QP4
121 dirsd = [0] * self.
NN
122 for i
in range(self.
NN):
123 dirsd[i] += self.
Qdiag[i] * dx[i]
132 @copydoc conopt.ModelData.evaluateSDLagrangian
133 @ingroup PYTHON1THREAD_QP4
137 for i
in range(self.
NN - 1)
139 ] + [self.
Qdiag[-1] * u[0]]
144if __name__ ==
'__main__':
145 name = os.path.basename(__file__)[:-3]
147 conopt = co.Conopt(name)
148 model = QPModelData()
153 conopt.loadModel(model)
154 conopt.setMessageHandler(msghdlr)
157 license_int_1 = os.environ.get(
'CONOPT_LICENSE_INT_1',
None)
158 license_int_2 = os.environ.get(
'CONOPT_LICENSE_INT_2',
None)
159 license_int_3 = os.environ.get(
'CONOPT_LICENSE_INT_3',
None)
160 license_text = os.environ.get(
'CONOPT_LICENSE_TEXT',
None)
162 license_int_1
is not None
163 and license_int_2
is not None
164 and license_int_3
is not None
165 and license_text
is not None
174 coi_error = conopt.solve()
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)
define the lagrangian structure and supplies it to CONOPT
evaluateDirectionalSD(self, x, dx, rowno, jacnum, thread)
computes the directional second derivative for a single constraint
buildModel(self)
adding the variables and constraints to the model
evaluateNonlinearTerm(self, x, rowno, ignerr, thread)
callback method for evaluating the nonlinear terms in a given row
evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread)
callback method for evaluating the jacobian for the nonlinear terms in a given row