Skip to content

Commit

Permalink
Fixed coverage until not resetting after new cover
Browse files Browse the repository at this point in the history
  • Loading branch information
euxhenh committed Dec 26, 2021
1 parent 4d5806f commit 8bedd9c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run(self):
'name': 'multiset_multicover',
'description': 'MM is a package for running the greedy cover algorithm to perform multiset multicover.',
'license': 'MIT',
'version': '0.21',
'version': '0.3',
'author': 'Euxhen Hasanaj',
'author_email': 'ehasanaj@cs.cmu.edu',
'url': 'https://github.com/ferrocactus/multiset_multicover',
Expand Down
1 change: 1 addition & 0 deletions src/multiset_multicover/GreedyCover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ vector<size_t> GreedyCoverInstance::__cover()
this->__init_leftovers();
this->__init_remaining_msets();
this->__reset_msets();
this->_coverage_until.clear();
this->_n_elements_remaining.clear();
this->solution.clear();

Expand Down
6 changes: 3 additions & 3 deletions src/multiset_multicover/python_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ vector<size_t> create_size_t_vector_from_list(PyObject* py_list)
size_t num = PyLong_AsSize_t(py_item);
v[i] = num;
} else {
throw Exception("Non numeric value found.");
throw Exception("Non integer value found.");
}
}
return v;
Expand Down Expand Up @@ -232,7 +232,7 @@ PyObject* _GreedyCoverInstance_delete_multiset(PyObject* self, PyObject* args, P
if (PyLong_Check(py_index) && PyIndex_Check(py_index))
gci->delete_multiset(PyLong_AsSize_t(py_index));
else
throw Exception("Non numeric value found.");
throw Exception("Non integer value found.");

Py_INCREF(Py_None);
return Py_None;
Expand Down Expand Up @@ -263,7 +263,7 @@ PyObject* _GreedyCoverInstance_cover(PyObject* self, PyObject* args, PyObject* k
if (PyLong_Check(py_max_iters))
max_iters = PyLong_AsSize_t(py_max_iters);
else
throw Exception("Non integer number found.");
throw Exception("Non integer value found.");
}

if (PyLong_Check(py_coverage)) {
Expand Down
6 changes: 6 additions & 0 deletions src/multiset_multicover/python_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def __getitem__(self, index):
"""
return _c_mm._GreedyCoverInstance_at(self._gci, index)

def __repr__(self):
return f"GreedyCoverInstance({self.n_elements})"

def __str__(self):
return f"GreedyCoverInstance({self.n_elements}) with {self.size} multisets"

@property
def size(self):
"""
Expand Down
5 changes: 4 additions & 1 deletion test/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ def test1(self):
coverage_until = gci.coverage_until_
self.assertListEqual(coverage_until, [1, 1, 2])

_ = gci.cover(3)
solution = gci.cover(3)
self.assertListEqual(solution, [2, 1, 4])
multisets_incomplete_cover = gci.multisets_incomplete_cover_
self.assertListEqual(multisets_incomplete_cover, [3])
coverage_until = gci.coverage_until_
self.assertListEqual(coverage_until, [0, 1, 2])

def test2(self):
gci = mm.GreedyCoverInstance(4)
Expand Down

0 comments on commit 8bedd9c

Please sign in to comment.