13sys.path.append(
'../common/')
33 adding the variables and constraints to the model
34 @ingroup PYTHON1THREAD_QP2
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,
49 self.addConstraint(co.ConstraintType_Eq, 1.0, varidx, ones,
53 self.setObjectiveElement(co.ObjectiveElement_Constraint, 0)
56 self.setOptimizationSense(co.Sense_Minimize)
59 self.setSDEvaluationType(co.SDEvaluationType_Constraint)
63 @ingroup PYTHON1THREAD_QP2
69 g += sum([(x[i] - self.
target[i])*q*(x[i] - self.
target[i])
70 for i, q
in enumerate(self.
Qdiag)])
71 g += 2*sum([(x[i + 1] - self.
target[i + 1])*q*(x[i] - self.
target[i])
78 @ingroup PYTHON1THREAD_QP2
82 for i
in range(self.
NN):
93 @ingroup PYTHON1THREAD_QP2
96 for i
in range(self.
NN):
97 dirsd[i] += self.
Qdiag[i]*dx[i]
104if __name__ ==
"__main__":
105 name = os.path.basename(__file__)[:-3]
107 conopt = co.Conopt(name)
108 model = QPModelData()
113 conopt.loadModel(model)
114 conopt.setMessageHandler(msghdlr)
117 license_int_1 = os.environ.get(
'CONOPT_LICENSE_INT_1',
None)
118 license_int_2 = os.environ.get(
'CONOPT_LICENSE_INT_2',
None)
119 license_int_3 = os.environ.get(
'CONOPT_LICENSE_INT_3',
None)
120 license_text = os.environ.get(
'CONOPT_LICENSE_TEXT',
None)
121 if license_int_1
is not None and license_int_2
is not None \
122 and license_int_3
is not None and license_text
is not None:
123 conopt.setLicense(int(license_int_1), int(license_int_2),
124 int(license_int_3), license_text)
126 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)
buildModel(self)
adding the variables and constraints to the model
evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread)
evaluateDirectionalSD(self, x, dx, rowno, jacnum, thread)