Skip to main content

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) <= 1000 or Location = "NY"
  • Aggregate constraints: SUM, COUNT, AVG, SUMPRODUCT, ratios, and scaled sums
  • Row-level logic: Filter rows with conditions like State = "CA" or Profit / Cost > 1.5
  • Support for SETVALUE objectives with tolerance
  • Per-row math: Ratios, addition, subtraction, multiplication
  • Robust scaling for decimal precision
  • No boilerplate: One function call to solve and return selected rows

Installation

Clone the repo locally or install with:

pip install wallin

How It Works

Wallin expects two inputs:

  1. A Pandas DataFrame (from Excel, CSV, etc.)
  2. A multi-line string of rules written in plain English

It returns the same DataFrame with a Selected column marking which rows were chosen by the optimizer.


Example

import pandas as pd
import wallin as wl

# Load your Excel file
df = pd.read_excel("Transaction Detail.xlsx")

# Define rules
RULES = """
MAXIMIZE: SUM(Profit)
CONSTRAINT: COGS/Profit < 0.06
CONSTRAINT: SUMPRODUCT(COGS, Profit) <= 60000
CONSTRAINT: Location = "NC"
"""

# Solve
result = wl.solve(df, RULES)

# Get selected rows
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, used 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

Row Filters (text/numbers)

CONSTRAINT: Region = "West"
CONSTRAINT: Profit >= 50 AND Profit <= 100
CONSTRAINT: State = "CA" OR State = "NY"

Output

The output DataFrame contains a Selected column marking which rows were chosen. You can filter it like this:

selected = result[result["Selected"]]

License

MIT License. Free to use, modify, and distribute.

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

wallin-1.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

wallin-1.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file wallin-1.0.2.tar.gz.

File metadata

  • Download URL: wallin-1.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for wallin-1.0.2.tar.gz
Algorithm Hash digest
SHA256 38e362dae0137288e735c6a5eed55276b022c967df2b517c46ad24b890efad9d
MD5 e7c8dd1522dac4e8377681475fa99714
BLAKE2b-256 aa3fd7b20f5083f78838dc57cea44864ae2064ed417f3f6c286c95efb44a200d

See more details on using hashes here.

File details

Details for the file wallin-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: wallin-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for wallin-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 03488cb6dce468ecd726836257c991a1662935e679f05369b4361d7481af7ef5
MD5 5ceac407e9dea27796fca7cb6a868d5c
BLAKE2b-256 1c9b23a1dd468942141ea72d761225e8f100273562e0308d301689626ff5af1e

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