Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Linear programs in LaTeX?

630 views
Skip to first unread message

Gregory Glockner

unread,
May 25, 1994, 6:13:14 PM5/25/94
to

I'm sure many of you use LaTeX for your technical writing (or as Lamport
would say, TeXnical). In linear programming, I often want to write
something that looks like:

a x + ... + a x = b i e {1, ..., n} (13)
i1 1 in n i


q x + ... + q x = b i e {1, ..., n} (14)
i1 1 in n i

In other words, I want the elements in the matrix to align properly, I want
the equals signs to match up, and I want the right hand sides to align. I
also want the "for all" stuff to align properly, and I want the equations
to be numbered.

I have found that the "array" environment *almost* suits my needs, but not
quite. You can't (to my knowledge) get automatic equation numbering within
the array environment. If you use "eqnarray", the equal signs align, the
numbering works properly, but the equations themselves do not align on the
left sides, nor can you get the "for all" stuff to align easily.

Suggestions, anyone? Thanks in advance.

Gregory Glockner
Graduate Research Assistant gloc...@isye.gatech.edu
Logistics Optimization Center (404) 894-2366 (w)
School of ISyE, Georgia Inst. of Technology (404) 634-8855 (h)

Mr W.M. Prinz

unread,
May 26, 1994, 4:33:16 AM5/26/94
to

In article <2s0ihq$f...@news.gatech.edu>, gloc...@iesun6.gatech.edu (Gregory Glockner) writes:
|>
|> I'm sure many of you use LaTeX for your technical writing (or as Lamport
|> would say, TeXnical). In linear programming, I often want to write
|> something that looks like:
|>
|> a x + ... + a x = b i e {1, ..., n} (13)
|> i1 1 in n i
|>
|>
|> q x + ... + q x = b i e {1, ..., n} (14)
|> i1 1 in n i


To get this, you could use the following:


\documentstyle{article}
%
\newcommand{\eqnnum}{\refstepcounter{equation}\hfill(\theequation)}
%
\begin{document}
\[
\begin{array}{l@{\;+\:\ldots\:+\;}l@{\;=\;}l@{\hspace{1cm}}lp{3cm}}
a_{i1} x_1 & a_{in} x_n & b_i & i \in \{ 1, \ldots, n\} & \eqnnum \\
q_{i1} x_1 & q_{in} x_n & b_i & i \in \{ 1, \ldots, n\} & \eqnnum
\end{array}
\]
\end{document}


That is not fully satisfying, but seems to be elegant enough.
You might want to adjust the spacings.

Matthias Prinz
--

Matthias

derek holmes

unread,
May 26, 1994, 4:46:30 PM5/26/94
to
In article <2s0ihq$f...@news.gatech.edu> gloc...@iesun6.gatech.edu (Gregory Glockner) writes:
>
>I'm sure many of you use LaTeX for your technical writing (or as Lamport
>would say, TeXnical). In linear programming, I often want to write
>something that looks like:
>
<Stuff deleted>

If anyone is interested, I modified the LaTeX files to include a "formulation"
environment that has 4 columns instead of three. To use it, you have to, in
effect, recreate LaTeX.

Despite going to all of that trouble, I find the \begin{equation} \begin{array}
.. end{} \end{} trick to give slightly better results. Also, it's not that much harder.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Derek Holmes dho...@engin.umich.edu ++ 1205 Beal Ave., +++
+++ Ind. & Operations Eng., Univ. of Michigan ++ Ann Arbor, MI 48109-2117 +++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


thomas keyser

unread,
May 27, 1994, 11:17:08 AM5/27/94
to
I am looking for a Revised SImplex code written in C. Any help would sure
be of great assistance. Thanks in advance.

TK

---
Tom Keyser, Industrial Engineering Department
Clemson University - Office: Freeman 125
Phone: (803)-654-4718
Reply to any of the following: tke...@eng.clemson.edu
tke...@clemson.clemson.edu



Paul Rubin

unread,
May 27, 1994, 1:22:00 PM5/27/94
to
I pulled the following from a list of public domain C code posted here from
time to time. I'm not a C-user, so I have no personal experience with these.
Name : lpsolve
Where : volume02 of comp.sources.reviewed
Description : very good mixed integer linear program solver
Author : Michel Berkelaar (mic...@es.ele.tue.nl)
Comments : Its core is a sparse matrix dual simplex LP solver. MILP
problems are solved with a branch-and-bound iteration over LP
solutions. It uses a lex+yacc parser to read a human-friendly
algebraic input format. The author has used the program to
solve LP problems up to about 30000 variables and 50000
constraints (on a 22 MFLOPS HP9000/750).
Name : weisfeld-simplex.shar (7457 bytes)
Where : pub/C-numanal on usc.edu
Description : small implementation of simplex method for linear programming.
Author : Matt Weisfeld (not on Internet)
Version : Feb 1993
Comments : associated with article in Feb 1993 CUJ.
For production use (where you want a black-box solver),
the `lpsolve' package (above) is better. If you want to
open up a simplex implementation and modify it, then this is
quite good, using the article as documentation.

**************************************************************************
* Paul A. Rubin Phone: (517) 336-3509 *
* Department of Management Fax: (517) 336-1111 *
* Eli Broad Graduate School of Management Net: RU...@MSU.EDU *
* Michigan State University *
* East Lansing, MI 48824-1122 (USA) *
**************************************************************************

Bob Bowerman

unread,
May 27, 1994, 3:20:55 PM5/27/94
to
In article 15...@cc.ic.ac.uk, mpr...@ms.ic.ac.uk (Mr W.M. Prinz) writes:
>
>In article <2s0ihq$f...@news.gatech.edu>, gloc...@iesun6.gatech.edu (Gregory Glockner) writes:
>|>
>|> I'm sure many of you use LaTeX for your technical writing (or as Lamport
>|> would say, TeXnical). In linear programming, I often want to write
>|> something that looks like:
>|>
>|> a x + ... + a x = b i e {1, ..., n} (13)
>|> i1 1 in n i
>|>
>|>
>|> q x + ... + q x = b i e {1, ..., n} (14)
>|> i1 1 in n i

Another solution is a little style file that I wrote called optprog.sty
which create the optprog and optprog* environments for defining optimization
problems (subject to my own personal layout preferences). To use it, place
optprog.sty and specify it as an optional argument. Here is a little sample
for using it.
--
\documentstyle[optprog]{article}

\begin{document}
Here is an example of its usage on a LP:
\begin{optprog}
\optaction[x_i]{Maximize} & \objective{Z = \sum_{j=1}^n c_j x_j} \label{obj}\\
subject to & \sum_{j=1}^n a_{ij} x_j & \leq & b_i & i=1\ldots{}m \label{cons1} \\
and & x_i & \geq & 0 & j=1\ldots{}n \label{cons2}
\end{optprog}
\end{document}
--

And here is the style file:
-- Cut here and save as optprog.sty
% optprog.sty
% <14 Apr 93> Bob Bowerman (bowe...@dial.uwaterloo.ca)
%
% This file defines the optprog environment and is just a hacked up
% version of the eqnarray environment designed for use with optimization
% problems. Instead of just 3 columns optprog lays out 7 columns set up as
% follows: rrcllll. The overall environment is set in displaystyle with
% the first column being defined as normal text. The first column is
% intended for text associated with the specification of the optimization
% program such as `Minimize' or `subject to'. The second, third, and fourth
% columns are intended for the lhs, operator, and rhs of the constraints.
% The fifth, sixth, and seventh columns are intended for defining the range
% for the indices of the constraints. The columns are centred between the
% left and right margins and both the objective function and the
% constraints are numbered.
%
% As well several utility macros are defined.
% \objective{#1} Typesets the objective function. Left
% aligns the objective function over the last 6 columns.
% \optaction[#2]{#1} Sets #2 in mathmode underneath #1 which is shown in
% text, e.g. \optarg[x_i]{Mimimize} puts $x_i$ directly underneath Minimize
%
% The optprog* environment is defined which does not include
% equation numbers. As well, \nonumber suppresses the equation number for
% a single line.
%
% Here is an example of its usage on a LP:
% \begin{optprog}
% \optaction[x_i]{Maximize} & \objective{Z = \sum_{j=1}^n c_j x_j} \label{obj}\\
% subject to & \sum_{j=1}^n a_{ij} x_j & \leq & b_i & i=1\ldots{}m \label{cons1} \\
% and & x_i & \geq & 0 & j=1\ldots{}n \label{cons2}
% \end{optprog}

\immediate\write\sixt@@n{Optprog Environment defined <14 Apr 93>}

\chardef\f@ur=4
\chardef\f@ve=5
\chardef\s@x=6

\def\@optprog{\stepcounter{equation}\let\@currentlabel\theequation
\global\@eqnswtrue\m@th
\global\@eqcnt\z@\tabskip\@centering\let\\\@prbspcr
$$\halign to\displaywidth\bgroup
\hfil\hskip\@centering \hbox{\tabskip\z@{##}}&
\global\@eqcnt\@ne\hskip 2\arraycolsep \hfill\hskip\@centering $\displaystyle\tabskip\z@{##}$&
\global\@eqcnt\tw@\hskip \arraycolsep \hfill${##}$\hfill&
\global\@eqcnt\thr@@\hskip \arraycolsep
$\displaystyle\tabskip\z@{##}$&
\global\@eqcnt\f@ur\hskip 2\arraycolsep
$\displaystyle\tabskip\z@{##}$&
\global\@eqcnt\f@ve\hskip 2\arraycolsep
$\displaystyle\tabskip\z@{##}$&
\global\@eqcnt\s@x\hskip 2\arraycolsep
$\displaystyle\tabskip\z@{##}$\hfil\tabskip\@centering&
\llap{##}\tabskip\z@\cr}

\def\endoptprog{\@@prbspcr\egroup
\global\advance\c@equation\m@ne$$\global\@ignoretrue}

\def\objective#1{\multispan{6} \global\@eqcnt\s@x\hskip \arraycolsep
$\displaystyle\tabskip\z@{#1}$\hfil\tabskip\@centering}

\def\optaction[#1]#2{\mbox{$\displaystyle\mathrel{\mathop{\hbox{#2}}\limits_{\textstyle#1}}$}}

\def\@prbspcr{{\ifnum0=`}\fi\@ifstar{\global\@eqpen\@M
\@yprbspcr}{\global\@eqpen\interdisplaylinepenalty \@yprbspcr}}

\def\@yprbspcr{\@ifnextchar [{\@xprbspcr}{\@xprbspcr[\z@]}}

\def\@xprbspcr[#1]{\ifnum0=`{\fi}\@@prbspcr
\noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}

\def\@@prbspcr{\let\@tempa\relax
\ifcase\@eqcnt \def\@tempa{& & & & & &}\or \def\@tempa{& & & & & &}
\or \def\@tempa{& & & & &} \or \def\@tempa{& & & &}
\or \def\@tempa{& & &} \or \def\@tempa{& &}
\else \def\@tempa{&}\fi
\@tempa \if@eqnsw\@eqnnum\stepcounter{equation}\fi
\global\@eqnswtrue\global\@eqcnt\z@\cr}

% Here's the optprog* environment:

\let\@sprbspcr=\@prbspcr
\@namedef{optprog*}{\def\@prbspcr{\nonumber\@sprbspcr}\optprog}
\@namedef{endoptprog*}{\nonumber\endoptprog}

\def\optprog{\@ifnextchar [{\@optprog1}{\@optprog}}
-- Cut here

I hope people find this of use.

Cheers,
Bob
--
Bob Bowerman
Department of Systems Design Engineering | Phone: (519)885-1211 x5194
University of Waterloo | Fax: (519)746-4791
Waterloo, ON N2L 3G1 | Email: bowe...@dial.uwaterloo.ca

,.;. squirrels: a source of campus nutrition
|\__/| .~ ~.
/o=o'`./ .' recipe for squirrel au vin:
{o__, \ { ingredients:
/ . . ) \ 1 squirrel (remove hair)
`-` '-' \ } 1 bottle of Andres Baby Duck
.( _( )_.' to prepare:
:. '---.~_ _ _| Get really drunk, eat the squirrel.


0 new messages