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