CONOPT
Loading...
Searching...
No Matches
largeres1.f90
Go to the documentation of this file.
1!> @file largeres1.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!!
5!! Example with a Large Residual in the initial point.
6!!
7!!
8!! For more information about the individual callbacks, please have a look at the source code.
9
10!> Main program. A simple setup and call of CONOPT
11!!
12Program largeres1
13
14 Use proginfo
15 Use coidef
16 implicit None
17!
18! Declare the user callback routines as Integer, External:
19!
20 Integer, External :: lr_readmatrix ! Mandatory Matrix definition routine defined below
21 Integer, External :: lr_fdeval ! Function and Derivative evaluation routine
22 ! needed a nonlinear model.
23 Integer, External :: std_status ! Standard callback for displaying solution status
24 Integer, External :: std_solution ! Standard callback for displaying solution values
25 Integer, External :: std_message ! Standard callback for managing messages
26 Integer, External :: std_errmsg ! Standard callback for managing error messages
27#if defined(itl)
28!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_ReadMatrix
29!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_FDEval
30!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
31!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
32!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
33!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
34#endif
35!
36! Control vector
37!
38 INTEGER :: numcallback
39 INTEGER, Dimension(:), Pointer :: cntvect
40 INTEGER :: coi_error
41!
42! The model is
43!
44! min x
45! exp(x) = 10
46! x.l = 35
47!
48! with x starting at a value where the function overflows.
49! When an error happens in the initial point CONOPT will just
50! return with COI_Error = 400
51!
52! Create and initialize a Control Vector
53!
54 call startup
55 numcallback = coidef_size()
56 Allocate( cntvect(numcallback) )
57 coi_error = coidef_inifort( cntvect )
58!
59! Tell CONOPT about the size of the model by populating the Control Vector:
60!
61 coi_error = max( coi_error, coidef_numvar( cntvect, 1 ) ) ! # variables
62 coi_error = max( coi_error, coidef_numcon( cntvect, 1 ) ) ! # constraints
63 coi_error = max( coi_error, coidef_numnz( cntvect, 1 ) ) ! # nonzeros in the Jacobian
64 coi_error = max( coi_error, coidef_numnlnz( cntvect, 1 ) ) ! # of which are nonlinear
65 coi_error = max( coi_error, coidef_optdir( cntvect, -1 ) ) ! Minimize
66 coi_error = max( coi_error, coidef_objvar( cntvect, 1 ) ) ! Objective is variable 1
67 coi_error = max( coi_error, coidef_optfile( cntvect, 'largeres.opt' ) )
68!
69! Tell CONOPT about the callback routines:
70!
71 coi_error = max( coi_error, coidef_readmatrix( cntvect, lr_readmatrix ) )
72 coi_error = max( coi_error, coidef_fdeval( cntvect, lr_fdeval ) )
73 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
74 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
75 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
76 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
77
78#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
79 coi_error = max( coi_error, coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
80#endif
81
82 If ( coi_error .ne. 0 ) THEN
83 write(*,*)
84 write(*,*) '**** Fatal Error while loading CONOPT Callback routines.'
85 write(*,*)
86 call flog( "Skipping Solve due to setup errors", 1 )
87 ENDIF
88!
89 coi_error = coi_solve( cntvect )
90
91 write(*,*)
92 write(*,*) 'End of Large Residual example. Return code=',coi_error
93
94 If ( coi_error /= 400 ) then
95 call flog( "COI_Solve was expected to return 400.", 1 )
96 endif
97
98 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
99
100 call flog( "Successful Solve", 0 )
101
102End Program largeres1
103!
104! ============================================================================
105! Define information about the model:
106!
107
108!> Define information about the model
109!!
110!! @include{doc} readMatrix_params.dox
111Integer Function lr_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
112 colsta, rowno, value, nlflag, n, m, nz, &
113 usrmem )
114#if defined(itl)
115!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_ReadMatrix
116#endif
117 implicit none
118 integer, intent (in) :: n ! number of variables
119 integer, intent (in) :: m ! number of constraints
120 integer, intent (in) :: nz ! number of nonzeros
121 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
122 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
123 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
124 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
125 ! (not defined here)
126 integer, intent (out), dimension(m) :: type ! vector of equation types
127 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
128 ! (not defined here)
129 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
130 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
131 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
132 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
133 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
134 real*8 usrmem(*) ! optional user memory
135
136!
137! Information about Variables:
138! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
139! Default: the status information in Vsta is not used.
140!
141 curr(1) = 35.d0
142!
143! Information about Constraints:
144! Default: Rhs = 0
145! Default: the status information in Esta and the function
146! value in FV are not used.
147! Default: Type: There is no default.
148! 0 = Equality,
149! 1 = Greater than or equal,
150! 2 = Less than or equal,
151! 3 = Non binding.
152!
153! Constraint 1
154! Rhs = 10.0 and type Equality
155!
156 type(1) = 0
157 rhs(1) = 10.0d0
158!
159! Information about the Jacobian. We have to define Rowno, Value,
160! Nlflag and Colsta.
161!
162! Colsta = Start of column indices (No Defaults):
163! Rowno = Row indices
164! Value = Value of derivative (by default only linear
165! derivatives are used)
166! Nlflag = 0 for linear and 1 for nonlinear derivative
167! (not needed for completely linear models)
168!
169! Indices
170! x(1)
171! 1: 1
172!
173! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
174! x(1)
175! 1: NL
176!
177! Value (Linear only)
178!
179 colsta(1) = 1
180 colsta(2) = 2
181 rowno(1) = 1
182 nlflag(1) = 1
183
184 lr_readmatrix = 0 ! Return value means OK
185
186end Function lr_readmatrix
187!
188!==========================================================================
189! Compute nonlinear terms and non-constant Jacobian elements
190!
191
192!> Compute nonlinear terms and non-constant Jacobian elements
193!!
194!! @include{doc} fdeval_params.dox
195Integer Function lr_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
196 n, nz, thread, usrmem )
197#if defined(itl)
198!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_FDEval
199#endif
200 implicit none
201 integer, intent (in) :: n ! number of variables
202 integer, intent (in) :: rowno ! number of the row to be evaluated
203 integer, intent (in) :: nz ! number of nonzeros in this row
204 real*8, intent (in), dimension(n) :: x ! vector of current solution values
205 real*8, intent (in out) :: g ! constraint value
206 real*8, intent (in out), dimension(n) :: jac ! vector of derivatives for current constraint
207 integer, intent (in), dimension(nz) :: jcnm ! list of variables that appear nonlinearly
208 ! in this row. Ffor information only.
209 integer, intent (in) :: mode ! evaluation mode: 1 = function value
210 ! 2 = derivatives, 3 = both
211 integer, intent (in) :: ignerr ! if 1 then errors can be ignored as long
212 ! as errcnt is incremented
213 integer, intent (in out) :: errcnt ! error counter to be incremented in case
214 ! of function evaluation errors.
215 integer, intent (in) :: thread
216 real*8 usrmem(*) ! optional user memory
217
218!
219! Row 1: exp(x)
220!
221 if ( rowno .eq. 1 ) then
222!
223! Mode = 1 or 3. Function value:
224!
225 if ( mode .eq. 1 .or. mode .eq. 3 ) then
226 g = exp(x(1))
227 endif
228!
229! Mode = 2 or 3: Derivative values:
230!
231 if ( mode .eq. 2 .or. mode .eq. 3 ) then
232 jac(1) = exp(x(1))
233 endif
234 lr_fdeval = 0
235 else
236 lr_fdeval = 1
237 endif
238
239end Function lr_fdeval
integer function std_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
Definition comdecl.f90:128
integer function std_status(modsta, solsta, iter, objval, usrmem)
Definition comdecl.f90:82
integer function std_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
Definition comdecl.f90:203
integer function std_errmsg(rowno, colno, posno, msglen, usrmem, msg)
Definition comdecl.f90:248
integer function coidef_fdeval(cntvect, coi_fdeval)
define callback routine for performing function and derivative evaluations.
integer function coidef_errmsg(cntvect, coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
integer function coidef_message(cntvect, coi_message)
define callback routine for handling messages returned during the solution process.
integer function coidef_readmatrix(cntvect, coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
integer function coidef_status(cntvect, coi_status)
define callback routine for returning the completion status.
integer function coidef_solution(cntvect, coi_solution)
define callback routine for returning the final solution values.
integer function coidef_optfile(cntvect, optfile)
define callback routine for defining an options file.
integer function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
Definition coistart.f90:680
integer function coidef_numvar(cntvect, numvar)
defines the number of variables in the model.
Definition coistart.f90:358
integer function coidef_numnz(cntvect, numnz)
defines the number of nonzero elements in the Jacobian.
Definition coistart.f90:437
integer function coidef_optdir(cntvect, optdir)
defines the Optimization Direction.
Definition coistart.f90:552
integer function coidef_numnlnz(cntvect, numnlnz)
defines the Number of Nonlinear Nonzeros.
Definition coistart.f90:476
integer function coidef_numcon(cntvect, numcon)
defines the number of constraints in the model.
Definition coistart.f90:398
integer function coidef_objvar(cntvect, objvar)
defines the Objective Variable.
Definition coistart.f90:586
integer function coidef_size()
returns the size the Control Vector must have, measured in standard Integer units.
Definition coistart.f90:176
integer function coidef_inifort(cntvect)
initialisation method for Fortran applications.
Definition coistart.f90:314
integer function coi_solve(cntvect)
method for starting the solving process of CONOPT.
Definition coistart.f90:14
integer function lr_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
program largeres1
Main program. A simple setup and call of CONOPT.
Definition largeres1.f90:12
integer function lr_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
subroutine flog(msg, code)
Definition comdecl.f90:56
subroutine startup
Definition comdecl.f90:35