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.0.tar.gz (5.8 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.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wallin-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 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.0.tar.gz
Algorithm Hash digest
SHA256 3ac4acbe8e704a40334c19c8f26c23b2318c2b29b3ae2d6ac87a5e66703ff2b2
MD5 27fea6b5d04e3a581cc92bfb1fc96db9
BLAKE2b-256 6a1c57bdaa4439af59b108cb55cb0122bed7c35855ada85d6c78673a08ea3391

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wallin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c12c64b8d2941bc2f342a19a369f98517d14699ab1a78d1f91541e424f0cd108
MD5 810b2dc49bb74215248b3347dd48668b
BLAKE2b-256 d98cd8484999a7dd0844f8495f4f9561338d7cca31e0cfaa82cd02a6cfe62c8e

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