Skip to content

Commit ae1d927

Browse files
improve add bin/item functions
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent b09c237 commit ae1d927

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

examples/python/bincover.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@ def init(self):
9292
def add_bin(self, min_bound):
9393
assert not self.initialized
9494
index = len(self.bins)
95-
self.bins += [Bin(min_bound, index)]
96-
return index
95+
bin = Bin(min_bound, index)
96+
self.bins += [bin]
97+
return bin
9798

9899
def add_item(self, weight):
99100
assert not self.initialized
100101
assert weight > 0
101102
index = len(self.items)
102-
self.items += [Item(weight, index)]
103-
return index
103+
item = Item(weight, index)
104+
self.items += [item]
105+
return item
104106

105107
def num_items(self):
106108
return len(self.items)
@@ -243,7 +245,13 @@ def __init__(self):
243245
self.bin_solver = BinCoverSolver(self.solver)
244246
self.mss_solver = MaximalSatisfyingSubset(self.solver)
245247

248+
#
246249
# Facilities to set up solver
250+
# First add items and bins.
251+
# Keep references to the returned objects.
252+
# Then call init
253+
# Then add any other custom constraints to the "solver" object.
254+
#
247255
def init(self):
248256
self.bin_solver.init()
249257

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

256-
def item_index2item(self, index):
257-
return self.bin_solver.items[index]
258-
259-
def bin_index2bin(self, index):
260-
return self.bin_solver.bins[index]
261-
262264
def optimize(self):
263265
self.init()
264266
mss = self.mss_solver.get_mss([bin.var for bin in self.bin_solver.bins])

0 commit comments

Comments
 (0)