CONOPT
Loading...
Searching...
No Matches
comdeclp.f90
Go to the documentation of this file.
2!
3! Module with information about the program used to check if the
4! example executed properly and write messages accordingly.
5! This is a version for parallel use with less functionality than
6! in the standard comdecl.f90 version
7!
8 Implicit NONE
9 Character(len=128):: progname ! Program name
10 Logical :: nameread = .false.
11 Integer :: stacalls = 0 ! Number of times Std_Status has been called
12 Integer :: solcalls = 0 ! Number of times Std_Solution has been called
13 real*8 :: obj ! Objective in last Std_Status
14 Integer :: mstat = 0 ! Value of MODSTA in last Std_Status
15 Integer :: sstat = 0 ! Value of SOLSTA in last Std_Status
16 Integer :: miter = 0 ! Value of ITER in last Std_Status
17 Logical :: debug = .false. ! Can be used to turn extra output on.
18
19 Contains
20!
21! Nullify pointers, get the name of the program, and write the first
22! status-line with "Starting to execute".
23!
24 Subroutine startup
25!$ Use OMP_Lib
26 IMPLICIT NONE
27!$ Integer :: MaxThread
28 read(*,"(A)") progname
29 call flog( "Starting to execute", 0 )
30!
31! Open the Progname.lst and Progname.sta files on unit 10 and 11
32!
33 open(10,file=trim(progname) // '.lst',status='Unknown')
34 open(11,file=trim(progname) // '.sta',status='Unknown')
35!$ maxthread = OMP_GET_MAX_THREADS() ! We make the call to force the right libraries to be loaded.
36 End Subroutine startup
37!
38! Write a one-line status report used to monitor in the Progname.rc file
39! how far the program has progressed.
40!
41 Subroutine flog( Msg, Code )
42 IMPLICIT NONE
43 character(len=*), Intent(IN) :: Msg
44 Integer, Intent(IN) :: Code
45
46 open(15,file=trim(progname) // '.rc',action='write',form='formatted',status='unknown')
47 write(15,"(A,': ',A)") trim(progname), msg
48 close(15)
49 if ( code /= 0 ) then ! Error return.
50 close(10) ! Close the Status and
51 close(11) ! Document files and
52 stop 1 ! Stop
53 Endif
54 End Subroutine flog
55
56End Module proginfop
57!
58! Standard routines for Message, Status, Solution, and ErrMsg called
59! Std_Message, Std_Status, Std_Solution, and Std_ErrMsg.
60! The routines assume that the documentation file is opened as unit
61! 10 and that the status file is opened as unit 11.
62! The routines are use in the model if they are defined as callbacks
63! using the COIDEF_* routines. Otherwise, they will be ignored.
64! The routines are intended as inspiration for some more realistic
65! and useful implementations.
66!
67Integer Function std_status( MODSTA, SOLSTA, ITER, OBJVAL, USRMEM )
68#if defined(itl)
69!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Status
70#endif
71!
72! Simple implementation in which we write to all files
73!
74 Use proginfop
75 IMPLICIT NONE
76 INTEGER, Intent(IN) :: modsta, solsta, iter
77 real*8, Intent(IN) :: objval
78 real*8, Intent(IN OUT) :: usrmem(*)
79
80 WRITE(*,*)
81 WRITE(*,*) 'CONOPT has finished optimizing.'
82 WRITE(*,*) 'Model status =',modsta
83 WRITE(*,*) 'Solver status =',solsta
84 WRITE(*,*) 'Iteration count=',iter
85 WRITE(*,*) 'Objective value=',objval
86
87 WRITE(10,*)
88 WRITE(10,*) 'CONOPT has finished optimizing.'
89 WRITE(10,*) 'Model status =',modsta
90 WRITE(10,*) 'Solver status =',solsta
91 WRITE(10,*) 'Iteration count=',iter
92 WRITE(10,*) 'Objective value=',objval
93
94 WRITE(11,*)
95 WRITE(11,*) 'Model status =',modsta
96 WRITE(11,*) 'Solver status =',solsta
97 WRITE(11,*) 'Objective value=',objval
98#if defined (wei)
99 Call flush(10)
100 Call flush(11)
101#endif
102
103 stacalls = stacalls + 1
104 obj = objval
105 mstat = modsta
106 sstat = solsta
107 miter = iter
108
109 std_status = 0
110
111END Function std_status
112
113Integer Function std_solution( XVAL, XMAR, XBAS, XSTA, YVAL, YMAR, YBAS, YSTA, N, M, USRMEM )
114#if defined(itl)
115!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Solution
116#endif
117!
118! Simple implementation in which we write the solution values to
119! the 'Documentation file' on unit 10.
120!
121 Use proginfop
122 IMPLICIT NONE
123 INTEGER, Intent(IN) :: n, m
124 INTEGER, Intent(IN), Dimension(N) :: xbas, xsta
125 INTEGER, Intent(IN), Dimension(M) :: ybas, ysta
126 real*8, Intent(IN), Dimension(N) :: xval, xmar
127 real*8, Intent(IN), Dimension(M) :: yval, ymar
128 real*8, Intent(IN OUT) :: usrmem(*)
129
130 Integer :: i
131 CHARACTER*5, Parameter, Dimension(4) :: basc = (/ 'Lower','Upper','Basic','Super' /)
132 CHARACTER*6, Parameter, Dimension(4) :: stat = (/ 'Normal','NonOpt','Infeas','Unbnd ' /)
133
134 WRITE(10,"(/' Variable Solution value Reduced cost Var-Basc Var-stat')")
135 DO i = 1, n
136 WRITE(10,"(1P,I7,E20.6,E16.6,4X,A5,7X,A6 )") i, xval(i), xmar(i), basc(1+xbas(i)), stat(1+xsta(i))
137 ENDDO
138
139 WRITE(10,"(/' Constrnt Activity level Marginal cost Con-Basc Con-stat')")
140 DO i = 1, m
141 WRITE(10,"(1P,I7,E20.6,E16.6,4X,A5,7X,A6 )") i, yval(i), ymar(i), basc(1+ybas(i)), stat(1+ysta(i))
142 ENDDO
143#if defined (wei)
144 Call flush(10)
145#endif
146
147 solcalls = solcalls + 1
148 std_solution = 0
149
150END Function std_solution
151
152Integer Function std_message( SMSG, DMSG, NMSG, LLEN, USRMEM, MSGV )
153#if defined(itl)
154!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_Message
155#endif
156!
157! Simple implementation in which we only write the 'Screen file'
158! to unit *, the 'Status file' to unit 11, and the 'Documentation file'
159! to unit 10.
160!
161 Use proginfop
162 IMPLICIT NONE
163
164 INTEGER, Intent(IN) :: smsg, dmsg, nmsg
165 INTEGER, Intent(IN) , Dimension(*) :: llen
166 CHARACTER(len=133), Intent(IN), Dimension(*) :: msgv
167 real*8, Intent(IN OUT) :: usrmem(*)
168
169 Integer :: i
170!
171! write to screen
172!
173 do i = 1, smsg
174 write(*,"(A)") msgv(i)(1:llen(i))
175 enddo
176!
177! write to status file
178!
179 do i = 1, nmsg
180 write(11,"(A)") msgv(i)(1:llen(i))
181 enddo
182!
183! write to document file
184!
185 do i = 1, dmsg
186 write(10,"(A)") msgv(i)(1:llen(i))
187 enddo
188#if defined (wei)
189 Call flush(10)
190 Call flush(11)
191#endif
192
193 std_message = 0
194
195END Function std_message
196
197Integer Function std_errmsg( ROWNO, COLNO, POSNO, MSGLEN, USRMEM, MSG )
198#if defined(itl)
199!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_ErrMsg
200#endif
201!
202! Simple implementation of ErrMsg in which we just write 'Variable XX',
203! 'Equation YY' or 'Variable XX appearing in Equation YY' followed by
204! the text. We write both to the 'Documentation file' on unit 10 and
205! to the 'Status File' on unit 11.
206!
207 Use proginfop
208 IMPLICIT NONE
209
210 INTEGER, Intent(IN) :: rowno, colno, posno, msglen
211 CHARACTER(Len=*), Intent(IN) :: msg
212 real*8, Intent(IN OUT) :: usrmem(*)
213!
214! If Rowno = 0 then the message is about a Column.
215! If Colno = 0 then the message is abuut a Row.
216! Otherwise, the message is about (Rowno,Colno)
217!
218 IF ( rowno .EQ. 0 ) THEN ! Must be a column (error) message
219 WRITE(10,1001) colno, msg(1:msglen)
220 WRITE(11,1001) colno, msg(1:msglen)
221 ELSEIF ( colno .EQ. 0 ) THEN ! Must be a row (error) message
222 WRITE(10,1002) rowno, msg(1:msglen)
223 WRITE(11,1002) rowno, msg(1:msglen)
224 ELSE ! Must be a (row,col) (error) message
225 WRITE(10,1000) colno, rowno, msg(1:msglen)
226 WRITE(11,1000) colno, rowno, msg(1:msglen)
227 ENDIF
228#if defined (wei)
229 Call flush(10)
230 Call flush(11)
231#endif
2321001 FORMAT('Variable',i8,' : ',a)
2331002 FORMAT('Equation',i8,' : ',a)
2341000 FORMAT('Variable',i8,' appearing in Equation',i8,' : ',a)
235
236 std_errmsg = 0
237
238END Function std_errmsg
239
240Integer Function std_triord( Mode, Type, Status, Irow, Icol, Inf, Value, Resid, Usrmem )
241#if defined(itl)
242!DEC$ ATTRIBUTES STDCALL, REFERENCE, NOMIXED_STR_LEN_ARG :: Std_TriOrd
243#endif
244!
245! Simple implementation of the TriOrd callback routine.
246!
247 Implicit NONE
248 INTEGER, INTENT(IN) :: mode, Type, status, irow, icol, inf
249 real*8, INTENT(IN) :: VALUE, resid
250 real*8, Intent(IN OUT) :: usrmem(*)
251
252 Integer, Parameter :: pretriangular = 1, & ! Fix a structural variable from an equality equation
253 fixedcolumn = 2, & ! Fix a structural variable from equal lower and upper bouunds
254 dependentrow = 3, & ! All structural variables are fixed and the row is feasible
255 redundantrow = 4, & ! The row is feasible due to bounds on all variables.
256 impliedlower = 5, & ! Change a simple inequality to a lower bound
257 impliedupper = 6, & ! Change a simple inequality to an upper bound
258 forcedlower = 7, & ! A variable is forced to the lower bound by a ForcingLower or
259 ! ForcingUpper constraint.
260 forcedupper = 8, & ! A variable is forced to the upper bound by a ForcingLower or
261 ! ForcingUpper constraint.
262 forcinglower = 9, & ! A constraint is forcing all variables in it to a bound
263 ! and it works as an =L= constraint.
264 forcingupper = 10, & ! A constraint is forcing all variables in it to a bound
265 ! and it works as an =G= constraint.
266!
267! Any of the next actions will terminate the pre-processor and there can therefore only be one of them
268! and only in an infeasible model.
269!
270 pretriainfeasb = 11, & ! An equation has only one nonfixed variable, but it cannot
271 ! be solved either because the variable will exceed a bound.
272 pretriainfeasp = 12, & ! An equation has only one nonfixed variable, but it cannot
273 ! be solved either because the pivot (derivative) is too small.
274 forcinginfeas = 13, & ! A constraint is infeasible due to bounds on all variables
275 inconsistentrow = 14 ! All structural variables are fixed and the row in infeasible
276 ! or the row is feasible due to bounds on all variables.
277
278! write(10,*) 'TriOrd: Mode=',mode,' Type=',Type,' Status=',Status,' Irow=',Irow,' Icol=',Icol,' Inf=',Inf,' Value=',Value,' Resid=',Resid
279 If ( mode == -1 ) THEN
280 write(10,"(/'The preprocessing transformation are described below in detection order:'/)")
281 Else if ( mode == -2 ) Then
282 write(10,"(//'The order of the critical transformations is:'/)")
283 Endif
284 Select case (type)
285 Case (pretriangular)
286 If ( inf == 0 ) Then
287 WRITE(10,"('Equation',i7,' solved with respect to variable',i7,'. Value=',1p,e18.10)") irow, icol, value
288 Elseif ( inf == 1 ) Then
289 WRITE(10,"('Equation',i7,' solved with respect to variable',i7,'. Value=',9x,'+Infinity')") irow, icol
290 Else
291 WRITE(10,"('Equation',i7,' solved with respect to variable',i7,'. Value=',9x,'-Infinity')") irow, icol
292 Endif
293 Case (fixedcolumn)
294 WRITE(10,"('Variable',i7,' fixed at value=',1p,e18.10)") icol, value
295 Case (dependentrow)
296 WRITE(10,"('Equation',i7,' is dependent (all variables are fixed.)')") irow
297 Case (redundantrow)
298 WRITE(10,"('Equation',i7,' is redundant (will later be solved with respect to the slack.)')") irow
299 Case (impliedlower)
300 WRITE(10,"('Equation',i7,' turned into lower bound on variable',i7,'. Bound=',1p,e18.10)") irow, icol, value
301 Case (impliedupper)
302 WRITE(10,"('Equation',i7,' turned into upper bound on variable',i7,'. Bound=',1p,e18.10)") irow, icol, value
303 Case (forcedlower)
304 WRITE(10,"('Variable',i7,' forced to lower bound=',1p,e18.10)") icol, value
305 Case (forcedupper)
306 WRITE(10,"('Variable',i7,' forced to upper bound=',1p,e18.10)") icol, value
307 Case (forcinglower)
308 WRITE(10,"('Previous variables were forced by equation',i7,' binding as a less than or equal constraint.')") irow
309 Case (forcingupper)
310 WRITE(10,"('Previous variables were forced by equation',i7,' binding as a greater than or equal constraint.')") irow
311 Case (pretriainfeasb)
312 WRITE(10,"('Equation',i7,' cannot be solved with respect to variable',i7,' due to bounds. Value=',1p,e18.10)") &
313 irow, icol, value
314 Case (pretriainfeasp)
315 WRITE(10, &
316 "('Equation',i7,' cannot be solved with respect to variable',i7,'. Infeasibility has local minimum at',1p,e18.10)") &
317 irow, icol, value
318 Case (forcinginfeas)
319 WRITE(10,"('Equation',i7,' is still infeasible after the above variables have been moved to the best bounds.')") irow
320 Case (inconsistentrow)
321 WRITE(10,"('Equation',i7,' cannot be solved. No free variables left.')") irow
322 Case Default
323 WRITE(10,"('Pretriangular action=',i7,' not implemented yet.')") type
324 stop 1
325 End Select
326 If ( resid /= 0.d0 ) write(10,"('Residual after last transformation=',1p,e18.10)") resid
327#if defined (wei)
328 Call flush(10)
329#endif
330
331 std_triord = 0
332
333End Function std_triord
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
integer function std_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
Definition comdecl.f90:203
integer function std_triord(mode, type, status, irow, icol, inf, value, resid, usrmem)
Definition comdecl.f90:291
integer function std_errmsg(rowno, colno, posno, msglen, usrmem, msg)
Definition comdecl.f90:248
subroutine flog(msg, code)
Definition comdeclp.f90:42
integer miter
Definition comdeclp.f90:16
character(len=128) progname
Definition comdeclp.f90:9
logical nameread
Definition comdeclp.f90:10
real *8 obj
Definition comdeclp.f90:13
logical debug
Definition comdeclp.f90:17
subroutine startup
Definition comdeclp.f90:25