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 in_wclone(self,other,clone=None): """ Tests if another weighted polymorphism is in the weighted clone. This method is overloaded so that we use the more efficient procedure for generating the min/max clone when no clone is passed as input. :param other: The weighted operation we have testing. :type other: :class:`WeightedOperation` :param clone: The supporting clone. :type clone: :class:`Clone` """ if clone is None: clone = MinMax.clone(other.arity,self.dom) return WeightedOperation.in_wclone(self,other,clone)
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)))
def __init__(self,dom=2): WeightedOperation.__init__(self,2,dom, [Projection(2,dom,0), Projection(2,dom,1), MinMax(2,[[0,1]],dom), MinMax(2,[[0],[1]],dom)], [-1,-1,1,1])