Skip to main content

Gloop

License: MIT PyPI version Github Documentation

Generalized Linear Object Oriented Programming (GLOOP) as a simple pythonic interface for OOP access to PULP. It features simple objects, helpful methods, and additional error checking that simplifies code and streamlines development.

Gloop also happens to be synonymous with the word "pulp" in the English language.

Why use Gloop?

  • Simple: Gloop is simple and easy to use.
  • Object Oriented: Gloop is object oriented by design.
  • Error Checking: Gloop has additional error checking to help you catch mistakes early.
    • This includes checking for duplicate names, invalid constraints, passed types, and more.
  • Intuitive: Gloop is intuitive
  • Unique: Gloops is unique in nature and can help you think differently about how you code for linear programming.

Setup

pip install gloop

Getting Started

gloop is a package designed for object oriented linear programming access to pulp. Technical docs can be found here.

Bare Bones Example

import gloop

# Create a variable
my_variable = gloop.Variable(name='my_variable_name', lowBound=0)

# Create a model
my_model = gloop.Model(name="my_model_name", sense="maximize")
# Add an objective for the model
my_model.add_objective(fn=my_variable)
# Add a constraint to the model
my_model.add_constraint(name="my_constraint_name", fn=my_variable <= 5)

# Solve the model
my_model.solve()

# Get the results
# my_model.show_outputs()
#=> {'status': 'Optimal', 'objective': 5.0, 'variables': {'my_variable_name': 5.0}}

Example

Transportation Problem

A product is manufactured in two assembly plants and sold in three regions. Monthly demand per region is shared in Table 1. Currently, assembly plants have no capacity restrictions and can source as many items as needed. Transportation costs (USD)0.12 per unit per mile.

Table 1: Demand in units

Demand Region 1 Region 2 Region 3
Units per month 2500 4350 3296

Table 2: Distance in Miles

Miles Region 1 Region 2 Region 3
Assembly Plant 1 105 256 108
Assembly Plant 2 240 136 198

Formulate a model using the available information. Your goal is to minimize the total transportation cost.

# Transportation Problem
import gloop


################### DATA ######################
# Transportation data
transport = [
    {"origin_name": "A1", "destination_name": "R1", "distance": 105},
    {"origin_name": "A1", "destination_name": "R2", "distance": 256},
    {"origin_name": "A1", "destination_name": "R3", "distance": 108},
    {"origin_name": "A2", "destination_name": "R1", "distance": 240},
    {"origin_name": "A2", "destination_name": "R2", "distance": 136},
    {"origin_name": "A2", "destination_name": "R3", "distance": 198},
]

# Loop through the transport data to create variables and calculate cost
for t in transport:
    # Create decision variables for each item in transport
    t["amt"] = gloop.Variable(
        name=f"{t['origin_name']}__{t['destination_name']}__amt", lowBound=0
    )
    # Calculate the variable cost of shipping for each item in tranport
    t["cost"] = t["distance"] * 0.12


# Demand data
demand = [
    {"name": "R1", "demand": 2500},
    {"name": "R2", "demand": 4350},
    {"name": "R3", "demand": 3296},
]


################### Model #####################
# Initialize the model
my_model = gloop.Model(name="transportation_example", sense="minimize")


# Add the Objective Fn
my_model.add_objective(fn=gloop.Sum([t["amt"] * t["cost"] for t in transport]))

# Add Constraints
## Demand Constraint
for d in demand:
    my_model.add_constraint(
        name=f"{d['name']}__demand",
        fn=gloop.Sum(
            [t["amt"] for t in transport if t["destination_name"] == d["name"]]
        )
        >= d["demand"],
    )

# Solve the model
my_model.solve()

################### OUTPUT #####################

# Show the outputs
# my_model.show_outputs() #=>
# {'objective': 145208.16,
#  'status': 'Optimal',
#  'variables': {'A1__R1__amt': 2500.0,
#                'A1__R2__amt': 0.0,
#                'A1__R3__amt': 3296.0,
#                'A2__R1__amt': 0.0,
#                'A2__R2__amt': 4350.0,
#                'A2__R3__amt': 0.0}}

Metadata

Release files for gloop 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gloop 1.0.1
File Size Uploaded
gloop-1.0.1.tar.gz 14.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gloop 1.0.1
File Interpreter ABI Platform
gloop-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / gloop-1.0.1.tar.gz

Download URL gloop-1.0.1.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
997f8fa719a2ab17bae6a692c40ba71efe2f7bbda80714f2f1d44d16446ab2f0
BLAKE2b-256 checksum
How to use checksums
3549664c430fa1cb47f06f7676e38d400d5c8efbb58b15143599fb290e8b9d3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / gloop-1.0.1-py3-none-any.whl

Download URL gloop-1.0.1-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a16d9514503c01a6640b9f3a8040e53cdcda200f499212dce9fb341a0053d6d
BLAKE2b-256 checksum
How to use checksums
8b217acf150150ced2de6ce799703cb830440d6639399e24da9197f7827aea2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page