reuelrds / NaiveLPPSolver

A Python Program to solve Linear Programming Problems.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Solving Linear Programming Problems in Python

(The naive way)

1. Setup the Environment

This assumes that you already have python installed.
The Program was tested using Python 3.9.1 installed using Anaconda Distrubution.

If you are using Anaconda Distrubution

  • Create the environment and install the requirements
conda create --name lpp_env --file requirements.txt
  • Activate the Enviroment
conda activate lpp_env

If you are using python virtual environment

Basically, please make sure that all the dependencies are installed before running the main.py file.

  • Create a Virtualenv
python3 -m venv env_name
  • Activate the env
.\env_name\Scripts\activate
  • Install the Dependencies
pip install -r requirements.txt

Note: If pip install fails for some reason (e.g. Due to not having proper build tools to install numpy, matplotlib, etc), you can also run:

easy_install numpy scipy matplotlib tabulate

The virtual environment has the script easy_install.exe in ./env_name/Scripts which can be used to install the required packages packages


2. To run the program run the command in the terminal

python main.py -i input_filename

eg:

python main.py -i input.txt

When a plot is displayed, Please close the plot window to proceed the next problem.


Changing the inputs to the program

All the input problems are stored in a text file which we pass to the main.py when we run the program.

Rules for the input text file

  • A line beginning with a # is treated as a comment and will be ignored.

  • Leave a single blank line between two LPPs.

  • The variables can be anything. eg: x_1 and x_2, x1 and x2, a and b, or x and y, etc.

  • Please leave no space between the coefficient and the variable. Anything after a number will be treated as a variable.
    eg:
    5x_1: coefficient 5 , variable x_1
    5x1: coefficient 5 , variable x1

  • Please use the signs >=, <= or = for the constraints.
    Do not use unicode symbols like, ≥ or ≤, because the program won't parse these symbols.

  • Example Format of LPP:

      Maximize: z = 5x_1 + 4x_2
      Subject to:
          6x_1 + 4x_2 <= 24
          x_1 + 2x_2 <= 6
          -x_1 + x_2 <= 1
          x_2 <= 2
          x_1 >= 0
          x_2 >= 0
    

Note: The program can also handle LPPs with three or more variables. A sample input file input.txt is included with a three variable LPP at the end.

About

A Python Program to solve Linear Programming Problems.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%