Transportation problem: Difference between revisions

m
→‎{{header|REXX}}: fixed courtesy GS
m (centered the two HTML tables.)
m (→‎{{header|REXX}}: fixed courtesy GS)
Line 3,910:
 
=={{header|REXX}}==
 
{{improve|REXX| <br> Please use a Classic REXX such as Regina and re-run this program. <br><br>}}
&nbsp;
&nbsp;
Regina REXX (when invoked with no arguments, yields: <br><br>
125 +++ Do i=1 To numSources
7 +++ Call init
Error 41 running "c:\walter.1", line 125: Bad arithmetic conversion
Error 41.1: Non-numeric value ("") to left of arithmetic operation "unknown"
&nbsp;
&nbsp;
R4 REXX yields:
Invalid operator character sequence
Error detected at line 86 offset 10
Source line:
cost+=m.r.c*costx.r.c
^
&nbsp;
&nbsp;
There are several more messages of the (above) type.
&nbsp;
&nbsp;
Perhaps a display of the input file would help, or at least state the contents
of the input file are the same as shown for the programming solution for the
XXX language.
&nbsp;
&nbsp;
PC/REXX yields:
125 +++ Do i=1 To numSources
7 +++ Call init
Error 41 on line 125 of C:\WALTER.2: Bad arithmetic conversion
&nbsp;
&nbsp;
After supplying an input file, Regina REXX issues the errors:
'WORDSORT' is not recognized as an internal or external command,
operable program or batch file.
119 +++ Return word(list,2)-word(list,1)
21 +++ dr.r=diff(dr.r)
Error 41 running "c:\walter.1", line 119: Bad arithmetic conversion
&nbsp;
&nbsp;
Also, it would be helpful to have a local constant alternative to 'input.txt', so it could be run on tio and similar.
&nbsp;
&nbsp;
 
<lang rexx>/* REXX ***************************************************************
* Solve the Transportation Problem using Vogel's Approximation
Default Input
2 3 # of sources / # of demands
25 35 sources
20 30 10 demands
3 5 7 cost ^matrix
3 2 5
* 20201210 support no input file -courtesy GS
* Note: correctness of input is not checked
**********************************************************************/
Parse Arg fid
Line 4,040 ⟶ 4,003:
If m.r.c>0 Then Do
ol=ol format(m.r.c,3)
cost+=cost+m.r.c*costx.r.c
End
Else
Line 4,076 ⟶ 4,039:
 
init:
If lines(fid)=0 Then Do
parse Value linein(fid) With numSources numDestinations 1 rr cc
Do i=1 To 5
l=linein(fid)
in.i=sourceline(i+3)
End
End
Else Do
Do i=1 By 1 while lines(fid)>0
l in.i=linein(fid)
End
End
parseParse ValueVar linein(fid) Within.1 numSources numDestinations . 1 rr cc .
source_sum=0
Do i=1 To numSources
Parse Var lin.2 source.i lin.2
ss.i=source.i
source_sum+=source_sum+source.i
End
l=linein(fid)
demand_sum=0
Do i=1 To numDestinations
Parse Var lin.3 demand.i lin.3
dd.i=demand.i
demand_sum+=demand_sum+demand.i
End
Do i=1 To numSources
j=i+3
l=linein(fid)
l=in.j
Do j=1 To numDestinations
Parse Var l cost.i.j l
Line 4,107 ⟶ 4,079:
When source_sum=demand_sum Then Nop /* balanced */
When source_sum>demand_sum Then Do /* unbalanced - add dummy demand */
cc+=cc+1
demand.cc=source_sum-demand_sum
dd.cc=demand.cc
Line 4,115 ⟶ 4,087:
End
Otherwise /* demand_sum>source_sum */ Do /* unbalanced - add dummy source */
rr+=rr+1
source.rr=demand_sum-source_sum
ss.rr=source.rr
2,289

edits