Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

but there is no restriction on any coefficient.

We assume the
Linear Programming in APL variab]es are in the vector X and there are several vectors and
-by c. matrices to be provided.

INF,AR PROGRAMMING HAS A HISTORY OF MANY YEARS w i t h 1. The objective vector is C with C+. xX maximized
Danzig's Simplex algorithm providing the first genera] 2. The array F and vector G such that G>F+. aX
solution. It is this algorithm that is implemented here. 3. The array H and vector U such that U<_H+.xX
The simplest description of the aim of linear programming is 4. The array 2? and vector S such that S=T+. xX
that we wish to maximize a linear function ofn variables,
Now create the vector R

i=1
R=G,U,S,C,(pU),(pS) where the two p's are crucial,
even if zero, and the array (origin 0)
subject to a number ofconstxaints, typically of the form:
M=F,[O]H,[O]2 andnow
~ a~i <b Z~-R LP M
i=I

Since these problems originated in the worm ofeconomics, the Provided there/s a solution, the final value of the objective is
variables x i are assumed to be positive, while all the other con- printed and a long vector ofresuhs is returned.
stants are not limited. The inequalities may be either direction or
equalities, with no upper limit to the number (other than The desired vector X is:
practicality). Use of any package requires care as to maximizing ( pX ) t Z the remaining numbers are described later.
or minimizing the objective, and a ~equent constraint is that all
the right sides (bj) must also be positive, and/or all inequalities The value of zero for the algorithm is used in fines 10 and 11, the
are only one direction. value 100000 in line 5 is, essentially, ® used to get started inside
The simplest description of the Simplex algorithm is that the the convex shape.
constraints determine a convex shape bounded by hyperplanes,
and the objective must be maximized on the boundary, and thus V X~B LP A;OIO;V;C;S;B;G;I;W;Z;H;Q
at one of the vertices. The algorithm first gets inside that shape [1] aio~o o A~(-I*O>(tpA)tR)*[O]A o V~-2~R
[2] G*(((tpA)-+/V)tR,-V[O]t(-+/V),(tpA)tR
(which is not intuitively easy to do in many cases), then gets to a [3] H*(2p~pA)pO o (0 0 ~H)~aG*(G+G=O),((tpA)-pG)pl
vertex and searches n.eighbouring vertices, always increasing the [4] A*A,H*H,(+NG)$(+/G)t[1],['']G*O>G
[5] C~C-(-pC~(l~pA)t(tpA)*-2*R)t(Q~V[l]++/G)plO0000
objective as it goes. Allowances must be made for adjacent vertex [6] 2~~S~(-l~pA)t-l^.<H
sets having the same objective values. The solution is found [7] R~(toA)t[R
[8] L P : ~ ( O ^ . > X ~ B ~ S / A ) / E B R
when the objective can increase no further, subject to the obvious
[9] G*2k(Vi[/V)=tpV*T/C-((S/C)[]~B)+..A
caveat of being within fuzz limits. There is also no guarantee of [10] ~(O.O0001zF/V)/DONE
a unique solution (again because offlat spots). [11] ~(O.O0001^.zZ~(,G/A)~B)/UNB
[12] H~(W/X)÷(W*Z>IE-13)/Z
[13] ~~S*(S^~SkWk(HiL/H)=ipB)vG
There are three possible outcomes: [14] ~LP
[15] DONE:t(Ov.<(-Q)tX~SkX)/'''Ihere are no feasible
solutions" o ~0'
1. There is no solution, i.e., the convex body is empty. [15] 'Done',~C+.xX o ~0
[17] ERR:~O,pD~'Error'
2. The solution is unbounded, i.e., the objective has no upper [18] UNB:~O,pD~'Unbounded'
V
limit.
3. A solution is found. T h e algorithm is implemented by adding or subtracting a
non-negative "alack variable" to each inequality, thus turning all
Note that since this is a purely numeric algorithm (contrast this inequalities into equalities. T h e solution vector Z now contains
with small problems in "Maple"), all coefficients must be present pX solutions followed by the final value of ( t pM)- t p2 slack
even if zero. All variables are also assumed to he non-negative, 1 variables. The remaining numbers in Z are the added variables
that allow for starting inside the convex shape. These slack and
added variables are also put into the objective function, and the
added variables must all become non-positive if there is to be a
t Ifyou need negatives, introduce one new variable, say3, and then replace
feasible solution.
all the x i that can be negative with x i - 3 " T h e r e is one extra term ill the
objective - ~ ' c i summed over those c i for for which x i can be negative, and Those of you interested in economic studies can use the
do the appropriate subtraction when the solution is found. "slack" variables for various forms of"marginal analysis."

MAICHt996 -- VOLUME~6, NUMSER~ I I


This algorithm has been run on a number of random]y-
Advertising in Quote Quad
generated matrices and objectives, though all too often the F YOU HAVE A SMALL ADVERTISING BUDGET but sill] w a n t to let
solution is "not feasible," so various test cases have been,
perhaps, too simple. Under APL2 for OS/2 on a Penfium 90
system with 32MB of memory, we get:
I the APL community know about you and your business, you
may be interested in taking advantage of the "business card
ads" in APL Quote Quad. The purpose of this type of ad is to
allow a consultant or a sma]l business to announce their avail-
bl is 7 5 x 2 5 , r u n time 2.7 secs ability to the APL community, and to do it at a lower cost than
M is 2 2 0 x 3 5 , run time 14.3 sees was previous]), available. This is now our lowest-cost ad.
A business card ad would typically display the contents of a
Other tests, and comparisons with other packages have not standard business card (organizational name, persona] name,
been done with such large mamces, but the reliability should be activity, and contact information).., but, within the space you
high--no errors have yet appeared in any of the tests. If you really have, be creative! It is to be U. S. business card size: 2" high by
want large systems, this is not, perhaps, the package to be used 3~A'' wide.
(nor should Karmakar be compared). While the software is APL2 For more specific information on any type of advertising,
for OS/2, there are only a few places where fairly obvious please contact the SIGAPL Advertising Coordinator, Chuck
changes must be made for other APLs. • Kennedy, at 408-941-5920 or via "ckennedy@hooked.net". •

1L G. Selfridge can be reached at the Computer and Sciences


Department at the University of Florida uia e-maiL" "sel~d@
nervm, nerdm,ufL edu ':

SOLITON
ASSOCIATES
Your5of~,vare.SolutionsCompany
APL+WIN N o w Supporting W'mdows 95 Controls
in Windows 95, N T and Windows 3.1.
SHARP APt is superior in the rapid development of Same Workspace, Same Inlm'lxeter for
All Versions of Windows.
mission.critical applications which meet the ever- A ~ L ~ Your 32 Bit SQL / O D B C Connection.
changing demands of our customers. APL+UNIX New and Improved.
Includes Control Slmctures
APL+DOS Updated in 1996.
Soliton Associates provides SHARP APL for MVS and UNIX with: ConsulUng Solutions Mainframe & D O S to Windows
Application Design and Turnkey
• Superior productivity Development Sorviens.
• Powerful cooperative processing Out_Bourne Suppli~ for Legacy A P L
Servicns: Opm'atinn,Maintenance &
• Applications for end-users and programmers Incremental Development
• Responsive support services
Con~aut Pm~amminE

Soliton Associates Limited APL2000 Rapid Appli~atlon Developm~ra


2 Independence Way, SuBe 1017
44 VictoriaStreet, Suite 2100
Princeton, NJ 08540 USA
Toronto, Ontario, Canada MSC I Y2
Tel: (416) 364-9355 Fax: (416) 364-6159
TeL 609-734-9692
/n ,l~rape In fhe 13.5. Fax 609-734-9644
Graot Blankenbmg 53 951 President Street, #3F 1100University Avenue, Suite 111 Web: http:/Imembers.aoLcom/APL2000
1082 AC Amsterdam Brooklyn Rochesler Emil: APL2OOO@AOL, COM
The Netherlands Hew Yadt, USA '11215 New York, USA 14607
Tel: + 31-20-646-4475 Tel: (718) 783-9330 Tel: (716) 7.56-6466 Providing APL Solutions for Developers
or via Internet to: sales@soliton.com

12 A,L 0,o', ,od

You might also like