3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-05 17:14:07 +00:00

improve add bin/item functions

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2023-12-21 15:27:11 -08:00
parent b09c237775
commit ae1d9270b5

View file

@ -92,15 +92,17 @@ class BinCoverSolver(UserPropagateBase):
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)
@ -243,7 +245,13 @@ class OptimizeBinCoverSolver:
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()
@ -253,12 +261,6 @@ class OptimizeBinCoverSolver:
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])