Skip to main content

A package that solves Linear Programs using pytorch

Project description

deeplp

PyPI version License: MIT

deeplp is a Python package for solving linear programming problems using deep learning techniques. It leverages PyTorch for its backend computations and provides a simple API for defining problems and training models.

Features

  • Define linear programming problems with a simple API.
  • Train deep learning models to solve LPs.
  • Built-in support for plotting results and saving models.
  • A command-line interface (CLI) for running experiments.
  • Available on PyPI for easy installation.

Requirements

deeplp requires:

  • Python 3.10+
  • PyTorch (with GPU support if desired)

Installing PyTorch

Visit the PyTorch website for installation instructions. For example, to install PyTorch with CUDA 11.3 support on Windows:

pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118

For CPU-only support, run:

pip install torch torchvision torchaudio

Installation

You can install deeplp either from PyPI or directly from GitHub.

Installing from PyPI

pip install deeplp

Installing from GitHub

pip install git+https://github.com/yourusername/deeplp.git

Basic Usage

Example 1: Solving a Simple LP

from deeplp import train, createProblem

# Define your problem data:
c = [1.0, 2.0]  # Objective coefficients
A = [[3, -5], [3, -1], [3, 1], [3, 4], [1, 3]]  # Constraint matrix
b = [15, 21, 27, 45, 30]  # Right-hand side values
tspan = (0.0, 10.0)  # Time span

# Create the problem (if no name is provided, a name is generated automatically)
problem = createProblem(
    c,
    A,
    b,
    tspan,
    name="Custom Example 1",
    b_testing_points=[[15, 21, 27, 45, 30], [15, 12, 20, 25, 50]],
    c_testing_points=[[2, 5], [12, 20]],
)

# Train the model
sols = train(
    batches=1,
    batch_size=32,
    epochs=100,
    problem=problem,
    problems_ids=[],
    cases=[1, 2, 3],
    do_plot=True,
    model_type="pinn",
)

Example 2: Solving an LP with Equality Constraints

from deeplp import train, createProblem

# Define your problem data:
c = [1.0, 2.0, -1.0, -2.0, 0, 0, 0, 0, 0]  # Objective coefficients
A = [
    [3, -5, -3, 5, 1, 0, 0, 0, 0],
    [3, -1, -3, 1, 0, 1, 0, 0, 0],
    [3, 1, -3, -1, 0, 0, 1, 0, 0],
    [3, 4, -3, -4, 0, 0, 0, 1, 0],
    [1, 3, -1, -3, 0, 0, 0, 0, 1],
]  # Constraint matrix
b = [15, 21, 27, 45, 30]  # Right-hand side values
tspan = (0.0, 10.0)  # Time span

# Create the problem
problem = createProblem(
    c,
    A,
    b,
    tspan,
    name="Custom Example 2 (Equality)",
    b_testing_points=[[15, 21, 27, 45, 30], [15, 12, 20, 25, 50]],
    c_testing_points=[c],
)

# Train the model
sols = train(
    batches=1,
    batch_size=32,
    epochs=100,
    problem=problem,
    problems_ids=[],
    cases=[3],
    do_plot=True,
    model_type="rnn",
)

Running the CLI

After installing the package, you can run:

deeplp --batches 1 --batch_size 128 --iterations 1000 --case 1 --example 1 --do_plot --folder saved_models

For other options, type

python deeplp --help

This command starts training with the specified options using the RNN model for case 3, example 2, with 2 iterations, 2 batches, and a batch size of 1.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deeplp-0.7.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deeplp-0.7.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file deeplp-0.7.1.tar.gz.

File metadata

  • Download URL: deeplp-0.7.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for deeplp-0.7.1.tar.gz
Algorithm Hash digest
SHA256 6513131f632965b24702bbf54139104d33caa227086af1acb9afda701b0512fe
MD5 0925d54231434af795f9f64e467cc93f
BLAKE2b-256 b50f906daac99680c3db5b8fd218be9e24571fcb36ec90c7f1504d59442dfb3e

See more details on using hashes here.

File details

Details for the file deeplp-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: deeplp-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Windows/11

File hashes

Hashes for deeplp-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9038b328f6bd2396496d13c9f71c883db285722f4ed6076f96ff711d883bbf58
MD5 4a211ccb4454de72d0294f876f2c2c79
BLAKE2b-256 2c87e8c26216cf6c5d360a888b0deac67bc10becc1bb2d757b5a22ba44316476

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page