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#if defined(_WIN32) && !defined(_WIN64)
12#define dec_directives_win32
13#endif
14
15!> Main program. A simple setup and call of CONOPT
16!!
17Program overflow01
18
20 Use conopt
21 implicit None
22!
23! Declare the user callback routines as Integer, External:
24!
25 Integer, External :: over_readmatrix ! Mandatory Matrix definition routine defined below
26 Integer, External :: over_fdeval ! Function and Derivative evaluation routine
27 ! needed a nonlinear model.
28 Integer, External :: std_status ! Standard callback for displaying solution status
29 Integer, External :: std_solution ! Standard callback for displaying solution values
30 Integer, External :: std_message ! Standard callback for managing messages
31 Integer, External :: std_errmsg ! Standard callback for managing error messages
32#ifdef dec_directives_win32
33!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_ReadMatrix
34!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_FDEval
35!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
36!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
37!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
38!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
39#endif
40!
41! Control vector
42!
43 INTEGER, Dimension(:), Pointer :: cntvect
44 INTEGER :: coi_error
45!
46! Create and initialize a Control Vector
47!
48 call startup
49
50 coi_error = coi_create( cntvect )
51!
52! Tell CONOPT about the size of the model by populating the Control Vector:
53!
54 coi_error = max( coi_error, coidef_numvar( cntvect, 4 ) ) ! 4 variables
55 coi_error = max( coi_error, coidef_numcon( cntvect, 3 ) ) ! 3 constraints
56 coi_error = max( coi_error, coidef_numnz( cntvect, 6 ) ) ! 6 nonzeros in the Jacobian
57 coi_error = max( coi_error, coidef_numnlnz( cntvect, 3 ) ) ! 3 of which are nonlinear
58 coi_error = max( coi_error, coidef_optdir( cntvect, 1 ) ) ! Maximize
59 coi_error = max( coi_error, coidef_objvar( cntvect, 1 ) ) ! Objective is variable 1
60 coi_error = max( coi_error, coidef_optfile( cntvect, 'Overflow01.opt' ) )
61!
62! Tell CONOPT about the callback routines:
63!
64 coi_error = max( coi_error, coidef_readmatrix( cntvect, over_readmatrix ) )
65 coi_error = max( coi_error, coidef_fdeval( cntvect, over_fdeval ) )
66 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
67 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
68 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
69 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
70
71#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
72 coi_error = max( coi_error, coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
73#endif
74
75 If ( coi_error .ne. 0 ) THEN
76 write(*,*)
77 write(*,*) '**** Fatal Error while loading CONOPT Callback routines.'
78 write(*,*)
79 call flog( "Skipping Solve due to setup errors", 1 )
80 ENDIF
81!
82! Save the solution so we can check the duals:
83!
84 do_allocate = .true.
85!
86! Start CONOPT:
87!
88 coi_error = coi_solve( cntvect )
89
90 write(*,*)
91 write(*,*) 'End of Overflow01 example. Return code=',coi_error
92
93 If ( coi_error /= 0 ) then
94 call flog( "Errors encountered during solution", 1 )
95 elseif ( stacalls == 0 .or. solcalls == 0 ) then
96 call flog( "Status or Solution routine was not called", 1 )
97!
98! Expecting Solver status = 1 (Normal) and Model Status = 3 = Unbounded
99 elseif ( sstat /= 1 .or. mstat /= 3 ) then
100 call flog( "Solver and Model Status was not as expected (1,3)", 1 )
101! We cannot use CheckDual for models with overflow since a variable does not have 'normal' status
102 endif
103
104 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
105
106 call flog( "Successful Solve", 0 )
107!
108! Free solution memory
109!
110 call finalize
111
112End Program overflow01
113!
114! ============================================================================
115! Define information about the model:
116!
117
118!> Define information about the model
119!!
120!! @include{doc} readMatrix_params.dox
121Integer Function over_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
122 colsta, rowno, value, nlflag, n, m, nz, &
123 usrmem )
124#ifdef dec_directives_win32
125!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_ReadMatrix
126#endif
127 implicit none
128 integer, intent (in) :: n ! number of variables
129 integer, intent (in) :: m ! number of constraints
130 integer, intent (in) :: nz ! number of nonzeros
131 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
132 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
133 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
134 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
135 ! (not defined here)
136 integer, intent (out), dimension(m) :: type ! vector of equation types
137 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
138 ! (not defined here)
139 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
140 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
141 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
142 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
143 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
144 real*8 usrmem(*) ! optional user memory
145!
146! Information about Variables:
147! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
148! Default: the status information in Vsta is not used.
149!
150 curr(1) = 1.0d0
151 curr(2) = 1.0d0
152 curr(3) = 1.0d0
153 curr(4) = 1.0d0
154!
155! Information about Constraints:
156! Default: Rhs = 0
157! Default: the status information in Esta and the function
158! value in FV are not used.
159! Default: Type: There is no default.
160! 0 = Equality,
161! 1 = Greater than or equal,
162! 2 = Less than or equal,
163! 3 = Non binding.
164!
165 type(1) = 0
166 type(2) = 0
167 type(3) = 0
168!
169! Information about the Jacobian. CONOPT expects a columnwise
170! representation in Rowno, Value, Nlflag and Colsta.
171!
172! Colsta = Start of column indices (No Defaults):
173! Rowno = Row indices
174! Value = Value of derivative (by default only linear
175! derivatives are used)
176! Nlflag = 0 for linear and 1 for nonlinear derivative
177! (not needed for completely linear models)
178!
179! Indices
180! x(1) x(2) x(3) x(4)
181! 1: 1 2
182! 2: 3 4
183! 3: 5 6
184!
185 colsta(1) = 1
186 colsta(2) = 2
187 colsta(3) = 4
188 colsta(4) = 6
189 colsta(5) = 7
190 rowno(1) = 1
191 rowno(2) = 1
192 rowno(3) = 2
193 rowno(4) = 2
194 rowno(5) = 3
195 rowno(6) = 3
196!
197! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
198! x(1) x(2) x(3) x(4)
199! 1: L NL
200! 2: L NL
201! 3: L NL
202!
203 nlflag(1) = 0
204 nlflag(2) = 1
205 nlflag(3) = 0
206 nlflag(4) = 1
207 nlflag(5) = 0
208 nlflag(6) = 1
209!
210! Value (Linear only)
211! x(1) x(2) x(3) x(4)
212! 1: -1 NL
213! 2: -1 NL
214! 3: -1 NL
215!
216 value(1) = -1.d0
217 value(3) = -1.d0
218 value(5) = -1.d0
220 over_readmatrix = 0 ! Return value means OK
221
222end Function over_readmatrix
223!
224!==========================================================================
225! Compute nonlinear terms and non-constant Jacobian elements
226!
227
228!> Compute nonlinear terms and non-constant Jacobian elements
229!!
230!! @include{doc} fdeval_params.dox
231Integer Function over_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
232 n, nz, thread, usrmem )
233#ifdef dec_directives_win32
234!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Over_FDEval
235#endif
236 implicit none
237 integer, intent (in) :: n ! number of variables
238 integer, intent (in) :: rowno ! number of the row to be evaluated
239 integer, intent (in) :: nz ! number of nonzeros in this row
240 real*8, intent (in), dimension(n) :: x ! vector of current solution values
241 real*8, intent (in out) :: g ! constraint value
242 real*8, intent (in out), dimension(n) :: jac ! vector of derivatives for current constraint
243 integer, intent (in), dimension(nz) :: jcnm ! list of variables that appear nonlinearly
244 ! in this row. Ffor information only.
245 integer, intent (in) :: mode ! evaluation mode: 1 = function value
246 ! 2 = derivatives, 3 = both
247 integer, intent (in) :: ignerr ! if 1 then errors can be ignored as long
248 ! as errcnt is incremented
249 integer, intent (in out) :: errcnt ! error counter to be incremented in case
250 ! of function evaluation errors.
251 integer, intent (in) :: thread
252 real*8 usrmem(*) ! optional user memory
253!
254! Row i: x(i+1)**2 - x(i) = 0
255!
256 over_fdeval = 0
257 if ( rowno .ge. 1 .and. rowno .le. 3 ) then
258!
259! Mode = 1 or 3. Function value: x(i+1)**2
260!
261 if ( mode .eq. 1 .or. mode .eq. 3 ) then
262 g = x(rowno+1)**2
263 endif
264!
265! Mode = 2 or 3: Derivative values:
266!
267 if ( mode .eq. 2 .or. mode .eq. 3 ) then
268 jac(rowno+1) = 2.d0*x(rowno+1)
269 endif
270 Else
271 over_fdeval = 1
272 endif
273
274end Function over_fdeval
integer function std_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
Definition comdecl.f90:170
integer function std_status(modsta, solsta, iter, objval, usrmem)
Definition comdecl.f90:126
integer function std_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
Definition comdecl.f90:243
integer function std_errmsg(rowno, colno, posno, msglen, usrmem, msg)
Definition comdecl.f90:286
integer(c_int) function coidef_message(cntvect, coi_message)
define callback routine for handling messages returned during the solution process.
Definition conopt.f90:1265
integer(c_int) function coidef_solution(cntvect, coi_solution)
define callback routine for returning the final solution values.
Definition conopt.f90:1238
integer(c_int) function coidef_status(cntvect, coi_status)
define callback routine for returning the completion status.
Definition conopt.f90:1212
integer(c_int) function coidef_readmatrix(cntvect, coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
Definition conopt.f90:1111
integer(c_int) function coidef_errmsg(cntvect, coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
Definition conopt.f90:1291
integer(c_int) function coidef_fdeval(cntvect, coi_fdeval)
define callback routine for performing function and derivative evaluations.
Definition conopt.f90:1135
integer(c_int) function coidef_optfile(cntvect, optfile)
define callback routine for defining an options file.
Definition conopt.f90:928
integer(c_int) function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
Definition conopt.f90:293
integer(c_int) function coidef_numvar(cntvect, numvar)
defines the number of variables in the model.
Definition conopt.f90:97
integer(c_int) function coidef_numcon(cntvect, numcon)
defines the number of constraints in the model.
Definition conopt.f90:121
integer(c_int) function coidef_numnlnz(cntvect, numnlnz)
defines the Number of Nonlinear Nonzeros.
Definition conopt.f90:167
integer(c_int) function coidef_optdir(cntvect, optdir)
defines the Optimization Direction.
Definition conopt.f90:213
integer(c_int) function coidef_numnz(cntvect, numnz)
defines the number of nonzero elements in the Jacobian.
Definition conopt.f90:144
integer(c_int) function coidef_objvar(cntvect, objvar)
defines the Objective Variable.
Definition conopt.f90:257
integer(c_int) function coi_create(cntvect)
initializes CONOPT and creates the control vector.
Definition conopt.f90:1726
integer(c_int) function coi_free(cntvect)
frees the control vector.
Definition conopt.f90:1749
integer(c_int) function coi_solve(cntvect)
method for starting the solving process of CONOPT.
Definition conopt.f90:1625
integer solcalls
Definition comdecl.f90:15
integer sstat
Definition comdecl.f90:18
subroutine finalize
Definition comdecl.f90:79
integer stacalls
Definition comdecl.f90:14
subroutine flog(msg, code)
Definition comdecl.f90:62
logical do_allocate
Definition comdecl.f90:27
integer mstat
Definition comdecl.f90:17
subroutine startup
Definition comdecl.f90:41
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.