CONOPT
Loading...
Searching...
No Matches
eq2b.f90
Go to the documentation of this file.
1!> @file eq2b.f90
2!! @ingroup FORT1THREAD_EXAMPLES
3!!
4!!
5!! Tests EQ2 constraints that are made post-triangular by transfer of bounds.
6!!
7!! \f{eqnarray*}{
8!! \min 7&x1&+8&x2&+100&x3&\\
9!! &x1& && +&x3& = 2.0 \\
10!! &x1&+ &x2& && < 1.0 \\
11!! &x1&, &x2&, &x3& \geq 0
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!!
19Program eq2b
20!
21! Declare the user callback routines as Integer, External:
22!
23 Use proginfo
24 Use coidef
25 implicit None
26
27 Integer, External :: eq2b_readmatrix ! Mandatory Matrix definition routine defined below
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#if defined(itl)
33!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: eq2b_ReadMatrix
34!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
35!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
36!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
37!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
38#endif
39!
40! Control vector
41!
42 INTEGER :: numcallback
43 INTEGER, Dimension(:), Pointer :: cntvect
44 INTEGER :: coi_error
45
46 real*8, dimension(3) :: xsol1 = (/ 1.0d0, 0.0d0, 1.0d0 /)
47 real*8, dimension(3) :: xdua1 = (/ 0.0d0, 101.0d0, 0.0d0 /)
48 real*8, dimension(3) :: udua1 = (/ 100.d0, -93.d0, 0.d0 /)
49 Integer :: i
50 Logical :: error
51
52 Call startup
53!
54! Create and initialize a Control Vector
55!
56 numcallback = coidef_size()
57 Allocate( cntvect(numcallback) )
58 coi_error = coidef_inifort( cntvect )
59!
60! Tell CONOPT about the size of the model by populating the Control Vector:
61!
62! Number of variables
63!
64 coi_error = max( coi_error, coidef_numvar( cntvect, 3 ) )
65!
66! Number of equations
67!
68 coi_error = max( coi_error, coidef_numcon( cntvect, 3 ) )
69!
70! Number of nonzeros in the Jacobian.
71!
72 coi_error = max( coi_error, coidef_numnz( cntvect, 7 ) )
73!
74! Number of nonlinear nonzeros.
75!
76 coi_error = max( coi_error, coidef_numnlnz( cntvect, 0 ) )
77!
78! Optimization direction is Minimize = -1
79!
80 coi_error = max( coi_error, coidef_optdir( cntvect, -1 ) )
81!
82! Objective is constraint 3
83!
84 coi_error = max( coi_error, coidef_objcon( cntvect, 3 ) )
85!
86! Define the options file as 'eq2b.opt'
87!
88 coi_error = max( coi_error, coidef_optfile( cntvect, 'eq2b.opt' ) )
89!
90! Tell CONOPT about the callback routines:
91!
92 coi_error = max( coi_error, coidef_readmatrix( cntvect, eq2b_readmatrix ) )
93 coi_error = max( coi_error, coidef_status( cntvect, std_status ) )
94 coi_error = max( coi_error, coidef_solution( cntvect, std_solution ) )
95 coi_error = max( coi_error, coidef_message( cntvect, std_message ) )
96 coi_error = max( coi_error, coidef_errmsg( cntvect, std_errmsg ) )
97
98#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
99 coi_error = max( coi_error, coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
100#endif
101
102 If ( coi_error .ne. 0 ) THEN
103 write(*,*)
104 write(*,*) '**** Fatal Error while loading CONOPT Callback routines.'
105 write(*,*)
106 call flog( "Skipping Solve due to setup errors", 1 )
107 ENDIF
108 do_allocate = .true.
109!
110! Start CONOPT:
111!
112 coi_error = coi_solve( cntvect )
113
114 write(*,*)
115 write(*,*) 'End of example eq2b'
116
117 If ( coi_error /= 0 ) then
118 call flog( "Errors encountered during solution", 1 )
119 elseif ( stacalls == 0 .or. solcalls == 0 ) then
120 call flog( "Status or Solution routine was not called", 1 )
121 elseif ( sstat /= 1 .or. mstat /= 1 ) then ! This is an LP model
122 call flog( "Solver and Model Status was not as expected (1,1)", 1 )
123 elseif ( abs( obj-107.0d0 ) > 0.000001d0 ) then
124 call flog( "Incorrect objective returned", 1 )
125 Else
126!
127! Check the primal and dual solution itself
128!
129 error = .false.
130 do i = 1, 3
131 if ( abs(xprim(i)-xsol1(i)) > 1.d-7 ) error = .true.
132 if ( abs(xdual(i)-xdua1(i)) > 1.d-7 ) error = .true.
133 if ( abs(udual(i)-udua1(i)) > 1.d-7 ) error = .true.
134 enddo
135 if ( error ) call flog( "Eq2b: Numerical solution was not as expected.", 1 )
136 Call checkdual( 'Eq2b', minimize )
137 endif
138
139 if ( coi_free(cntvect) /= 0 ) call flog( "Error while freeing control vector",1)
140
141 call flog( "Successful Solve", 0 )
142
143End Program eq2b
144!
145! ============================================================================
146! Define information about the model:
147!
148
149!> Define information about the model
150!!
151!! @include{doc} readMatrix_params.dox
152Integer Function eq2b_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
153 colsta, rowno, value, nlflag, n, m, nz, usrmem )
154#if defined(itl)
155!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: eq2b_ReadMatrix
156#endif
157 implicit none
158 integer, intent (in) :: n ! number of variables
159 integer, intent (in) :: m ! number of constraints
160 integer, intent (in) :: nz ! number of nonzeros
161 real*8, intent (in out), dimension(n) :: lower ! vector of lower bounds
162 real*8, intent (in out), dimension(n) :: curr ! vector of initial values
163 real*8, intent (in out), dimension(n) :: upper ! vector of upper bounds
164 integer, intent (in out), dimension(n) :: vsta ! vector of initial variable status
165 ! (not defined here)
166 integer, intent (out), dimension(m) :: type ! vector of equation types
167 integer, intent (in out), dimension(m) :: esta ! vector of initial equation status
168 ! (not defined here)
169 real*8, intent (in out), dimension(m) :: rhs ! vector of right hand sides
170 integer, intent (in out), dimension(n+1) :: colsta ! vector with start of column indices
171 integer, intent (out), dimension(nz) :: rowno ! vector of row numbers
172 integer, intent (in out), dimension(nz) :: nlflag ! vector of nonlinearity flags
173 real*8, intent (in out), dimension(nz) :: value ! vector of matrix values
174 real*8 usrmem(*) ! optional user memory
175!
176! Define information about the Variables:
177!
178! Curr is not defined. We will use the default starting values of
179! zero.
180!
181! By default, we do not define the status argument Vsta.
182!
183! The variables are Positive, i.e. have a lower bound of zero.
184!
185 lower(1) = 0.d0
186 lower(2) = 0.d0
187 lower(3) = 0.d0
188!
189! Define information about the Constraints:
190!
191 rhs(1) = 2.0d0
192 type(1) = 0 ! =E=
193 rhs(2) = 1.0d0
194 type(2) = 2 ! =L=
195 type(3) = 3 ! =N=
196!
197! The Jacobian has to be sorted column-wise so we will just define
198! the elements column by column according to the table above:
199!
200 colsta(1) = 1
201 rowno(1) = 1
202 value(1) = 1.d0
203 rowno(2) = 2
204 value(2) = 1.d0
205 rowno(3) = 3
206 value(3) = 7.d0
207!
208 colsta(2) = 4
209 rowno(4) = 2
210 value(4) = 1.0d0
211 rowno(5) = 3
212 value(5) = 8.0d0
213!
214 colsta(3) = 6
215 rowno(6) = 1
216 value(6) = 1.d0
217 rowno(7) = 3
218 value(7) = 100.0d0
219!
220!
221! End of columns, the next free position is = number of elements+1:
222!
223 colsta(4) = 8
224
226
227end Function eq2b_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 eq2b_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
Definition eq2b.f90:154
program eq2b
Main program. A simple setup and call of CONOPT.
Definition eq2b.f90:19
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_objcon(cntvect, objcon)
defines the Objective Constraint.
Definition coistart.f90:629
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_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
real *8 obj
Definition comdecl.f90:10
integer solcalls
Definition comdecl.f90:9
integer sstat
Definition comdecl.f90:12
real *8, dimension(:), pointer udual
Definition comdecl.f90:18
real *8, dimension(:), pointer xdual
Definition comdecl.f90:17
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
real *8, dimension(:), pointer xprim
Definition comdecl.f90:17
integer mstat
Definition comdecl.f90:11
subroutine startup
Definition comdecl.f90:35