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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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