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