CONOPT
Loading...
Searching...
No Matches
largeres2.f90
Go to the documentation of this file.
1!> @file largeres2.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 largeres2
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 = 100
47!
48! with x starting at a value where the function overflows.
49! The difference between LargeRes1 and LargeRes2 is the initial point.
50! In LargeRes1 the function value is above Rtmaxv but not really large.
51! In LargeRes2 the function value is really large, above 1.e30.
52! When an error happens in the initial point CONOPT will just
53! return with COI_Error = 400
54!
55! Create and initialize a Control Vector
56!
57 call startup
58 numcallback = coidef_size()
59 Allocate( cntvect(numcallback) )
60 coi_error = coidef_inifort( cntvect )
61!
62! Tell CONOPT about the size of the model by populating the Control Vector:
63!
64 coi_error = max( coi_error, coidef_numvar( cntvect, 1 ) ) ! # variables
65 coi_error = max( coi_error, coidef_numcon( cntvect, 1 ) ) ! # constraints
66 coi_error = max( coi_error, coidef_numnz( cntvect, 1 ) ) ! # nonzeros in the Jacobian
67 coi_error = max( coi_error, coidef_numnlnz( cntvect, 1 ) ) ! # of which are nonlinear
68 coi_error = max( coi_error, coidef_optdir( cntvect, -1 ) ) ! Minimize
69 coi_error = max( coi_error, coidef_objvar( cntvect, 1 ) ) ! Objective is variable 1
70 coi_error = max( coi_error, coidef_optfile( cntvect, 'largeres.opt' ) )
71!
72! Tell CONOPT about the callback routines:
73!
74 coi_error = max( coi_error, coidef_readmatrix( cntvect, lr_readmatrix ) )
75 coi_error = max( coi_error, coidef_fdeval( cntvect, lr_fdeval ) )
76 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
77 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
78 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
79 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
80
81#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
82 coi_error = max( coi_error, coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
83#endif
84
85 If ( coi_error .ne. 0 ) THEN
86 write(*,*)
87 write(*,*) '**** Fatal Error while loading CONOPT Callback routines.'
88 write(*,*)
89 call flog( "Skipping Solve due to setup errors", 1 )
90 ENDIF
91!
92 coi_error = coi_solve( cntvect )
93
94 write(*,*)
95 write(*,*) 'End of Large Residual example. Return code=',coi_error
96
97 If ( coi_error /= 400 ) then
98 call flog( "COI_Solve was expected to return 400.", 1 )
99 endif
100
101 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
102
103 call flog( "Successful Solve", 0 )
104
105End Program largeres2
106!
107! ============================================================================
108! Define information about the model:
109!
110
111!> Define information about the model
112!!
113!! @include{doc} readMatrix_params.dox
114Integer Function lr_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
115 colsta, rowno, value, nlflag, n, m, nz, &
116 usrmem )
117#if defined(itl)
118!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_ReadMatrix
119#endif
120 implicit none
121 integer, intent (in) :: n ! number of variables
122 integer, intent (in) :: m ! number of constraints
123 integer, intent (in) :: nz ! number of nonzeros
124 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
125 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
126 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
127 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
128 ! (not defined here)
129 integer, intent (out), dimension(m) :: type ! vector of equation types
130 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
131 ! (not defined here)
132 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
133 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
134 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
135 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
136 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
137 real*8 usrmem(*) ! optional user memory
138
139!
140! Information about Variables:
141! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
142! Default: the status information in Vsta is not used.
143!
144 curr(1) = 100.d0
145!
146! Information about Constraints:
147! Default: Rhs = 0
148! Default: the status information in Esta and the function
149! value in FV are not used.
150! Default: Type: There is no default.
151! 0 = Equality,
152! 1 = Greater than or equal,
153! 2 = Less than or equal,
154! 3 = Non binding.
155!
156! Constraint 1
157! Rhs = 10.0 and type Equality
158!
159 type(1) = 0
160 rhs(1) = 10.0d0
161!
162! Information about the Jacobian. We have to define Rowno, Value,
163! Nlflag and Colsta.
164!
165! Colsta = Start of column indices (No Defaults):
166! Rowno = Row indices
167! Value = Value of derivative (by default only linear
168! derivatives are used)
169! Nlflag = 0 for linear and 1 for nonlinear derivative
170! (not needed for completely linear models)
171!
172! Indices
173! x(1)
174! 1: 1
175!
176! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
177! x(1)
178! 1: NL
179!
180! Value (Linear only)
181!
182 colsta(1) = 1
183 colsta(2) = 2
184 rowno(1) = 1
185 nlflag(1) = 1
186
187 lr_readmatrix = 0 ! Return value means OK
188
189end Function lr_readmatrix
190!
191!==========================================================================
192! Compute nonlinear terms and non-constant Jacobian elements
193!
194
195!> Compute nonlinear terms and non-constant Jacobian elements
196!!
197!! @include{doc} fdeval_params.dox
198Integer Function lr_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
199 n, nz, thread, usrmem )
200#if defined(itl)
201!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lr_FDEval
202#endif
203 implicit none
204 integer, intent (in) :: n ! number of variables
205 integer, intent (in) :: rowno ! number of the row to be evaluated
206 integer, intent (in) :: nz ! number of nonzeros in this row
207 real*8, intent (in), dimension(n) :: x ! vector of current solution values
208 real*8, intent (in out) :: g ! constraint value
209 real*8, intent (in out), dimension(n) :: jac ! vector of derivatives for current constraint
210 integer, intent (in), dimension(nz) :: jcnm ! list of variables that appear nonlinearly
211 ! in this row. Ffor information only.
212 integer, intent (in) :: mode ! evaluation mode: 1 = function value
213 ! 2 = derivatives, 3 = both
214 integer, intent (in) :: ignerr ! if 1 then errors can be ignored as long
215 ! as errcnt is incremented
216 integer, intent (in out) :: errcnt ! error counter to be incremented in case
217 ! of function evaluation errors.
218 integer, intent (in) :: thread
219 real*8 usrmem(*) ! optional user memory
220
221!
222! Row 1: exp(x)
223!
224 if ( rowno .eq. 1 ) then
225!
226! Mode = 1 or 3. Function value:
227!
228 if ( mode .eq. 1 .or. mode .eq. 3 ) then
229 g = exp(x(1))
230 endif
231!
232! Mode = 2 or 3: Derivative values:
233!
234 if ( mode .eq. 2 .or. mode .eq. 3 ) then
235 jac(1) = exp(x(1))
236 endif
237 lr_fdeval = 0
238 else
239 lr_fdeval = 1
240 endif
241
242end 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.
integer function lr_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
program largeres2
Main program. A simple setup and call of CONOPT.
Definition largeres2.f90:12
subroutine flog(msg, code)
Definition comdecl.f90:56
subroutine startup
Definition comdecl.f90:35