Skip to main content

Generalized Linear Object Oriented Programming (GLOOP)

Project description

Gloop

PyPI version License: MIT

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

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

Setup

pip install gloop

Getting Started

gloop is a package designed for object oriented linear programming access to pulp. Technical Docs Here.

Basic 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}}

Application Example

Blinky

After years of work, your friend Robert, and you launched the brand Blink. Blink's business includes assembling, selling, and distributing a smart pet wearable device, the Blinky22. This device has multiple functions; it monitors pet activity levels, tracks health indicators, provides wellness recommendations, records veterinarian visits, tracks location, and shares this all in real-time through a mobile app. Blinky22 is waterproof and light-weight. The collar is adjustable so that any pet can wear it.

Blinky is manufactured in two assembly plants and it is 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. Blink’s 3PL carrier charges a transportation cost of (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.

# Blink
import gloop


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

# Loop through the transport data to create variable 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']*t['cost_per_mile']


# 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}}

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

gloop-1.0.0b2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

gloop-1.0.0b2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file gloop-1.0.0b2.tar.gz.

File metadata

  • Download URL: gloop-1.0.0b2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gloop-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 dcb0f481d2ef45a89c94c76987f01c51cab6ccc057a762af46300a128252bc4e
MD5 abd5695438ae95349792641fb9f1506b
BLAKE2b-256 02631efaa8872294076985171c54cd02321e6d7b44ec8ecade3ede6e4e0ef992

See more details on using hashes here.

File details

Details for the file gloop-1.0.0b2-py3-none-any.whl.

File metadata

  • Download URL: gloop-1.0.0b2-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gloop-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ed4668a852da116727cd6b99e8a05a395f4666a16b98b22487cb434dfd0d39a
MD5 b0dd0ba8f5a2d7e72486dbf50d579754
BLAKE2b-256 32b42b8282b93a1781b7b6e3a13facf44e33e5320bc6b012c7b640005acb4e27

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