def check_submodular(gamma): sm = Submodular() if sm.improves(gamma): print "%s is submodular." % str(gamma) else: print "%s is not submodular." % str(gamma)
def setUp(self): self.sm = Submodular(2) self.proj3 = [MinMax(3,[[i]]) for i in [0,1,2]] self.f = MinMax(3,[[0,1],[0,2]]) self.g = MinMax(3,[[0],[1],[2]]) self.h = MinMax(3,[[0,1]]) self.wop3 = WeightedOperation(3,2,self.proj3 + [self.f,self.g,self.h], [-1,-1,-1,1,1,1])
class TestSubmodular(unittest.TestCase): def setUp(self): self.sm = Submodular(2) self.proj3 = [MinMax(3,[[i]]) for i in [0,1,2]] self.f = MinMax(3,[[0,1],[0,2]]) self.g = MinMax(3,[[0],[1],[2]]) self.h = MinMax(3,[[0,1]]) self.wop3 = WeightedOperation(3,2,self.proj3 + [self.f,self.g,self.h], [-1,-1,-1,1,1,1]) def test_translations(self): self.assertEqual(self.sm.translations(2),[[-1,-1,1,1]]) def test_in_wclone(self): self.assertTrue(self.sm.in_wclone(self.wop3)) self.assertTrue(self.wop3.in_wclone(self.sm,MinMax.clone(2)))