Skip to content

Commit

Permalink
improve add bin/item functions
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Dec 21, 2023
1 parent b09c237 commit ae1d927
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions examples/python/bincover.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ def init(self):
def add_bin(self, min_bound):
assert not self.initialized
index = len(self.bins)
self.bins += [Bin(min_bound, index)]
return index
bin = Bin(min_bound, index)
self.bins += [bin]
return bin

def add_item(self, weight):
assert not self.initialized
assert weight > 0
index = len(self.items)
self.items += [Item(weight, index)]
return index
item = Item(weight, index)
self.items += [item]
return item

def num_items(self):
return len(self.items)
Expand Down Expand Up @@ -243,7 +245,13 @@ def __init__(self):
self.bin_solver = BinCoverSolver(self.solver)
self.mss_solver = MaximalSatisfyingSubset(self.solver)

#
# Facilities to set up solver
# First add items and bins.
# Keep references to the returned objects.
# Then call init
# Then add any other custom constraints to the "solver" object.
#
def init(self):
self.bin_solver.init()

Expand All @@ -253,12 +261,6 @@ def add_item(self, weight):
def add_bin(self, min_bound):
return self.bin_solver.add_bin(min_bound)

def item_index2item(self, index):
return self.bin_solver.items[index]

def bin_index2bin(self, index):
return self.bin_solver.bins[index]

def optimize(self):
self.init()
mss = self.mss_solver.get_mss([bin.var for bin in self.bin_solver.bins])
Expand Down

0 comments on commit ae1d927

Please sign in to comment.