def test_4variables(self): l1 = Variable('l1', list(range(10))) l2 = Variable('l2', list(range(10))) l3 = Variable('l3', list(range(10))) y1 = Variable('y1', list(range(10))) @AsNAryFunctionRelation(l1, l2, l3, y1) def scene_rel(l1_, l2_, l3_, y1_): if y1_ == round((l1_ + l2_ + l3_) / 3): return 0 return 10000 @AsNAryFunctionRelation(l3) def cost_l3(l3_): return l3_ self.assertEqual(scene_rel(9, 6, 0, 5), 0) self.assertEqual(scene_rel(3, 6, 0, 5), 10000) joined = dpop.join_utils(scene_rel, cost_l3) self.assertEqual(joined(9, 6, 0, 5), 0) self.assertEqual(joined(3, 6, 0, 5), 10000) util = dpop.projection(joined, l3, 'min')
def test_projection_min_oneVarRel(self): # u1 is a relation with a single variable : x1 = Variable('x1', ['a', 'b', 'c']) u1 = NAryMatrixRelation([x1], np.array([2, 4, 8], np.int8)) # take the projection of u1 along x1 p = dpop.projection(u1, x1, mode='min') # the dimension must be one less than the dimension of u1 self.assertEqual(p.arity, 0) # this means that p is actually a signle value, corresponding to the # max of u1 self.assertEqual(p.get_value_for_assignment(), 2)
def test_projection_min_twoVarsRel(self): x1 = Variable('x1', ['a', 'b', 'c']) x2 = Variable('x2', ['1', '2']) u1 = NAryMatrixRelation([x1, x2], np.array([[2, 16], [4, 32], [8, 64]], np.int8)) # take the projection of u1 along x1 p = dpop.projection(u1, x1, mode='min') # the dimension must be one less than the dimension of u1, it should # contain only x2 self.assertEqual(p.arity, 1) self.assertListEqual(p.dimensions, [x2]) # the min of u1 when setting x2<-1 is 2 self.assertEqual(p.get_value_for_assignment(['1']), 2) # the min of u1 when setting x2<-2 is 16 self.assertEqual(p.get_value_for_assignment(['2']), 16)