Constraint-based Excel optimizer powered by OR-Tools
Project description
Wallin
Wallin is a simple, expressive optimization library that lets you define constraints and objectives in plain English. It’s designed for business analysts, accountants, and operations pros who want to solve real-world allocation problems without having to learn an optimization language.
Built on top of Google OR-Tools, Wallin turns your Excel data and rule logic into a solvable optimization model.
Features
- Plain English syntax: Write rules like
SUM(Cost) <= 1000orLocation = "NY" - Aggregate math: SUM, COUNT, AVG, ratios, SUMPRODUCT, scaling, cross-column constraints
- Row-level logic: Conditions like
Region = "West"orProfit / Cost > 1.5 - Per-row math: Addition, subtraction, multiplication, division, scaling
SETVALUEsupport: Target-based objectives with optional toleranceGROUPSUM()support: Enables ratio-based constraints across selected rows- Handles negative numbers and quoted column names
- Minimal setup: Just define rules and call
solve(df, rules)
Installation
Install from PyPI:
pip install wallin
How It Works
You provide:
- A Pandas DataFrame (typically from Excel)
- A block of plain English rules
Wallin returns the same DataFrame with a Selected column showing which rows were chosen.
Example
import pandas as pd
import wallin as wl
df = pd.read_excel("Transaction Detail.xlsx")
RULES = """
MAXIMIZE: SUM(Profit)
CONSTRAINT: COGS/Profit < 0.06
CONSTRAINT: SUMPRODUCT(COGS, Profit) <= 60000
CONSTRAINT: Location = "NC"
"""
result = wl.solve(df, RULES)
selected = result[result["Selected"]]
selected.to_excel("selected_rows.xlsx", index=False)
Supported Syntax
Objectives
MAXIMIZE: SUM(Profit)
MINIMIZE: COUNT(*)
SETVALUE: SUM(Amount) = 100
TOLERANCE: 1.5 # optional, works with SETVALUE
Aggregate Constraints
CONSTRAINT: SUM(Cost) <= 1000
CONSTRAINT: COUNT(*) = 5
CONSTRAINT: AVG(Score) > 3.5
CONSTRAINT: SUM(COGS) + SUM(Fees) <= 2000
CONSTRAINT: 2 * SUM(Value) / 3 >= 50
CONSTRAINT: SUM(COGS) / SUM(Profit) <= 0.2
CONSTRAINT: SUM(COGS * Profit) <= 30000
CONSTRAINT: SUMPRODUCT(COGS, Profit) <= 30000
Row-Level Math
CONSTRAINT: Profit / Cost >= 1.5
CONSTRAINT: Score + Bonus >= 10
CONSTRAINT: 3 * Cost / 2 <= 500
CONSTRAINT: COGS * Profit < 2000
Filters and Conditions
CONSTRAINT: Region = "West"
CONSTRAINT: Profit >= 50
CONSTRAINT: Type = "Hardware"
GROUPSUM() Constraints
CONSTRAINT: Amount / GROUPSUM(Amount) <= 0.3
CONSTRAINT: Ending / GROUPSUM(Ending) = Beginning / GROUPSUM(Beginning)
CONSTRAINT: Sales / GROUPSUM(Sales WHERE Category = "Books") <= 0.4
GROUPSUM(col)computes the sum of a column over selected rows (optionally filtered). This enables proportional, fairness, and relational constraints.
Output
Wallin appends a boolean Selected column to the DataFrame.
result[result["Selected"]]
This shows the rows the optimizer picked based on your objective and constraints.
License
MIT License — free for commercial and non-commercial use.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wallin-1.0.3.tar.gz.
File metadata
- Download URL: wallin-1.0.3.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5953de11db9feaed1add87a2ef2cd5b64471bea8f73ff672456dda33a6d44d6
|
|
| MD5 |
00405a088196e260abb8cbacd0b02dab
|
|
| BLAKE2b-256 |
990ab7fa411c0a2debce82826e9bc48e5b8247bb247864fb8cbd8e8fec017b92
|
File details
Details for the file wallin-1.0.3-py3-none-any.whl.
File metadata
- Download URL: wallin-1.0.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22c68d2789c9739e783ff94fd1a38a6873cc965c2eb7dff2d45f1ac59a2db0bd
|
|
| MD5 |
0a805dcebc8347670b20a7d45a7254f5
|
|
| BLAKE2b-256 |
7b181ccd02a2c9b4e02be050f722441e92173f4867f1c5835837f37942cff7a2
|