Skip to content

Commit

Permalink
Significant update to highspy:
Browse files Browse the repository at this point in the history
* additional tests (with >99% coverage)
* performance improvements
* added support for calculating a value from expression
* added support for getting expression for a given constraint
* various bug fixes
* made behaviour more consistent/intuitive
* improved numpy interability
* improved error reporting/handling
  • Loading branch information
mathgeekcoder committed Sep 7, 2024
1 parent b09d2dd commit 1b346e8
Show file tree
Hide file tree
Showing 3 changed files with 1,823 additions and 319 deletions.
12 changes: 6 additions & 6 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(h.qsum(x[i,:]) == 1 for i in range(N)) # each row has exactly one queen
h.addConstrs(h.qsum(x[:,j]) == 1 for j in range(N)) # 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.addConstrs(h.qsum(x.diagonal(k)) <= 1 for k in range(-N + 1, N)) # each diagonal has at most one queen
h.addConstrs(h.qsum(y.diagonal(k)) <= 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
Loading

0 comments on commit 1b346e8

Please sign in to comment.