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