15sys.path.append(
'../../common/')
18class TutModelData(conoptpy.ModelData):
29 adding the variables and constraints to the model
30 @ingroup PYTHON1THREAD_AD_TUTORIAL
33 self.addVariable(0.1, conoptpy.CONOPT_INF, 0.5)
34 self.addVariable(0.1, conoptpy.CONOPT_INF, 0.5)
35 self.addVariable(0.0, conoptpy.CONOPT_INF)
36 self.addVariable(0.0, conoptpy.CONOPT_INF)
39 self.addConstraint(conoptpy.ConstraintType_Free, -0.1, [0, 1, 2, 3],
40 [-1, -1, 0, 0], [0, 0, 1, 1])
41 self.addConstraint(conoptpy.ConstraintType_Eq, 0.0, [0, 1, 2], [0, 0, -1],
43 self.addConstraint(conoptpy.ConstraintType_Eq, 4.0, [2, 3], [1, 2],
47 self.setObjectiveElement(conoptpy.ObjectiveElement_Constraint, 0)
50 self.setOptimizationSense(conoptpy.Sense_Maximize)
58 @ingroup PYTHON1THREAD_AD_TUTORIAL
59 evaluates the nonlinear function and records a tape is necessary
61 @param x current point to be evaluated
62 @param rowno the index of the constraint. This is also used for the trace tag.
68 ax = adolc.as_adouble(x)
72 item.declareIndependent()
82 hold1 = (self.
Al*pow(L,(-self.
Rho)) + self.
Ak*pow(self.
K,(-self.
Rho)) + self.
Ainp*pow(Inp,(-self.
Rho)))
83 hold2 = pow(hold1,( -1./self.
Rho ))
93 @ingroup PYTHON1THREAD_AD_TUTORIAL
94 initialises the automatic differentiation
97 for v
in range(self.numVar()):
98 x.append(self.getVariable(v).curr)
100 for c
in range(self.numCons()):
106 @ingroup PYTHON1THREAD_AD_TUTORIAL
109 g = adolc.function(rowno, x)[0]
110 except adolc.BranchException:
112 g = adolc.function(rowno, x)[0]
119 @ingroup PYTHON1THREAD_AD_TUTORIAL
123 jacres = adolc.gradient(rowno, x)
124 except adolc.BranchException:
126 jacres = adolc.gradient(rowno, x)
129 jac.append(jacres[i])
134if __name__ ==
"__main__":
135 name = os.path.basename(__file__)[:-3]
137 conopt = conoptpy.Conopt(name)
143 conopt.loadModel(model)
144 conopt.setMessageHandler(msghdlr)
147 license_int_1 = os.environ.get(
'CONOPT_LICENSE_INT_1',
None)
148 license_int_2 = os.environ.get(
'CONOPT_LICENSE_INT_2',
None)
149 license_int_3 = os.environ.get(
'CONOPT_LICENSE_INT_3',
None)
150 license_text = os.environ.get(
'CONOPT_LICENSE_TEXT',
None)
151 if license_int_1
is not None and license_int_2
is not None \
152 and license_int_3
is not None and license_text
is not None:
153 conopt.setLicense(int(license_int_1), int(license_int_2),
154 int(license_int_3), license_text)
156 coi_error = conopt.solve()
static int checkSolve(String name, int model_status, int solution_status, double objective, double expected_objective, double tol)
tapeFunction(self, x, rowno)
evaluates the nonlinear function and records a tape is necessary
initialiseAutoDiff(self)
initialises the automatic differentiation
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