13sys.path.append(
'../common/')
30 adding the variables and constraints to the model
31 @ingroup PYTHON1THREAD_TUTORIAL2
34 self.
varl = self.addVariable(0.1, co.Conopt.Infinity, 0.5)
35 self.
varinp = self.addVariable(0.1, co.Conopt.Infinity, 0.5)
36 self.
varout = self.addVariable(0.0, co.Conopt.Infinity)
37 self.
varp = self.addVariable(0.0, co.Conopt.Infinity)
41 co.ConstraintType_Free,
55 co.ConstraintType_Eq, 4.0, [self.
varout, self.
varp], [1, 2], [0, 0]
59 self.setObjectiveElement(co.ObjectiveElement_Constraint, 0)
62 self.setOptimizationSense(co.Sense_Maximize)
65 self.setSDLagrangianStructure([0, 1, 1, 3], [0, 0, 1, 2])
69 @copydoc conopt.ModelData.evaluateNonlinearTerm
70 @ingroup PYTHON1THREAD_TUTORIAL2
82 self.
Al * pow(L, (-self.
Rho))
83 + self.
Ak * pow(self.
K, (-self.
Rho))
84 + self.
Ainp * pow(Inp, (-self.
Rho))
86 hold2 = pow(hold1, (-1.0 / self.
Rho))
94 @copydoc conopt.ModelData.evaluateNonlinearJacobian
96 NOTE: The jacobian is returned as a list of length jacnum. In this
97 example, the returned list is constructed using `append`. It is also
98 possible to initially create a list of length jacnum containing only 0s,
99 then update the values by the variable indices.
101 @ingroup PYTHON1THREAD_TUTORIAL2
114 self.
Al * pow(L, (-self.
Rho))
115 + self.
Ak * pow(self.
K, (-self.
Rho))
116 + self.
Ainp * pow(Inp, (-self.
Rho))
118 hold2 = pow(hold1, (-1.0 / self.
Rho))
119 hold3 = hold2 / hold1
121 jac.append(hold3 * self.
Al * pow(L, (-self.
Rho - 1.0)))
122 jac.append(hold3 * self.
Ainp * pow(Inp, (-self.
Rho - 1.0)))
128 @copydoc conopt.ModelData.evaluateSDLagrangian
129 @ingroup PYTHON1THREAD_TUTORIAL2
131 numhessian = len(hessianrow)
132 hessian = [0
for i
in range(numhessian)]
141 self.
Al * pow(L, -self.
Rho)
142 + self.
Ak * pow(self.
K, -self.
Rho)
143 + self.
Ainp * pow(Inp, -self.
Rho)
145 hold2 = pow(hold1, -1.0 / self.
Rho)
146 hold3 = hold2 / hold1
148 hold4 = hold3 / hold1 * (-1.0 / self.
Rho - 1.0)
150 hessian[0] = hold4 * (-self.
Rho) * pow(
151 self.
Al * pow(L, -self.
Rho - 1.0), 2
152 ) + hold3 * self.
Al * (-self.
Rho - 1.0) * pow(L, -self.
Rho - 2.0)
156 * (self.
Al * pow(L, -self.
Rho - 1.0))
157 * (self.
Ainp * pow(Inp, -self.
Rho - 1.0))
159 hessian[2] = hold4 * (-self.
Rho) * pow(
160 self.
Ainp * pow(Inp, -self.
Rho - 1.0), 2
161 ) + hold3 * self.
Ainp * (-self.
Rho - 1.0) * pow(Inp, -self.
Rho - 2.0)
163 for i
in range(numhessian):
164 hessian[i] = hessian[i] * u[self.
consprod]
169if __name__ ==
'__main__':
170 name = os.path.basename(__file__)[:-3]
172 conopt = co.Conopt(name)
173 model = TutModelData()
178 conopt.loadModel(model)
179 conopt.setMessageHandler(msghdlr)
182 license_int_1 = os.environ.get(
'CONOPT_LICENSE_INT_1',
None)
183 license_int_2 = os.environ.get(
'CONOPT_LICENSE_INT_2',
None)
184 license_int_3 = os.environ.get(
'CONOPT_LICENSE_INT_3',
None)
185 license_text = os.environ.get(
'CONOPT_LICENSE_TEXT',
None)
187 license_int_1
is not None
188 and license_int_2
is not None
189 and license_int_3
is not None
190 and license_text
is not None
199 coi_error = conopt.solve()
static int checkSolve(String name, int model_status, int solution_status, double objective, double expected_objective, double tol)
evaluateNonlinearTerm(self, x, rowno, ignerr, thread)
callback method for evaluating the nonlinear terms in a given row
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
evaluateSDLagrangian(self, x, u, hessianrow, hessiancol)
Computes and returns the numerical values of the Lagrangian of the Hessian.