CONOPT
Loading...
Searching...
No Matches
evalerror01.f90
Go to the documentation of this file.
1!> @file evalerror01.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!!
5!! Test function evaluation errors.
6!! Case 01: Function evaluation error in the initial point.
7!!
8!!
9!! For more information about the individual callbacks, please have a look at the source code.
10
11!> Main program. A simple setup and call of CONOPT
12!!
14
15 Use proginfo
16 Use coidef
17 implicit None
18!
19! Declare the user callback routines as Integer, External:
20!
21 Integer, External :: eval_readmatrix ! Mandatory Matrix definition routine defined below
22 Integer, External :: eval_fdeval ! Function and Derivative evaluation routine
23 ! needed a nonlinear model.
24 Integer, External :: std_status ! Standard callback for displaying solution status
25 Integer, External :: std_solution ! Standard callback for displaying solution values
26 Integer, External :: std_message ! Standard callback for managing messages
27 Integer, External :: std_errmsg ! Standard callback for managing error messages
28#if defined(itl)
29!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Eval_ReadMatrix
30!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Eval_FDEval
31!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
32!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
33!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
34!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
35#endif
36!
37! Control vector
38!
39 INTEGER, Dimension(:), Pointer :: cntvect
40 INTEGER :: coi_error
41!
42! Create and initialize a Control Vector
43!
44 call startup
45
46 coi_error = coi_createfort( cntvect )
47!
48! Tell CONOPT about the size of the model by populating the Control Vector:
49!
50 coi_error = max( coi_error, coidef_numvar( cntvect, 2 ) ) ! # variables
51 coi_error = max( coi_error, coidef_numcon( cntvect, 1 ) ) ! # constraints
52 coi_error = max( coi_error, coidef_numnz( cntvect, 2 ) ) ! # nonzeros in the Jacobian
53 coi_error = max( coi_error, coidef_numnlnz( cntvect, 1 ) ) ! # of which are nonlinear
54 coi_error = max( coi_error, coidef_optdir( cntvect, 1 ) ) ! Maximize
55 coi_error = max( coi_error, coidef_objvar( cntvect, 1 ) ) ! Objective is variable 1
56 coi_error = max( coi_error, coidef_optfile( cntvect, 'EvalError01.opt' ) )
57!
58! Tell CONOPT about the callback routines:
59!
60 coi_error = max( coi_error, coidef_readmatrix( cntvect, eval_readmatrix ) )
61 coi_error = max( coi_error, coidef_fdeval( cntvect, eval_fdeval ) )
62 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
63 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
64 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
65 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
66
67#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
68 coi_error = max( coi_error, coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
69#endif
70
71 If ( coi_error .ne. 0 ) THEN
72 write(*,*)
73 write(*,*) '**** Fatal Error while loading CONOPT Callback routines.'
74 write(*,*)
75 call flog( "Skipping Solve due to setup errors", 1 )
76 ENDIF
77!
78! Save the solution so we can check the duals:
79!
80 do_allocate = .true.
81!
82! Start CONOPT:
83!
84 coi_error = coi_solve( cntvect )
85
86 write(*,*)
87 write(*,*) 'End of EvalError01 example. Return code=',coi_error
88
89 If ( coi_error /= 400 ) then
90 call flog( "Excepted COI_Solve to return 400", 1 )
91 endif
92
93 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
94
95 call flog( "Successful Solve", 0 )
96
97End Program evalerror01
98!
99! ============================================================================
100! Define information about the model:
101!
102
103!> Define information about the model
104!!
105!! @include{doc} readMatrix_params.dox
106Integer Function eval_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
107 colsta, rowno, value, nlflag, n, m, nz, &
108 usrmem )
109#if defined(itl)
110!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Eval_ReadMatrix
111#endif
112 implicit none
113 integer, intent (in) :: n ! number of variables
114 integer, intent (in) :: m ! number of constraints
115 integer, intent (in) :: nz ! number of nonzeros
116 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
117 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
118 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
119 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
120 ! (not defined here)
121 integer, intent (out), dimension(m) :: type ! vector of equation types
122 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
123 ! (not defined here)
124 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
125 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
126 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
127 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
128 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
129 real*8 usrmem(*) ! optional user memory
130!
131! Information about Variables:
132! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
133! Default: the status information in Vsta is not used.
134!
135!
136! Information about Constraints:
137! Default: Rhs = 0
138! Default: the status information in Esta and the function
139! value in FV are not used.
140! Default: Type: There is no default.
141! 0 = Equality,
142! 1 = Greater than or equal,
143! 2 = Less than or equal,
144! 3 = Non binding.
145!
146! Constraint 1 (Objective)
147! Rhs = 0 and type Equality
148!
149 type(1) = 0
150!
151! Information about the Jacobian. We use the standard method with
152! Rowno, Value, Nlflag and Colsta and we do not use Colno.
153!
154! Colsta = Start of column indices (No Defaults):
155! Rowno = Row indices
156! Value = Value of derivative (by default only linear
157! derivatives are used)
158! Nlflag = 0 for linear and 1 for nonlinear derivative
159! (not needed for completely linear models)
160!
161! Indices
162! x(1) x(2)
163! 1: 1 2
164!
165 colsta(1) = 1
166 colsta(2) = 2
167 colsta(3) = 3
168 rowno(1) = 1
169 rowno(2) = 1
170!
171! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
172! x(1) x(2)
173! 1: NL L
174!
175 nlflag(1) = 1
176 nlflag(2) = 0
177!
178! Value (Linear only)
179! x(1) x(2)
180! 1: NL -1
181!
182 value(2) = -1.d0
183
184 eval_readmatrix = 0 ! Return value means OK
185
186end Function eval_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 eval_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 :: Eval_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! Row 1: x2 = log(x1)
219!
220 eval_fdeval = 0
221 if ( rowno .eq. 1 ) then
222!
223! Mode = 1 or 3. Function value: G = log(x1)
224!
225 if ( mode .eq. 1 .or. mode .eq. 3 ) then
226 if ( x(1) .le. 0.0d0 ) then
227 errcnt = errcnt + 1
228 else
229 g = log(x(1))
230 endif
231 endif
232!
233! Mode = 2 or 3: Derivative values:
234!
235 if ( mode .eq. 2 .or. mode .eq. 3 ) then
236 if ( x(1) .le. 0.0d0 ) then
237 errcnt = errcnt + 1
238 else
239 jac(1) = 1.0d0/x(1)
240 endif
241 endif
242 Else
243!
244! Other rows -- should not happen
245!
246 eval_fdeval = 1
247 endif
248
249end Function eval_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 eval_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
integer function eval_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
program evalerror01
Main program. A simple setup and call of CONOPT.
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 coi_solve(cntvect)
method for starting the solving process of CONOPT.
Definition coistart.f90:14
subroutine flog(msg, code)
Definition comdecl.f90:56
logical do_allocate
Definition comdecl.f90:21
subroutine startup
Definition comdecl.f90:35