Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utcsri!rpi!news.ans.net!europa.asd.contel.com!uunet!decwrl!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: while & break statements in J (example using simplex algorithm)
Message-ID: <1992Jul31.005436.29955@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1992Jul29.010314.29840@csus.edu>
Distribution: NA
Date: Fri, 31 Jul 1992 00:54:36 GMT
Lines: 46

 I wrote the following routine including the while and
 the break I wanted, but the structure of this program 
 could be cleaned up.  Any tips on how? Or could someone
 point me in the right direction?

   smpx
+---------------------------------------------------------+-++
| a =. y.                                                 |:||
| loop)                                                   | ||
| c =. '' $ 0 > , <./ obj =. (_1}. {. a ) , 0             | ||
| $.=.(c#next),end                                        | ||
|next)                                                    | ||
| bvc =. </\ (<./ obj ) = obj                             | ||
| d   =. , }. (_1{."1 a) % factors =.,bvc#"1 a            | ||
| bvr =. 0 , </\ ( <./ (0 < d) # d) = d                   | ||
| $.=.((-. *./ bvr)#cont),infes                           | ||
| infes) a =. ($y.) $ 0                                   | ||
| $.=. end                                                | ||
| cont)                                                   | ||
| factors =. factors % pivot=.'' $ bvc# , bvr#"2 a        | ||
| factors =. ((<: % ]) pivot ) (bvr# i. $ bvr) } factors  | ||
| a =. a -  |: ($ |: a)  $ , (, bvr#"2 a ) *"(0 1) factors| ||
| $.=. loop                                               | ||
| end) y. =. a                                            | ||
+---------------------------------------------------------+-++
   a
_1 _2 _3 _5 0 0 0  0
 4  3  2  4 1 0 0 10
10  2  6  8 0 1 0 20
20  1  5  5 0 0 1 30
   smpx a
 5  2.5 0  1  1.5 0 0  15
 2  1.5 1  2  0.5 0 0   5
_2   _7 0 _4   _3 1 0 _10
10 _6.5 0 _5 _2.5 0 1   5
   

By the way what does this function do?  For the matrix a
it finds the values x0, x1, x2, x3, and z where:

 z = maximum of (x0 + 2*x1 + 3*x2 +5*x3)
 subject to the constraints : 
   4*x0 + 3*x1 + 2*x2 + 4*x4 <=10
  10*x0 + 2*x1 + 6*x3 + 8*x4 <=20
  20*x0 +  *x1 + 5*x3 + 5*x4 <=30

