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 math: SUM, COUNT, AVG, ratios, SUMPRODUCT, scaling, cross-column constraints
  • Row-level logic: Conditions like Region = "West" or Profit / Cost > 1.5
  • Per-row math: Addition, subtraction, multiplication, division, scaling
  • SETVALUE support: Target-based objectives with optional tolerance
  • GROUPSUM() 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:

  1. A Pandas DataFrame (typically from Excel)
  2. 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


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.3.tar.gz (6.6 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.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for wallin-1.0.3.tar.gz
Algorithm Hash digest
SHA256 f5953de11db9feaed1add87a2ef2cd5b64471bea8f73ff672456dda33a6d44d6
MD5 00405a088196e260abb8cbacd0b02dab
BLAKE2b-256 990ab7fa411c0a2debce82826e9bc48e5b8247bb247864fb8cbd8e8fec017b92

See more details on using hashes here.

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

Hashes for wallin-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 22c68d2789c9739e783ff94fd1a38a6873cc965c2eb7dff2d45f1ac59a2db0bd
MD5 0a805dcebc8347670b20a7d45a7254f5
BLAKE2b-256 7b181ccd02a2c9b4e02be050f722441e92173f4867f1c5835837f37942cff7a2

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