Skip to main content

A mip model framework like gurobi, make write lp and mip easy, and support gurobi, cbc, highs solver.

Project description

Using gurobi syntax for MIP modeling

The syntax of gurobi is very traversal for mip modeling, but the syntax of some open-source solvers and their corresponding API interfaces often uses the conventional naming convention of Python, which is inconvenient for programming with complex constraints.

Therefore, I developed a Python library called gurobi2, which encapsulates commonly used objects such as variable sets, create constraints, constraint sets, and large M methods, and provides a programming experience consistent with gurobipy. I hope to improve the efficiency and experience of programming through this.

For specific API usage, please refer to the official documentation of Gurobi: https://www.gurobi.com/documentation/current/refman/index.html

Here is an example:

from msopt.api import Model, Param, INF, quicksum


m = Model("example", "CBC")

x = m.addVars([1,2,3], vtype="C", name="x")
y = m.addVars([1,2,3], vtype="B", name="y")
z = m.addVars([1,2,3], vtype="I", name="z")

m.addConstr(x.sum() == 1, name="c1")
m.addConstr(y.sum() >= 1, name="c2")
m.addConstr(z[1] == 1, name="c3")

objective = quicksum(x[i] for i in [1,2,3])
m.setObjective(objective, "maximize")

m.setParam(Param.TimeLimit, 10)
m.setParam(Param.MIPGap, 0.01)
m.optimize()

print("status: ", m.status)
print("Objective value: ", m.objVal)
print("x: ", x[1].x, x[2].x, x[3].x)
print("y: ", y[1].x, y[2].x, y[3].x)
print("z: ", z[1].x, z[2].x, z[3].x)

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

msopt-0.0.8.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

msopt-0.0.8-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file msopt-0.0.8.tar.gz.

File metadata

  • Download URL: msopt-0.0.8.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for msopt-0.0.8.tar.gz
Algorithm Hash digest
SHA256 ba4c4e8ca632bffe5e51d5914036344d51924f52e26a5cf7d2d34b7972e2aba8
MD5 6acbfa51684c6f701aa040bb2b064fcb
BLAKE2b-256 8176d98349cdc6f79e6a12ca84079964605fb56af87b362e302e219e6cf16c3e

See more details on using hashes here.

File details

Details for the file msopt-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: msopt-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for msopt-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 35632ee08c0ca1dd189ff5ee1471d5275e1df2b58d6d96d03bd1670953d7dd9e
MD5 552199ad3e623d43de4d5c01fd3a8ba4
BLAKE2b-256 b3946e878c4fe386d06d6069806d6602740dd264424e06c99f28aa5b6d07e35d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page