CONOPT
Loading...
Searching...
No Matches
largeres1.py
Go to the documentation of this file.
7
8import sys
9import os
10import math
11
12import conopt as co
13
14sys.path.append('../common/')
15import std
16
17
18class LargeResModelData(co.ModelData):
19 def __init__(self):
20 super().__init__()
21
22 def buildModel(self):
23 """
24 adding the variables and constraints to the model
25 @ingroup PYTHON1THREAD_LARGERES1
26 """
27 # adding the variables to the model
28 self.varidx = self.addVariable(
29 -co.Conopt.Infinity, co.Conopt.Infinity, 35.0
30 )
31
32 # adding the constraints to the model
33 self.considx = self.addConstraint(co.ConstraintType_Eq, 10, [0], [0], [1])
34
35 # setting the objective constraint
36 self.setObjectiveElement(co.ObjectiveElement_Variable, self.varidx)
37
38 # setting the optimisation direction
39 self.setOptimizationSense(co.Sense_Maximize)
40
41 def evaluateNonlinearTerm(self, x, rowno, ignerr, thread):
42 """
43 @copydoc conopt.ModelData.evaluateNonlinearTerm
44 @ingroup PYTHON1THREAD_LARGERES1
45 """
46 g = 0
47 if rowno == self.considx:
48 g = math.exp(x[self.varidx])
49
50 return g
51
52 def evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread):
53 """
54 @copydoc conopt.ModelData.evaluateNonlinearJacobian
55 @ingroup PYTHON1THREAD_LARGERES1
56 """
57 jac = []
58 if rowno == self.considx:
59 jac.append(math.exp(x[self.varidx]))
60
61 return jac
62
63
64if __name__ == '__main__':
65 name = os.path.basename(__file__)[:-3]
66
67 conopt = co.Conopt(name)
68 model = LargeResModelData()
69 msghdlr = std.TutMessageHandler(name)
70
71 model.buildModel()
72
73 conopt.loadModel(model)
74 conopt.setMessageHandler(msghdlr)
75
76 # getting the license variables
77 license_int_1 = os.environ.get('CONOPT_LICENSE_INT_1', None)
78 license_int_2 = os.environ.get('CONOPT_LICENSE_INT_2', None)
79 license_int_3 = os.environ.get('CONOPT_LICENSE_INT_3', None)
80 license_text = os.environ.get('CONOPT_LICENSE_TEXT', None)
81 if (
82 license_int_1 is not None
83 and license_int_2 is not None
84 and license_int_3 is not None
85 and license_text is not None
86 ):
87 conopt.setLicense(
88 int(license_int_1),
89 int(license_int_2),
90 int(license_int_3),
91 license_text,
92 )
93
94 coi_error = conopt.solve()
95
96 if coi_error != 400:
97 std.python_log(conopt, 'Expected return code 400, Saw')
98
99 std.python_log(conopt, 'Successful Solve')
evaluateNonlinearJacobian(self, x, rowno, jacnum, ignerr, thread)
callback method for evaluating the jacobian for the nonlinear terms in a given row
Definition largeres1.py:52
evaluateNonlinearTerm(self, x, rowno, ignerr, thread)
callback method for evaluating the nonlinear terms in a given row
Definition largeres1.py:41
buildModel(self)
adding the variables and constraints to the model
Definition largeres1.py:22