Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant enhancements and stability for highspy #1942

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/network_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# sum(out) - sum(in) = { -1 if n = dest
# { 0 otherwise
rhs = lambda n: 1 if n == orig else -1 if n == dest else 0
flow = lambda E: sum((x[e] for e in E))
flow = lambda E: h.qsum((x[e] for e in E))

h.addConstrs(flow(G.out_edges(n)) - flow(G.in_edges(n)) == rhs(n) for n in G.nodes)
h.minimize()
Expand Down
8 changes: 4 additions & 4 deletions examples/nqueens.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
h = highspy.Highs()
h.silent()

x = np.reshape(h.addBinaries(N*N), (N, N))
x = h.addBinaries(N, N)

h.addConstrs(sum(x[i,:]) == 1 for i in range(N)) # each row has exactly one queen
h.addConstrs(sum(x[:,j]) == 1 for j in range(N)) # each col has exactly one queen
h.addConstrs(x.sum(axis=0) == 1) # each row has exactly one queen
h.addConstrs(x.sum(axis=1) == 1) # each col has exactly one queen

y = np.fliplr(x)
h.addConstrs(x.diagonal(k).sum() <= 1 for k in range(-N + 1, N)) # each diagonal has at most one queen
h.addConstrs(y.diagonal(k).sum() <= 1 for k in range(-N + 1, N)) # each 'reverse' diagonal has at most one queen

h.solve()
sol = np.array(h.vals(x))
sol = h.vals(x)

print('Queens:')

Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Typing :: Typed",
]

[project.optional-dependencies]
Expand All @@ -44,7 +45,9 @@ wheel.packages = ["src/highspy"]
# gitignore syntax.
sdist.include = [
"src/highspy/highs.py",
"src/highspy/_core.pyi",
"src/highspy/__init__.py",
"src/highspy/__init__.pyi",
"src/highspy/_core/*.pyi",
"tests/test_highspy.py",
"Version.txt",
"LICENSE",
Expand Down Expand Up @@ -188,7 +191,6 @@ log_cli_level = "INFO"
filterwarnings = ["error"]
testpaths = ["tests"]


[tool.cibuildwheel]
build = "*"
skip = "cp3{6,7}-*"
Expand Down
215 changes: 134 additions & 81 deletions src/highs_bindings.cpp

Large diffs are not rendered by default.

282 changes: 86 additions & 196 deletions src/highspy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,199 +1,89 @@
# from __future__ import annotations

from ._core import \
ObjSense, \
MatrixFormat, \
HessianFormat, \
SolutionStatus, \
BasisValidity, \
HighsModelStatus, \
HighsPresolveStatus, \
HighsBasisStatus, \
HighsVarType, \
HighsOptionType, \
HighsInfoType, \
HighsStatus, \
HighsLogType, \
IisStrategy, \
IisBoundStatus, \
HighsSparseMatrix, \
HighsLp, \
HighsHessian, \
HighsModel, \
HighsInfo, \
HighsOptions, \
_Highs, \
HighsIis, \
HighsSolution, \
HighsObjectiveSolution, \
HighsBasis, \
HighsRangingRecord, \
HighsRanging, \
kHighsInf, \
kHighsIInf, \
HIGHS_VERSION_MAJOR, \
HIGHS_VERSION_MINOR, \
HIGHS_VERSION_PATCH, \
simplex_constants, \
cb, \
kSolutionStatusNone, \
kSolutionStatusInfeasible, \
kSolutionStatusFeasible, \
kBasisValidityInvalid, \
kBasisValidityValid

# kMaximize, \
# kColwise, \
# kRowwise, \
# kRowwisePartitioned, \
# kTriangular, \
# kSquare, \

# kNotset, \
# kLoadError, \
# kModelError, \
# kPresolveError, \
# kSolveError, \
# kPostsolveError, \
# kModelEmpty, \
# kOptimal, \
# kInfeasible, \
# kUnboundedOrInfeasible, \
# kUnbounded, \
# kObjectiveBound, \
# kObjectiveTarget, \
# kTimeLimit, \
# kUnknown, \
# kSolutionLimit, \
# kInterrupt, \
# kMemoryLimit, \
# kNotPresolved, \
# kNotReduced, \
# kInfeasible, \
# kUnboundedOrInfeasible, \
# kReduced, \
# kReducedToEmpty, \
# kTimeout, \
# kNullError, \
# kOptionsError, \
# kOutOfMemory, \
# kLower, \
# kBasic, \
# kUpper, \
# kZero, \
# kNonbasic, \
# kContinuous, \
# kInteger, \
# kSemiContinuous, \
# kSemiInteger, \
# kBool, \
# kInt, \
# kDouble, \
# , \
# , \
# , \
# , \
# , \
# , \
# , \
from ._core import (
ObjSense,
MatrixFormat,
HessianFormat,
SolutionStatus,
BasisValidity,
HighsModelStatus,
HighsPresolveStatus,
HighsBasisStatus,
HighsVarType,
HighsOptionType,
HighsInfoType,
HighsStatus,
HighsLogType,
IisStrategy,
IisBoundStatus,
HighsSparseMatrix,
HighsLp,
HighsHessian,
HighsModel,
HighsInfo,
HighsOptions,
_Highs, # type: ignore
HighsIis,
HighsSolution,
HighsObjectiveSolution,
HighsBasis,
HighsRangingRecord,
HighsRanging,
kHighsInf,
kHighsIInf,
HIGHS_VERSION_MAJOR,
HIGHS_VERSION_MINOR,
HIGHS_VERSION_PATCH,
simplex_constants, # type: ignore
cb, # type: ignore
kSolutionStatusNone,
kSolutionStatusInfeasible,
kSolutionStatusFeasible,
kBasisValidityInvalid,
kBasisValidityValid,
)

from .highs import Highs

__all__ = ["__doc__",
"__version__",
"ObjSense",
"MatrixFormat",
"HessianFormat",
"SolutionStatus",
"BasisValidity",
"HighsModelStatus",
"HighsPresolveStatus",
"HighsBasisStatus",
"HighsVarType",
"HighsOptionType",
"HighsInfoType",
"HighsStatus",
"HighsLogType",
"IisStrategy",
"IisBoundStatus",
"HighsSparseMatrix",
"HighsLp",
"HighsHessian",
"HighsModel",
"HighsInfo",
"HighsOptions",
"_Highs",
"Highs",
"HighsIis",
"HighsSolution",
"HighsObjectiveSolution",
"HighsBasis",
"HighsRangingRecord",
"HighsRanging",
"kHighsInf",
"kHighsIInf",
"HIGHS_VERSION_MAJOR",
"HIGHS_VERSION_MINOR",
"HIGHS_VERSION_PATCH",
"simplex_constants",
"cb",
# "kMinimize",
# "kMaximize",
# "kColwise",
# "kRowwise",
# "kRowwisePartitioned",
# "kTriangular",
# "kSquare",
"kSolutionStatusNone",
"kSolutionStatusInfeasible",
"kSolutionStatusFeasible",
"kBasisValidityInvalid",
"kBasisValidityValid",
# "kNotset",
# "kLoadError",
# "kModelError",
# "kPresolveError",
# "kSolveError",
# "kPostsolveError",
# "kModelEmpty",
# "kOptimal",
# "kInfeasible",
# "kUnboundedOrInfeasible",
# "kUnbounded",
# "kObjectiveBound",
# "kObjectiveTarget",
# "kTimeLimit",
# "kUnknown",
# "kSolutionLimit",
# "kInterrupt",
# "kMemoryLimit",
# "kNotPresolved",
# "kNotReduced",
# "kInfeasible",
# "kUnboundedOrInfeasible",
# "kReduced",
# "kReducedToEmpty",
# "kTimeout",
# "kNullError",
# "kOptionsError",
# "kOutOfMemory",
# "kLower",
# "kBasic",
# "kUpper",
# "kZero",
# "kNonbasic",
# "kContinuous",
# "kInteger",
# "kSemiContinuous",
# "kSemiInteger",
# "kBool",
# "kInt",
# "kDouble",
# "",
# "",
# "",
# "",
# "",
# "",
# "",
]
__all__ = [
"__doc__",
"ObjSense",
"MatrixFormat",
"HessianFormat",
"SolutionStatus",
"BasisValidity",
"HighsModelStatus",
"HighsPresolveStatus",
"HighsBasisStatus",
"HighsVarType",
"HighsOptionType",
"HighsInfoType",
"HighsStatus",
"HighsLogType",
"IisStrategy",
"IisBoundStatus",
"HighsSparseMatrix",
"HighsLp",
"HighsHessian",
"HighsModel",
"HighsInfo",
"HighsOptions",
"_Highs",
"Highs",
"HighsIis",
"HighsSolution",
"HighsObjectiveSolution",
"HighsBasis",
"HighsRangingRecord",
"HighsRanging",
"kHighsInf",
"kHighsIInf",
"HIGHS_VERSION_MAJOR",
"HIGHS_VERSION_MINOR",
"HIGHS_VERSION_PATCH",
"simplex_constants",
"cb",
"kSolutionStatusNone",
"kSolutionStatusInfeasible",
"kSolutionStatusFeasible",
"kBasisValidityInvalid",
"kBasisValidityValid",
]
Loading
Loading