CONOPT
Loading...
Searching...
No Matches
lp10.f90
Go to the documentation of this file.
1!> @file lp10.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!! Test model lp10.gms -- case with an error
5!!
6!! For more information about the individual callbacks, please have a look at the source code.
7
8#if defined(_WIN32) && !defined(_WIN64)
9#define dec_directives_win32
10#endif
11
12module caseconst
13 real*8 :: case_c
14end module caseconst
15!> Main program. A simple setup and call of CONOPT
16!!
17Program lp10
18
20 Use conopt
21 Use caseconst
22 implicit None
23!
24! Declare the user callback routines as Integer, External:
25!
26 Integer, External :: lp10_readmatrix ! Mandatory Matrix definition routine defined below
27 Integer, External :: std_status ! Standard callback for displaying solution status
28 Integer, External :: std_solution ! Standard callback for displaying solution values
29 Integer, External :: std_message ! Standard callback for managing messages
30 Integer, External :: std_errmsg ! Standard callback for managing error messages
31#ifdef dec_directives_win32
32!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lp10_ReadMatrix
33!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
34!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
35!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
36!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
37#endif
38!
39! Control vector
40!
41 INTEGER, Dimension(:), Pointer :: cntvect
42 INTEGER :: coi_error
43
44 Integer :: iter
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, 5 ) ) ! # variables
55 coi_error = max( coi_error, coidef_numcon( cntvect, 2 ) ) ! # constraints
56 coi_error = max( coi_error, coidef_numnz( cntvect, 7 ) ) ! # nonzeros in the Jacobian
57 coi_error = max( coi_error, coidef_numnlnz( cntvect, 0 ) ) ! # of which are nonlinear
58 coi_error = max( coi_error, coidef_optdir( cntvect, -1 ) ) ! Minimize
59 coi_error = max( coi_error, coidef_objvar( cntvect, 5 ) ) ! Objective is variable 5
60 coi_error = max( coi_error, coidef_optfile( cntvect, 'lp10.opt' ) )
61!
62! Tell CONOPT about the callback routines:
63!
64 coi_error = max( coi_error, coidef_readmatrix( cntvect, lp10_readmatrix ) )
65 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
66 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
67 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
68 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
69
70#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
71 coi_error = max( coi_error, coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
72#endif
73
74 If ( coi_error .ne. 0 ) THEN
75 write(*,*)
76 write(*,*) '**** Fatal Error while loading CONOPT4 Callback routines.'
77 write(*,*)
78 call flog( "Skipping Solve due to setup errors", 1 )
79 ENDIF
80!
81! Save the solution so we can check the duals:
82!
83 do_allocate = .true.
84!
85! Start CONOPT:
86!
87 case_c = 1.0d0
88 do iter = 1, 100
89 case_c = case_c / 10.d0
90 coi_error = coi_solve( cntvect )
91 If ( coi_error /= 0 ) then
92 call flog( "Errors encountered during solution", 1 )
93 elseif ( stacalls == 0 .or. solcalls == 0 ) then
94 call flog( "Status or Solution routine was not called", 1 )
95 elseif ( sstat /= 1 ) then
96 call flog( "Solver Status was 1 not as expected.", 1 )
97 else
98 if ( mstat == 3 ) then ! Unbounded
99 if ( c_unbnd == 0 ) then
100 call flog( "Unbounded model but count of unbounded variables was zero.", 1 )
101 endif
102 else if ( mstat == 1 ) then ! Optimal
103 if ( c_unbnd /= 0 ) then
104 call flog( "Optimal model but Count of unbounded variables was not zero.", 1 )
105 Endif
106 if ( case_c > 1.d-6 ) then
107 call flog( "Optimal model but case_c > 1.d-6 should give unbounded.", 1 )
108 endif
109 exit
110 else
111 call flog( "Model Status was not as expected 3 or 1.", 1 )
112 endif
113 endif
114 enddo
115
116 write(*,*)
117 write(*,*) 'End of lp10 example. Return code=',coi_error
118
119 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
120
121 call flog( "Successful Solve", 0 )
122!
123! Free solution memory
124!
125 call finalize
126
127End Program lp10
128!
129! ============================================================================
130! Define information about the model:
131!
132
133!> Define information about the model
134!!
135!! @include{doc} readMatrix_params.dox
136Integer Function lp10_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
137 colsta, rowno, value, nlflag, n, m, nz, &
138 usrmem )
139#ifdef dec_directives_win32
140!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Lp10_ReadMatrix
141#endif
142 use caseconst
143 implicit none
144 integer, intent (in) :: n ! number of variables
145 integer, intent (in) :: m ! number of constraints
146 integer, intent (in) :: nz ! number of nonzeros
147 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
148 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
149 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
150 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
151 ! (not defined here)
152 integer, intent (out), dimension(m) :: type ! vector of equation types
153 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
154 ! (not defined here)
155 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
156 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
157 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
158 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
159 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
160 real*8 usrmem(*) ! optional user memory
161!
162! Information about Variables:
163! Default: Lower = -Inf, Curr = 0, and Upper = +inf.
164! Default: the status information in Vsta is not used.
165!
166 lower(3) = 0.0d0
167 lower(4) = 0.0d0
168!
169! Information about Constraints:
170! Default: Rhs = 0
171! Default: the status information in Esta and the function
172! value in FV are not used.
173! Default: Type: There is no default.
174! 0 = Equality,
175! 1 = Greater than or equal,
176! 2 = Less than or equal,
177! 3 = Non binding.
178!
179 type(1) = 0
180 type(2) = 0
181!
182! Information about the Jacobian. CONOPT expects a columnwise
183! representation in Rowno, Value, Nlflag and Colsta.
184!
185! Colsta = Start of column indices (No Defaults):
186! Rowno = Row indices
187! Value = Value of derivative (by default only linear
188! derivatives are used)
189! Nlflag = 0 for linear and 1 for nonlinear derivative
190! (not needed for completely linear models)
191!
192! Indices
193! x1 x2 x3 x4 x5
194! 1: 1 4 7
195! 2: 2 3 5 6
196!
197 colsta(1) = 1
198 colsta(2) = 3
199 colsta(3) = 4
200 colsta(4) = 6
201 colsta(5) = 7
202 colsta(6) = 8
203 rowno(1) = 1
204 rowno(2) = 2
205 rowno(3) = 2
206 rowno(4) = 1
207 rowno(5) = 2
208 rowno(6) = 2
209 rowno(7) = 1
210!
211! Nonlinearity Structure: Not needed for a linear model
212!
213! Value (Linear only)
214! x1 x2 x3 x4 x5
215! 1: -1 -1 1
216! 2: 1 c 1 -1
217!
218 value(1) = -1.d0
219 value(2) = 1.d0
220 value(3) = case_c
221 value(4) = -1.d0
222 value(5) = 1.d0
223 value(6) = -1.d0
224 value(7) = 1.d0
225
226 lp10_readmatrix = 0 ! Return value means OK
227
228end Function lp10_readmatrix
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_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 function lp10_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
Definition lp10.f90:141
program lp10
Main program. A simple setup and call of CONOPT.
Definition lp10.f90:19
real *8 case_c
Definition lp10.f90:15
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
integer c_unbnd
Definition comdecl.f90:22