Skip to main content

MIP-Tool

MIP-Tool is a package for Python-MIP.

Installation

pip install mip-tool

Example

Show/View model

from mip import Model, maximize
from mip_tool import show_model

m = Model()
x = m.add_var("x")
y = m.add_var("y")
m.objective = maximize(x + y)
m += x + 2 * y <= 16
m += 3 * x + y <= 18
show_model(m)

Output

\Problem name: 

Minimize
OBJROW: - x - y
Subject To
constr(0):  x + 2 y <= 16
constr(1):  3 x + y <= 18
Bounds
End

In Jupyter

from mip_tool.view import view_model

view_model(m)

Output

モデル
変数x :非負変数
y :非負変数
目的関数x + y → 最大化
制約条件x + 2.0y ≦ 16.0
3.0x + y ≦ 18.0

Non-convex piecewise linear constraint

Maximize y which is on points of (-2, 6), (-1, 7), (2, -2), (4, 5).

import numpy as np
from mip import INF, Model, OptimizationStatus
from mip_tool import add_lines, show_model

m = Model(solver_name="CBC")
x = m.add_var("x", lb=-INF)
y = m.add_var("y", obj=-1)
curve = np.array([[-2, 6], [-1, 7], [2, -2], [4, 5]])
add_lines(m, curve, x, y)
m.verbose = 0
m.optimize()
assert m.status == OptimizationStatus.OPTIMAL
assert (x.x, y.x) == (-1, 7)
show_model(m)

Output

\Problem name: 

Minimize
OBJROW: - y
Subject To
constr(0):  x - w_0 - w_1 - w_2 = -2
constr(1):  y - w_0 + 3 w_1 -3.50000 w_2 = 6
constr(2):  - w_0 + z_0 <= -0
constr(3):  w_0 <= 1
constr(4):  - w_1 + 3 z_1 <= -0
constr(5):  w_1 -3 z_0 <= -0
constr(6):  w_2 -2 z_1 <= -0
Bounds
 x Free
 0 <= z_0 <= 1
 0 <= z_1 <= 1
Integers
z_0 z_1 
End

F example

Easy to understand using F.

attention: Change Model and Var when using mip_tool.func.

from mip_tool.func import F

m = Model(solver_name="CBC")
x = m.add_var("x")
y = m.add_var("y", obj=-1)
m += y <= F([[0, 2], [1, 3], [2, 2]], x)
m.verbose = 0
m.optimize()
print(x.x, y.x)  # 1.0 3.0
  • y <= F(curve, x) and y >= F(curve, x) call add_lines_conv.
  • y == F(curve, x) calls add_lines.

pandas.DataFrame example

attention: Change Series when using mip_tool.func.

import pandas as pd
from mip import Model, maximize, xsum
from mip_tool.func import addvars

A = pd.DataFrame([[1, 2], [3, 1]])
b = pd.Series([16, 18])
m = Model(solver_name="CBC")
x = addvars(m, A, "X", False)
m.objective = maximize(xsum(x))
m += A @ x <= b
m.verbose = 0
m.optimize()
print(x.astype(float))  # [4. 6.]

Expression m += A.T.apply(lambda row: xsum(row * x)) <= b may be faster than m += A @ x <= b.

Metadata

Release files for mip-tool 0.6.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mip-tool 0.6.4
File Interpreter ABI Platform
mip_tool-0.6.4-py3-none-any.whl Python 3 none any Details

Release files / mip_tool-0.6.4-py3-none-any.whl

Download URL mip_tool-0.6.4-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46ba8305aab80c73a339b84aea6da533a7f3a62171133c02ea203d440491a456
BLAKE2b-256 checksum
How to use checksums
799e3a42c00dd5a466cf5e295fe8fac413611796e2db1ad67e269435d426634d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.6.4 This release

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

2 release files

0.2.0

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page