MIT Supply Chain Python Package
Project description
SCx
MIT's Supply Chain Micromaster (SCx) Python Package
Documentation
Technical documentation can be found here.
Examples
Setup
Cloud Setup (Google Colab)
- You can access google colab here
- Create a new notebook
- Install the
scx
package by adding the following to a new code cell at the top of your notebook and running it:pip install scx
Local Setup
Make sure you have Python 3.7.x (or higher) installed on your system. You can download it here.
Recommended (but Optional) -> Expand this section to setup and activate a virtual environment.
- Install (or upgrade) virtualenv:
python3 -m pip install --upgrade virtualenv
- Create your virtualenv named
venv
:
python3 -m virtualenv venv
- Activate your virtual environment
- On Unix (Mac or Linux):
source venv/bin/activate
- On Windows:
venv\scripts\activate
pip install scx
Optimization Getting Started
See all of the optimization examples here.
Basic Usage
from scx.optimize import Model
Simple Optimization
from scx.optimize import Model
# Create variables
product_1_amt = Model.variable(name="product_1", lowBound=0)
product_2_amt = Model.variable(name="product_2", lowBound=0)
# Initialize the model
my_model = Model(name="Generic_Problem", sense='maximize')
# Add the Objective Fn
my_model.add_objective(
fn = (product_1_amt*1)+(product_2_amt*1)
)
# Add Constraints
my_model.add_constraint(
name = 'input_1_constraint',
fn = product_1_amt*1+product_2_amt*2 <= 100
)
my_model.add_constraint(
name = 'input_2_constraint',
fn = product_1_amt*3+product_2_amt*1 <= 200
)
# Solve the model
my_model.solve(get_duals=True, get_slacks=True)
# Show the outputs
# NOTE: outputs can be fetched directly as a dictionary with `my_model.get_outputs()`
my_model.show_outputs()
Outputs:
{'duals': {'input_1_constraint': 0.4, 'input_2_constraint': 0.2},
'objective': 80.0,
'slacks': {'input_1_constraint': -0.0, 'input_2_constraint': -0.0},
'status': 'Optimal',
'variables': {'product_1': 60.0, 'product_2': 20.0}}
Database Getting Started
See all of the database examples here
Basic Usage
from scx.database import Database
# Specify the S3 path to the data
data_folder = 's3://scx-dev/databases/supermarket/'
# Create the database
db = Database(f"""
CREATE TABLE Customers AS SELECT * FROM read_parquet('{data_folder}customers.parquet');
""")
# Show the database Schema
db.show_info()
# Query the database
db.query("SELECT * FROM Customers LIMIT 5")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
scx-1.2.0.tar.gz
(9.4 kB
view details)
Built Distribution
scx-1.2.0-py3-none-any.whl
(8.9 kB
view details)
File details
Details for the file scx-1.2.0.tar.gz
.
File metadata
- Download URL: scx-1.2.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7277e0bed805bfcd6a12f1125415721f9ef23d76dbbddcc0dc4085f05d6fa44 |
|
MD5 | e4cd0288ed839491697ee26b03bfeee9 |
|
BLAKE2b-256 | 53bfd8100016bd7e98c1c046fca9f8bdbf4ddad01e3b6e78aca7f260e7184154 |
File details
Details for the file scx-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: scx-1.2.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 226a83fafe1b761bb10884b48d56abacb5517269047f15502f922f3c0f546142 |
|
MD5 | e29aa4259c4821da1dca6c9e92ca1da4 |
|
BLAKE2b-256 | 63b4d7684bb2e647f023baeb24ded36f9d63ba03bdd9f282eaaf534e150102d9 |