13sys.path.append(
'../common/')
32 adding the variables and constraints to the model
33 @ingroup PYTHON1THREAD_QP4
36 for i
in range(self.
NN):
37 self.addVariable(0.0, co.Conopt.Infinity)
41 varidx = list(range(self.
NN))
44 self.addConstraint(co.ConstraintType_Free, 0.0, varidx, zeros,
48 self.addConstraint(co.ConstraintType_Eq, 1.0, varidx, ones,
52 self.setObjectiveElement(co.ObjectiveElement_Constraint, 0)
55 self.setOptimizationSense(co.Sense_Minimize)
58 self.setSDEvaluationType(co.SDEvaluationType_Constraint)
65 @ingroup PYTHON1THREAD_QP4
67 hessianrow = [f
for x
in range(self.
NN - 1)
for f
in [x, x + 1]] \
69 hessiancol = [f
for x
in range(self.
NN - 1)
for f
in [x, x]] \
72 self.setSDLagrangianStructure(hessianrow, hessiancol)
76 @ingroup PYTHON1THREAD_QP4
82 g += sum([(x[i] - self.
target[i])*q*(x[i] - self.
target[i])
83 for i, q
in enumerate(self.
Qdiag)])
84 g += 2*sum([(x[i + 1] - self.
target[i + 1])*q*(x[i] - self.
target[i])
91 @ingroup PYTHON1THREAD_QP4
95 for i
in range(self.
NN):
106 @ingroup PYTHON1THREAD_QP4
109 for i
in range(self.
NN):
110 dirsd[i] += self.
Qdiag[i]*dx[i]
119 @ingroup PYTHON1THREAD_QP4
121 hessian = [x*u[0]
for i
in range(self.
NN - 1) \
123 + [self.
Qdiag[-1]*u[0]]
128if __name__ ==
"__main__":
129 name = os.path.basename(__file__)[:-3]
131 conopt = co.Conopt(name)
132 model = QPModelData()
137 conopt.loadModel(model)
138 conopt.setMessageHandler(msghdlr)
141 license_int_1 = os.environ.get(
'CONOPT_LICENSE_INT_1',
None)
142 license_int_2 = os.environ.get(
'CONOPT_LICENSE_INT_2',
None)
143 license_int_3 = os.environ.get(
'CONOPT_LICENSE_INT_3',
None)
144 license_text = os.environ.get(
'CONOPT_LICENSE_TEXT',
None)
145 if license_int_1
is not None and license_int_2
is not None \
146 and license_int_3
is not None and license_text
is not None:
147 conopt.setLicense(int(license_int_1), int(license_int_2),
148 int(license_int_3), license_text)
150 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)
setLagrangianStructure(self)
evaluateDirectionalSD(self, x, dx, rowno, jacnum, thread)
buildModel(self)
adding the variables and constraints to the model
evaluateNonlinearTerm(self, x, rowno, ignerr, thread)
evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread)