CONOPT
Loading...
Searching...
No Matches
overflow01.f90
Go to the documentation of this file.
1!> @file overflow01.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!!
5!! A program that will give large post-triangular variables.
6!! Used to check the back-tracking in Newton and Conedm.
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 :: over_readmatrix ! Mandatory Matrix definition routine defined below
22 Integer, External :: over_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 :: Over_ReadMatrix
30!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_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, 4 ) ) ! 4 variables
51 coi_error = max( coi_error, coidef_numcon( cntvect, 3 ) ) ! 3 constraints
52 coi_error = max( coi_error, coidef_numnz( cntvect, 6 ) ) ! 6 nonzeros in the Jacobian
53 coi_error = max( coi_error, coidef_numnlnz( cntvect, 3 ) ) ! 3 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, 'Overflow01.opt' ) )
57!
58! Tell CONOPT about the callback routines:
59!
60 coi_error = max( coi_error, coidef_readmatrix( cntvect, over_readmatrix ) )
61 coi_error = max( coi_error, coidef_fdeval( cntvect, over_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 Overflow01 example. Return code=',coi_error
88
89 If ( coi_error /= 0 ) then
90 call flog( "Errors encountered during solution", 1 )
91 elseif ( stacalls == 0 .or. solcalls == 0 ) then
92 call flog( "Status or Solution routine was not called", 1 )
93!
94! Expecting Solver status = 1 (Normal) and Model Status = 3 = Unbounded
95 elseif ( sstat /= 1 .or. mstat /= 3 ) then
96 call flog( "Solver and Model Status was not as expected (1,3)", 1 )
97! We cannot use CheckDual for models with overflow since a variable does not have 'normal' status
98 endif
99
100 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
101
102 call flog( "Successful Solve", 0 )
103
104End Program overflow01
105!
106! ============================================================================
107! Define information about the model:
108!
109
110!> Define information about the model
111!!
112!! @include{doc} readMatrix_params.dox
113Integer Function over_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
114 colsta, rowno, value, nlflag, n, m, nz, &
115 usrmem )
116#if defined(itl)
117!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_ReadMatrix
118#endif
119 implicit none
120 integer, intent (in) :: n ! number of variables
121 integer, intent (in) :: m ! number of constraints
122 integer, intent (in) :: nz ! number of nonzeros
123 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
124 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
125 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
126 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
127 ! (not defined here)
128 integer, intent (out), dimension(m) :: type ! vector of equation types
129 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
130 ! (not defined here)
131 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
132 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
133 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
134 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
135 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
136 real*8 usrmem(*) ! optional user memory
137!
138! Information about Variables:
139! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
140! Default: the status information in Vsta is not used.
141!
142 curr(1) = 1.0d0
143 curr(2) = 1.0d0
144 curr(3) = 1.0d0
145 curr(4) = 1.0d0
146!
147! Information about Constraints:
148! Default: Rhs = 0
149! Default: the status information in Esta and the function
150! value in FV are not used.
151! Default: Type: There is no default.
152! 0 = Equality,
153! 1 = Greater than or equal,
154! 2 = Less than or equal,
155! 3 = Non binding.
156!
157 type(1) = 0
158 type(2) = 0
159 type(3) = 0
160!
161! Information about the Jacobian. We use the standard method with
162! Rowno, Value, Nlflag and Colsta and we do not use Colno.
163!
164! Colsta = Start of column indices (No Defaults):
165! Rowno = Row indices
166! Value = Value of derivative (by default only linear
167! derivatives are used)
168! Nlflag = 0 for linear and 1 for nonlinear derivative
169! (not needed for completely linear models)
170!
171! Indices
172! x(1) x(2) x(3) x(4)
173! 1: 1 2
174! 2: 3 4
175! 3: 5 6
176!
177 colsta(1) = 1
178 colsta(2) = 2
179 colsta(3) = 4
180 colsta(4) = 6
181 colsta(5) = 7
182 rowno(1) = 1
183 rowno(2) = 1
184 rowno(3) = 2
185 rowno(4) = 2
186 rowno(5) = 3
187 rowno(6) = 3
188!
189! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
190! x(1) x(2) x(3) x(4)
191! 1: L NL
192! 2: L NL
193! 3: L NL
194!
195 nlflag(1) = 0
196 nlflag(2) = 1
197 nlflag(3) = 0
198 nlflag(4) = 1
199 nlflag(5) = 0
200 nlflag(6) = 1
201!
202! Value (Linear only)
203! x(1) x(2) x(3) x(4)
204! 1: -1 NL
205! 2: -1 NL
206! 3: -1 NL
207!
208 value(1) = -1.d0
209 value(3) = -1.d0
210 value(5) = -1.d0
211
212 over_readmatrix = 0 ! Return value means OK
213
214end Function over_readmatrix
215!
216!==========================================================================
217! Compute nonlinear terms and non-constant Jacobian elements
218!
219
220!> Compute nonlinear terms and non-constant Jacobian elements
221!!
222!! @include{doc} fdeval_params.dox
223Integer Function over_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
224 n, nz, thread, usrmem )
225#if defined(itl)
226!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_FDEval
227#endif
228 implicit none
229 integer, intent (in) :: n ! number of variables
230 integer, intent (in) :: rowno ! number of the row to be evaluated
231 integer, intent (in) :: nz ! number of nonzeros in this row
232 real*8, intent (in), dimension(n) :: x ! vector of current solution values
233 real*8, intent (in out) :: g ! constraint value
234 real*8, intent (in out), dimension(n) :: jac ! vector of derivatives for current constraint
235 integer, intent (in), dimension(nz) :: jcnm ! list of variables that appear nonlinearly
236 ! in this row. Ffor information only.
237 integer, intent (in) :: mode ! evaluation mode: 1 = function value
238 ! 2 = derivatives, 3 = both
239 integer, intent (in) :: ignerr ! if 1 then errors can be ignored as long
240 ! as errcnt is incremented
241 integer, intent (in out) :: errcnt ! error counter to be incremented in case
242 ! of function evaluation errors.
243 integer, intent (in) :: thread
244 real*8 usrmem(*) ! optional user memory
245!
246! Row i: x(i+1)**2 - x(i) = 0
247!
248 over_fdeval = 0
249 if ( rowno .ge. 1 .and. rowno .le. 3 ) then
250!
251! Mode = 1 or 3. Function value: x(i+1)**2
252!
253 if ( mode .eq. 1 .or. mode .eq. 3 ) then
254 g = x(rowno+1)**2
255 endif
256!
257! Mode = 2 or 3: Derivative values:
258!
259 if ( mode .eq. 2 .or. mode .eq. 3 ) then
260 jac(rowno+1) = 2.d0*x(rowno+1)
261 endif
262 Else
263 over_fdeval = 1
264 endif
265
266end Function over_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 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
program overflow01
Main program. A simple setup and call of CONOPT.
integer function over_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer function over_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.