JijModeling

raw JSON →
2.4.1 verified Sat May 09 auth: no python

JijModeling is a Python library for mathematical modeling of optimization problems, with a focus on combinatorial optimization. It provides an intuitive API to define decision variables, constraints, and objective functions, and interfaces with solvers like JijZept. Current version 2.4.1, requires Python >=3.11, <4. Released regularly.

pip install jijmodeling
error ModuleNotFoundError: No module named 'jijmodeling'
cause jijmodeling is not installed or installed in wrong environment.
fix
Run pip install jijmodeling in the correct Python environment (Python >=3.11).
error AttributeError: module 'jijmodeling' has no attribute 'Model'
cause In version 2.x, `Model` was renamed to `Problem`.
fix
Use jm.Problem instead of jm.Model.
error JijModelingError: Cannot use operator '>' with Expression objects
cause Using Python comparison operators like `>` outside of Constraint definition.
fix
Wrap comparisons in jm.Constraint('name', expr) or use jm.Constraint(expr).
breaking In version 2.0+, the API changed significantly. The old `jijmodeling` standalone model definition (e.g., `jm.Model`) is replaced by `jm.Problem`. Code from v1.x must be rewritten.
fix Migrate from `jm.Model` to `jm.Problem`. Use `jm.BinaryVar` instead of `jm.Binary`. Check migration guide.
gotcha Variable indexing returns a placeholder, not the actual value. You cannot compare variables directly using Python comparison operators; use `==`, `<=`, `>=` only within constraints or objective expressions.
fix Always use `jm.Constraint` for comparisons. Do not use `if x[0] == 1:` in code logic.
deprecated The `jm.pw` (piecewise linear) function is deprecated in 2.4.0+. Use `jm.Problem.add_piecewise` or custom linearization.
fix Replace `jm.pw(...)` with `problem.add_piecewise(...)` or reformulate.

Define a simple binary optimization problem with variables, objective, and constraint.

import jijmodeling as jm

# Define variables
x = jm.BinaryVar('x', shape=(3,))
y = jm.BinaryVar('y', shape=(3,))

# Set problem
problem = jm.Problem('simple')
problem += x[0] + x[1] + x[2]
problem += jm.Constraint('c1', x[0] + y[0] == 1)

# Solve (requires JijZept token)
token = os.environ.get('JIJZEPT_TOKEN', '')
if token:
    import jijzept as jz
    sampler = jz.JijSASampler(token)
    result = sampler.sample(problem)
    print(result)
else:
    print('No JIJZEPT_TOKEN set. Problem defined:', problem)