lp_solve command

The lp_solve program is a command line application that can use as good as all functionality of the library.

Installation

There is no installation procedure for this application. There is no need for it. You only need one file: lp_solve.exe under Windows or lp_solve under Unix/Linux. It can be found in the archive lp_solve_5.5.2.0_exe.zip (Windows) or lp_solve_5.5.2.0_exe.tar.gz (Unix/Linux). Just extract the file and you can use it. Note for Windows users, that you can not just run the lp_solve program by double clicking on it from Windows Explorer. The program needs arguments and this is best done from the command line (cmd.exe / command.com) or via batch files. lp_solve has many options as shown further.

Usage

This program reads the MIP model from standard input or from a file and outputs the result back to the console or to a file. There are several possible input formats: The 'lp' format (See lp-format), and the 'mps' format (See mps-format) are build in, but other formats are also supported via the XLI functionality (See external language interface). For example a MathProg interface is developed via the XLI functionality (See external language interface for an example). These input formats have nothing to do with the API. So lp1 = make_lp(0,4) is a totally wrong input for the lp_solve program. The lp format is the default. Optionaly you can use the -lp option for it. To enable the mps format, use the -mps option. To enable the XLI, use the -rxli option. If lp_solve is started without an input file, then it gives a blinking cursor and waits for input. It is then possible to enter the model in the specified format (lp by default). But this is not very handy. You must enter the whole model each time you want to solve it and must be careful that you don't type any errors. To stop input mode, press Ctrl Z.
However it is much better to write your model in a disk file with your favourite editor (make sure it is in text format) and then provide this file to lp_solve. For example:

lp_solve input.lp

It is also possible to use input redirection:

lp_solve <input.lp

Or more sophisticated constructs like:

gen_model | lp_solve

gen_model is here a user written program that outputs the model to standard output and via the pipe character (|) this output is redirected to lp_solve. So no intermediate file is needed in this case.

Examples:

lp_solve input.lp

lp_solve -s input.lp

lp_solve -s input.lp >output.txt

lp_solve -s -mps input.mps >output.txt

lp_solve -s -S4 -mps input.mps >output.txt

lp_solve -s -S4 -mps input.mps -wpar par.ini -wparopt "-HMyPar" >output.txt

A list of all options is given by entering the following command:

lp_solve -h

This gives:

Usage of lp_solve version 5.5.2.0:
lp_solve [options] [[<]input_file]
List of options:
-h              prints this message
-lp             read from LP file (default) See read_LP, See lp-format
-mps            read from MPS file, default in fixed format See read_MPS, See mps-format
-mps_free		use free format See read_MPS, See mps-format
-mps_ibm		interprete integers accoring to ibm format See read_MPS, See mps-format
-mps_negobjconst	negate objective constant See read_MPS, See mps-format
-fmps           read from MPS file in free format See read_freeMPS, See mps-format
-rpar filename  read parameters from filename. See read_params
-rparopt options
                options for parameter file:
                 -H headername: header name for parameters. By default 'Default'
-rxli xliname filename
                read file with xli library See external language interface
-rxlidata datafilename
                data file name for xli library. See external language interface
-rxliopt options
                options for xli library. See external language interface
-rbas filename  read basis from filename. See read_basis, See mps bas file format
-gbas filename	guess basis with variables from filename. See guess_basis
-plp		print model. See print_lp
-wlp filename   write to LP file See write_lp, See lp-format
-wmps filename  write to MPS file in fixed format See write_mps, See mps-format
-wfmps filename write to MPS file in free format See write_freemps, See mps-format
-wxli xliname filename
                write file with xli library See external language interface
-wxliopt options
                options for xli library. See external language interface
-wxlisol xliname filename
                write solution file with xli library See external language interface
-wxlisolopt options
                options for xli library. See external language interface
-wbas filename  write basis to filename. See write_basis, See mps bas file format
-wpar filename  write parameters to filename. See write_params
-wparopt options
                options for parameter file:
                 -H headername: header name for parameters. By default 'Default'
-wafter         Write model after solve (useful if presolve used).
-parse_only     parse input file but do not solve
-nonames        Ignore variables and constraint names See set_use_names
-norownames     Ignore constraint names See set_use_names
-nocolnames     Ignore variable names See set_use_names

-min            Minimize the lp problem (overrules setting in file) See set_minim
-max            Maximize the lp problem (overrules setting in file) See set_maxim
-r <value>      specify max nbr of pivots between a re-inversion of the matrix See set_maxpivot
-piv <rule>     specify simplex pivot rule See set_pivoting
         -piv0: Select first
         -piv1: Select according to Dantzig
         -piv2: Select Devex pricing from Paula Harris (default)
         -piv3: Select steepest edge
These pivot rules can be combined with any of the following:
-pivf           In case of Steepest Edge, fall back to DEVEX in primal. See set_pivoting
-pivm           Multiple pricing. See set_pivoting
-piva           Temporarily use First Index if cycling is detected.  See set_pivoting
-pivr           Adds a small randomization effect to the selected pricer. See set_pivoting
-pivll          Scan entering/leaving columns left rather than right. See set_pivoting
-pivla          Scan entering/leaving columns alternatingly left/right. See set_pivoting
-pivh           Use Harris' primal pivot logic rather than the default. See set_pivoting
-pivt           Use true norms for Devex and Steepest Edge initializations. See set_pivoting
-o0             Don't put objective in basis. See set_obj_in_basis
-o1             Put objective in basis (default). See set_obj_in_basis
-s <mode> <scaleloop>   use automatic problem scaling. See set_scaling
         -s0: No scaling
         -s1: Geometric scaling (default)
         -s2: Curtis-reid scaling
         -s3: Scale to convergence using largest absolute value
          -s:
         -s4: Numerical range-based scaling
         -s5: Scale to convergence using logarithmic mean of all values
         -s6: Scale based on the simple numerical range
         -s7: Scale quadratic
These scaling rules can be combined with any of the following:
-sp             also do power scaling. See set_scaling
-si             also do Integer scaling (default). See set_scaling
-se             also do equilibration to scale to the -1..1 range (default). See set_scaling
-presolve       presolve problem before start optimizing (rows+columns) See set_presolve
-presolverow    presolve problem before start optimizing (rows only) See set_presolve
-presolvecol    presolve problem before start optimizing (columns only) See set_presolve
-presolvel      also eliminate linearly dependent rows See set_presolve
-presolves      also convert constraints to SOSes (only SOS1 handled) See set_presolve
-presolver      If the phase 1 solution process finds that a constraint is
                redundant then this constraint is deleted See set_presolve
-presolvek      Simplification of knapsack-type constraints through
                addition of an extra variable, which also helps bound the OF See set_presolve
-presolveq      Direct substitution of one variable in 2-element equality
                constraints; this requires changes to the constraint matrix See set_presolve
-presolvem	Merge rows See set_presolve
-presolvefd	COLFIXDUAL See set_presolve
-presolvebnd	Presolve bounds See set_presolve
-presolved	Presolve duals See set_presolve
-presolvef      Identify implied free variables (releasing their expl. bounds) See set_presolve
-presolveslk	IMPLIEDSLK See set_presolve
-presolveg      Reduce (tighten) coef. in integer models based on GCD argument See set_presolve
-presolveb      Attempt to fix binary variables at one of their bounds See set_presolve
-presolvec      Attempt to reduce coefficients in binary models See set_presolve
-presolverowd   Idenfify and delete qualifying constraints that
                are dominated by others, also fixes variables at a bound See set_presolve
-presolvecold   Deletes variables (mainly binary), that are dominated
                by others (only one can be non-zero) See set_presolve
-C <mode>       basis crash mode See set_basiscrash
         -C0: No crash basis
         -C2: Most feasible basis
         -C3: Least degenerate basis
-prim           Prefer the primal simplex for both phases. See set_preferdual
-dual           Prefer the dual simplex for both phases. See set_preferdual
-simplexpp      Set Phase1 Primal, Phase2 Primal. See set_simplextype
-simplexdp      Set Phase1 Dual, Phase2 Primal. See set_simplextype
-simplexpd      Set Phase1 Primal, Phase2 Dual. See set_simplextype
-simplexdd      Set Phase1 Dual, Phase2 Dual. See set_simplextype
-degen          use perturbations to reduce degeneracy,
                can increase numerical instability See set_anti_degen
-degenc         use column check to reduce degeneracy See set_anti_degen
-degend         dynamic check to reduce degeneracy See set_anti_degen
-degenf         anti-degen fixedvars See set_anti_degen
-degens         anti-degen stalling See set_anti_degen
-degenn         anti-degen numfailure See set_anti_degen
-degenl         anti-degen lostfeas See set_anti_degen
-degeni         anti-degen infeasible See set_anti_degen
-degenb         anti-degen B&B See set_anti_degen
-degenr         anti-degen Perturbation of the working RHS at refactorization See set_anti_degen
-degenp         anti-degen Limit bound flips See set_anti_degen
-trej <Trej>    set minimum pivot value See set_epspivot
-epsd <epsd>    set minimum tolerance for reduced costs See set_epsd
-epsb <epsb>    set minimum tolerance for the RHS See set_epsb
-epsel <epsel>  set tolerance for rounding values to zero See set_epsel
-epsp <epsp>    set the value that is used as perturbation scalar for
                degenerative problems See set_epsperturb
-improve <level>        iterative improvement level See set_improve
         -improve0: none
         -improve1: Running accuracy measurement of solved equations on Bx=r
         -improve2: Improve initial dual feasibility by bound flips (default)
         -improve4: Low-cost accuracy monitoring in the dual
         -improve8: check for primal/dual feasibility at the node level
-timeout <sec>  Timeout after sec seconds when not solution found. See set_timeout
-bfp <filename> Set basis factorization package. See set_BFP

-noint          Ignore integer restrictions
-e <number>     specifies the tolerance which is used to determine whether a
                floating point number is in fact an integer.
                Should be < 0.5 See set_epsint
-g <number>
-ga <number>    specifies the absolute MIP gap for branch-and-bound. See set_mip_gap
                This specifies the absolute allowed tolerance
                on the object function. Can result in faster solving times.
-gr <number>    specifies the relative MIP gap for branch-and-bound. See set_mip_gap
                This specifies the relative allowed tolerance
                on the object function. Can result in faster solving times.
-f              specifies that branch-and-bound algorithm stops at first found
                solution See set_break_at_first
-b <bound>      specify a lower bound for the objective function See set_obj_bound
                to the program. If close enough, may speed up the
                calculations.
-o <value>      specifies that branch-and-bound algorithm stops when objective
                value is better than value See set_break_at_value
-c
-cc             during branch-and-bound, take the ceiling branch first See set_bb_floorfirst
-cf             during branch-and-bound, take the floor branch first See set_bb_floorfirst
-ca             during branch-and-bound, the algorithm chooses branch See set_bb_floorfirst
-depth <limit>  set branch-and-bound depth limit See set_bb_depthlimit
-n <solnr>      specify which solution number to return See set_solutionlimit
-B <rule>       specify branch-and-bound rule See set_bb_rule
         -B0: Select Lowest indexed non-integer column (default)
         -B1: Selection based on distance from the current bounds
         -B2: Selection based on the largest current bound
         -B3: Selection based on largest fractional value
         -B4: Simple, unweighted pseudo-cost of a variable
         -B5: This is an extended pseudo-costing strategy based on minimizing
              the number of integer infeasibilities
         -B6: This is an extended pseudo-costing strategy based on maximizing
              the normal pseudo-cost divided by the number of infeasibilities.
              Similar to (the reciprocal of) a cost/benefit ratio
These branch-and-bound rules can be combined with any of the following:
-Bw             WeightReverse branch-and-bound See set_bb_rule
-Bb             BranchReverse branch-and-bound See set_bb_rule
-Bg             Greedy branch-and-bound See set_bb_rule
-Bp             PseudoCost branch-and-bound See set_bb_rule
-BR             Extended PseudoCost branch-and-bound See set_bb_rule
-Bf             DepthFirst branch-and-bound See set_bb_rule
-Br             Randomize branch-and-bound See set_bb_rule
-BG             GubMode branch-and-bound See set_bb_rule
-Bd             Dynamic branch-and-bound See set_bb_rule
-Bs             RestartMode branch-and-bound See set_bb_rule
-BB             BreadthFirst branch-and-bound See set_bb_rule
-Bo             Order variables to improve branch-and-bound performance See set_bb_rule
-Bc             Do bound tightening during B&B based of reduced cost info See set_bb_rule
-Bi             Initialize pseudo-costs by strong branching See set_bb_rule

-time           Print CPU time to parse input and to calculate result. See time_elapsed
-v <level>      verbose mode, gives flow through the program. See set_verbose
                 if level not provided (-v) then -v4 (NORMAL) is taken.
         -v0: NEUTRAL
         -v1: CRITICAL
         -v2: SEVERE
         -v3: IMPORTANT (default)
         -v4: NORMAL
         -v5: DETAILED
         -v6: FULL
-t              trace pivot selection See set_trace
-d              debug mode, all intermediate results are printed,
                and the branch-and-bound decisions See set_debug
-R              report information while solving the model See put_msgfunc See get_working_objective
-Db <filename>  Do a generic readable data dump of key lp_solve model variables
                before solve. See print_debugdump
                Principally for run difference and debugging purposes
-Da <filename>  Do a generic readable data dump of key lp_solve model variables
                after solve. See print_debugdump
                Principally for run difference and debugging purposes
-i              print all intermediate valid solutions. See set_print_sol
                Can give you useful solutions even if the total run time
                is too long
-ia             print all intermediate (only non-zero values) valid solutions. See set_print_sol
                Can give you useful solutions even if the total run time
                is too long
-stat		Print model statistics
-S <detail>     Print solution. If detail omitted, then -S2 is used.
         -S0: Print nothing
         -S1: Only objective value See print_objective See get_objective
         -S2: Obj value+variables (default) See print_solution See get_variables, get_ptr_variables
         -S3: Obj value+variables+constraints See print_constraints See get_constraints
         -S4: Obj value+variables+constraints+duals
              See print_duals
              See get_sensitivity_rhs, get_ptr_sensitivity_rhs, get_dual_solution, get_ptr_dual_solution, get_var_dualresult,
              See get_sensitivity_obj, get_ptr_sensitivity_obj, get_sensitivity_objex, get_ptr_sensitivity_objex
         -S5: Obj value+variables+constraints+duals+lp model See print_lp
         -S6: Obj value+variables+constraints+duals+lp model+scales See print_scales
         -S7: Obj value+variables+constraints+duals+lp model+scales+lp tableau See print_tableau

A practical example

Enter the following in your favorite text editor (Windows users, don't use Word or Wordpad, that won't work. If you don't have an editor, use notepad).

max: 143 x + 60 y;

120 x + 210 y <= 15000;
110 x + 30 y <= 4000;
x + y <= 75;

Save this on your hard disk with name model.lp (don't forget in which directory/folder you save it).

Now enter the following:

lp_solve -S3 model.lp

This gives:

Value of objective function: 6315.63

Actual values of the variables:
x                          21.875
y                          53.125

Actual values of the constraints:
R1                        13781.2
R2                           4000
R3                             75

Note that this is the model presented in Formulation of an lp problem in lpsolve. The model is formulated in the lp format. See lp-format for a description of it.