CONOPT
Loading...
Searching...
No Matches
lp01a.f90
Go to the documentation of this file.
1!> @file lp01a.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!! Test model lp01a.gms -- case with an error
5!!
6!! For more information about the individual callbacks, please have a look at the source code.
7
8
9!> Main program. A simple setup and call of CONOPT
10!!
11Program lp01a
12
13 Use proginfo
14 Use coidef
15 implicit None
16!
17! Declare the user callback routines as Integer, External:
18!
19 Integer, External :: lp01a_readmatrix ! Mandatory Matrix definition routine defined below
20 Integer, External :: std_status ! Standard callback for displaying solution status
21 Integer, External :: std_solution ! Standard callback for displaying solution values
22 Integer, External :: std_message ! Standard callback for managing messages
23 Integer, External :: std_errmsg ! Standard callback for managing error messages
24#if defined(itl)
25!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lp01a_ReadMatrix
26!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
27!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
28!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
29!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
30#endif
31!
32! Control vector
33!
34 INTEGER :: numcallback
35 INTEGER, Dimension(:), Pointer :: cntvect
36 INTEGER :: coi_error
37!
38! Create and initialize a Control Vector
39!
40 call startup
41
42 numcallback = coidef_size()
43 Allocate( cntvect(numcallback) )
44 coi_error = coidef_inifort( cntvect )
45!
46! Tell CONOPT about the size of the model by populating the Control Vector:
47!
48 coi_error = max( coi_error, coidef_numvar( cntvect, 1 ) ) ! 4 variables
49 coi_error = max( coi_error, coidef_numcon( cntvect, 1 ) ) ! 3 constraints
50 coi_error = max( coi_error, coidef_numnz( cntvect, 1 ) ) ! 9 nonzeros in the Jacobian
51 coi_error = max( coi_error, coidef_numnlnz( cntvect, 0 ) ) ! 4 of which are nonlinear
52 coi_error = max( coi_error, coidef_optdir( cntvect, -1 ) ) ! Minimize
53 coi_error = max( coi_error, coidef_objvar( cntvect, 1 ) ) ! Objective is constraint 1
54 coi_error = max( coi_error, coidef_optfile( cntvect, 'lp01a.opt' ) )
55!
56! Tell CONOPT about the callback routines:
57!
58 coi_error = max( coi_error, coidef_readmatrix( cntvect, lp01a_readmatrix ) )
59 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
60 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
61 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
62 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
63
64#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
65 coi_error = max( coi_error, coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
66#endif
67
68 If ( coi_error .ne. 0 ) THEN
69 write(*,*)
70 write(*,*) '**** Fatal Error while loading CONOPT4 Callback routines.'
71 write(*,*)
72 call flog( "Skipping Solve due to setup errors", 1 )
73 ENDIF
74!
75! Save the solution so we can check the duals:
76!
77 do_allocate = .true.
78!
79! Start CONOPT:
80!
81 coi_error = coi_solve( cntvect )
82
83 write(*,*)
84 write(*,*) 'End of lp01a example. Return code=',coi_error
85
86 If ( coi_error /= 0 ) then
87 call flog( "Errors encountered during solution", 1 )
88 elseif ( stacalls == 0 .or. solcalls == 0 ) then
89 call flog( "Status or Solution routine was not called", 1 )
90 elseif ( sstat /= 1 .or. mstat /= 1 ) then
91 call flog( "Solver and Model Status was not as expected (1,1)", 1 )
92 elseif ( abs( obj-1.d0 ) > 0.000001d0 ) then
93 call flog( "Incorrect objective returned", 1 )
94 Else
95 Call checkdual( 'lp01a', minimize )
96 endif
97
98 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
99
100 call flog( "Successful Solve", 0 )
101
102End Program lp01a
103!
104! ============================================================================
105! Define information about the model:
106!
107
108!> Define information about the model
109!!
110!! @include{doc} readMatrix_params.dox
111Integer Function lp01a_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
112 colsta, rowno, value, nlflag, n, m, nz, &
113 usrmem )
114#if defined(itl)
115!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lp01a_ReadMatrix
116#endif
117 implicit none
118 integer, intent (in) :: n ! number of variables
119 integer, intent (in) :: m ! number of constraints
120 integer, intent (in) :: nz ! number of nonzeros
121 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
122 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
123 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
124 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
125 ! (not defined here)
126 integer, intent (out), dimension(m) :: type ! vector of equation types
127 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
128 ! (not defined here)
129 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
130 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
131 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
132 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
133 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
134 real*8 usrmem(*) ! optional user memory
135!
136! Information about Variables:
137! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
138! Default: the status information in Vsta is not used.
139!
140! Information about Constraints:
141! Default: Rhs = 0
142! Default: the status information in Esta and the function
143! value in FV are not used.
144! Default: Type: There is no default.
145! 0 = Equality,
146! 1 = Greater than or equal,
147! 2 = Less than or equal,
148! 3 = Non binding.
149!
150! Constraint 1 (Objective)
151! Rhs = -0.1 and type Non binding
152!
153 rhs(1) = 1.0d0
154 type(1) = 0
155!
156! Information about the Jacobian. We use the standard method with
157! Rowno, Value, Nlflag and Colsta and we do not use Colno.
158!
159! Colsta = Start of column indices (No Defaults):
160! Rowno = Row indices
161! Value = Value of derivative (by default only linear
162! derivatives are used)
163! Nlflag = 0 for linear and 1 for nonlinear derivative
164! (not needed for completely linear models)
165!
166! Indices
167! x(1)
168! 1: 1
169!
170 colsta(1) = 1
171 colsta(2) = 2
172 rowno(1) = 1
173!
174! Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear
175! x(1)
176! 1: L
177!
178! nlflag(1) = 0 ! Not needed for a linear model
179!
180! Value (Linear only)
181! x(1)
182! 1: 1
183!
184 value(1) = 1.d0
185
186 lp01a_readmatrix = 0 ! Return value means OK
187
188end Function lp01a_readmatrix
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
subroutine checkdual(case, minmax)
Definition comdecl.f90:365
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_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 lp01a_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
Definition lp01a.f90:114
program lp01a
Main program. A simple setup and call of CONOPT.
Definition lp01a.f90:11
real *8 obj
Definition comdecl.f90:10
integer solcalls
Definition comdecl.f90:9
integer sstat
Definition comdecl.f90:12
integer, parameter minimize
Definition comdecl.f90:25
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