P2CLPFD

Open-source procurement allocation optimizer · GPLv3

You have parts to buy and suppliers to buy them from. P2CLPFD returns the single cost-optimal award that satisfies every one of your sourcing rules — and the argument for it, in a buyer's language.

What P2CLPFD does

Supplier allocation is the problem of deciding how much of each part each supplier should win. Some suppliers are cheap but too small. Some want a volume commitment before they discount. Some cannot go beyond 500 units. You need two sources on the safety-critical parts, and nobody should hold more than 40% of the spend.

Give P2CLPFD your demand, your supplier quotes and your business rules as a single CSV, and it returns the award with the lowest total cost of ownership that breaks none of them. No heuristics and no approximations: the result is mathematically guaranteed to be the best legal split, and the solver can prove that no cheaper one exists.

Why a defensible award matters more than a fast one

Finding the cheapest legal award is the easy part — a purpose-built solver will do it faster. The hard part comes after, when the award is contested by the suppliers who lost, by the stakeholder who wanted their incumbent, by legal, or by an auditor a year later.

P2CLPFD is built for that second part. Every constraint is a declarative rule you write down rather than a formula you assemble, so what you signed off on is what ran. The tracer replays the decision rule by rule — before capacity, supplier2 could take anything between 0 and 250 units; after the MOQ and the share floor, only 75 to 150 remain — so when someone asks why supplier2 could not have more, you can show them the exact rule that closed the door. And the judgment layer reads the result back: whether the data was fit to decide on, whether one supplier just took 76% of your spend, which constraint is the one worth a phone call.

The trade is plain. Speed is where P2CLPFD loses. "Prove it and explain it to a human" is where it wins — which is the right trade only for decisions that get questioned.

How the optimum is found

P2CLPFD is built on CLP(FD) — constraint logic programming over finite domains. Think of a Sudoku solver: it does not try every combination, it uses the constraints to eliminate impossible values until the answer remains. P2CLPFD does the same with procurement rules, propagating them to strike out impossible quantities and then searching what is left for the lowest-TCO award. A heuristic finds a good split; constraint solving finds the best one.

The rules it enforces

RuleExample
Demandpart1 needs 250 units in total
Capacitysupplier2 can only make 150 of part1
MOQsupplier2 won't take an order below 75 units
Share boundssupplier2 must hold 30–70% of part1
Volume discountsupplier1 charges $100 under 40 units, $40 above
Fixed costsupplier1 needs $2,000 of tooling if awarded
Dual-sourcepart1 must come from at least 2 suppliers
Supply base cappart2 from at most 2 suppliers
Global shareno supplier above 40% of total volume
Qualitysupplier2 carries a +3 logistics penalty per unit

Where it is used

  • Automotive: thousands of part numbers across dozens of suppliers, dual-sourcing on safety-critical parts, discount tiers, and a cap on any one supplier's share of spend.
  • Pharmaceuticals: active ingredients across qualified manufacturers, quality scores folded into the effective unit cost, at least two sources per API.
  • Electronics: components sourced across regions with different logistics costs, tiered pricing, and a minimum number of suppliers on critical parts.
  • Construction and CAPEX: line items with several bidders each, mobilization charges, and a manageable supply base per category.
  • Beyond procurement: the engine is domain-agnostic — production split across factories, marketing spend across channels, staffing across shifts.

Getting started

P2CLPFD is free and open source under the GPLv3, installs from PyPI as p2clpfd, and runs on your own machine — your quotes never leave it. It also speaks the Model Context Protocol, so you can put the solver behind the AI agent you already use and ask for an award in plain language.

The full documentation, the constraint reference, the benchmarks and the source live in the P2CLPFD repository on GitHub.


P2CLPFD is built and maintained by Ahmed K. Hafsi. For a commercial conversation, a pilot, or a sourcing dataset to test it on, use the contact page.