Seeker Quick Start

This page builds one complete model in seven small steps. Each step adds a few lines; the full model is at the end, ready to run in Colab. Expect ten minutes.

1. Install and create an environment

Seeker runs in Python. The free demo installs with pip and works in Google Colab, Jupyter or any Python 3.12/3.13 environment on Linux. It handles models with up to 50 variables and 20 constraints, which is plenty for learning and for every example on these pages. With a license, pass the license file to Env and the limits go away.

Every model lives in an environment. You create it first and end it when you are done.

%pip install -q seekerdemo "setuptools<81"
import seekerdemo as skr
env = skr.Env('')                 # '' = free demo; with a license: skr.Env('license.sio')

2. Bring your data

Data stays plain Python: lists, numbers, NumPy arrays, whatever you already have. Here a café decides how many croissants, muffins and bagels to bake. Each product has a price that drops a little with every extra unit sold, an ingredient cost, oven time and flour use.

products  = ["croissant", "muffin", "bagel"]
base      = [2.80, 2.20, 3.40]    # price when selling only a few (EUR)
slope     = [0.004, 0.003, 0.006] # price drops by this much per extra unit
unit_cost = [0.90, 0.70, 1.10]    # ingredients per unit (EUR)
minutes   = [2.0, 1.5, 3.0]       # oven minutes per unit
grams     = [60, 80, 110]         # flour per unit (g)

3. Add decision variables

Decision variables are the only things Seeker searches over. Create as few as possible, and pick the type that matches what the number means:

  • env.continuous(low, high) for any real number (a temperature, a share, a price)
  • env.ordinal(low, high) for whole numbers where 6 is close to 7 (quantities, start hours)
  • env.categorical(low, high) for labels where 2 is not close to 3 (which machine, which supplier)

Here: one ordinal per product, how many to bake.

qty = [env.ordinal(0, 400) for _ in products]

4. Derive terms from data and decisions

Everything else is a derived term: ordinary Python arithmetic on variables and data, plus Seeker functions such as env.sum, env.max or env.if_. Revenue, cost, profit and oven time are not variables. Seeker recomputes them automatically, and only the parts that change, whenever the search moves a variable. Nonlinear expressions like q * (base - slope * q) are fine.

revenue = env.sum([q * (base[i] - slope[i] * q) for i, q in enumerate(qty)])
cost    = env.sum([q * unit_cost[i] for i, q in enumerate(qty)])
profit  = revenue - cost
oven    = env.sum([q * minutes[i] for i, q in enumerate(qty)])
flour   = env.sum([q * grams[i] for i, q in enumerate(qty)])

5. Add constraints

Constraints are rules every solution must follow. Post them with env.enforce_leq, enforce_geq, enforce_eq and friends. Use them for real limits only: whenever a rule can be built into the choice of variables instead, do that (see the toolkit and templates). If Seeker cannot satisfy a constraint, it tells you which one.

env.enforce_leq(oven, 480)        # one oven, 8 hours
env.enforce_leq(flour, 25000)     # 25 kg of flour

6. Optimize

Call env.minimize(term, seconds) or env.maximize(term, seconds). The time limit is in seconds; Seeker returns the best value it found. If you know a bound that cannot be beaten, pass it as a third argument and Seeker stops as soon as it reaches it.

env.maximize(profit, 2)

7. Read the results

After solving, every variable and every derived term has a value: call .get_value(). End the environment when you are done.

for name, q in zip(products, qty):
    print(f"{name:10} {q.get_value():4.0f}")
print(f"profit EUR {profit.get_value():.2f}, oven {oven.get_value():.0f} min, "
      f"flour {flour.get_value():.0f} g")
env.end()

The complete model

All steps together. Copy it into a Colab cell, or download it as a notebook, and run it.

%pip install -q seekerdemo "setuptools<81"
import seekerdemo as skr

# Data: plain Python, no Seeker involved
products  = ["croissant", "muffin", "bagel"]
base      = [2.80, 2.20, 3.40]    # price when selling only a few (EUR)
slope     = [0.004, 0.003, 0.006] # price drops by this much per extra unit
unit_cost = [0.90, 0.70, 1.10]    # ingredients per unit (EUR)
minutes   = [2.0, 1.5, 3.0]       # oven minutes per unit
grams     = [60, 80, 110]         # flour per unit (g)

# 1. Create the environment
env = skr.Env('')                 # '' = free demo; with a license: skr.Env('license.sio')

# 2. Decision variables: how many of each product to bake
qty = [env.ordinal(0, 400) for _ in products]

# 3. Derived terms: computed from data and decisions, not variables
revenue = env.sum([q * (base[i] - slope[i] * q) for i, q in enumerate(qty)])
cost    = env.sum([q * unit_cost[i] for i, q in enumerate(qty)])
profit  = revenue - cost
oven    = env.sum([q * minutes[i] for i, q in enumerate(qty)])
flour   = env.sum([q * grams[i] for i, q in enumerate(qty)])

# 4. Constraints
env.enforce_leq(oven, 480)        # one oven, 8 hours
env.enforce_leq(flour, 25000)     # 25 kg of flour

# 5. Optimize: maximize profit, stop after 2 seconds
env.maximize(profit, 2)

# 6. Read the results
for name, q in zip(products, qty):
    print(f"{name:10} {q.get_value():4.0f}")
print(f"profit EUR {profit.get_value():.2f}, oven {oven.get_value():.0f} min, "
      f"flour {flour.get_value():.0f} g")
env.end()
croissant    93
muffin      104
bagel        46
profit EUR 358.76, oven 480 min, flour 18960 g

That plan is optimal: we checked it against every possible combination. Seeker stopped after the two seconds we allowed.

Where to go next

  • Change something and rerun. Raise the oven time, add a fourth product, or replace env.ordinal by env.continuous and see what happens.
  • Learn the building blocks. The Modeling toolkit lists every kind of variable, function and constraint, each with a small example.
  • Start from a template. The Templates cover assignment, grouping, scheduling, routing, selection, blending, pricing, uncertainty and simulation. Copy the closest one and replace the data block.
  • See what it is worth. The Examples compare Seeker models against how problems are solved today, and explain modeling principles in depth.