def merge(op1, op2, rule_type, op1_child, op2_child): #print op1, op1.id, op2, op2.id, rule_type new_op = Rule(rule_type).merge(op1, op2) if new_op is None: return None #print "op2.parent:", op2, op2.id, op2.parent, op2.parent.id, op2.parent.child_list new_op.parent = op2.parent new_op.child_list.extend(op1.child_list) new_op.child_list.extend(op2.child_list) new_op.child_list.remove(op1) new_op.id.extend(op2.id) new_op.id.extend(op1.id) print "new_op:", new_op, new_op.id print "op2:", op2, op2.id if op1.pk_list is None or len(op1.pk_list) == 0: new_op.pk_list = op2.pk_list else: new_op.pk_list = op1.pk_list op1_child.extend(op1.child_list) op2_child.extend(op2.child_list) if new_op.parent is not None: print "new_op.parent:", new_op.parent, new_op.parent.child_list, new_op.parent.id op2_index = new_op.parent.child_list.index(op2) new_op.parent.child_list[op2_index] = new_op for child in new_op.child_list: child.parent = new_op return new_op
def preOptimize(self, free_vertexes, minset_map, minset, minset_num): _node = self.node_list[0] if _node.parent is None: minset_map[self] = 0 minset[0] = [self] else: prev = self.getPrevNoneSPOp() if isinstance(_node, node.SPNode): if isinstance(_node.child, node.TableNode): minset_map[self] = minset_map[prev] minset[minset_map[prev]].append(self) return self.child_list[0].preOptimize(free_vertexes, minset_map, minset, minset_num) return if Rule.__pk_compare__(self.pk_list, prev.pk_list): if isinstance(_node.parent, node.SPNode): minset_map[self.parent] = minset_map[prev] minset[minset_map[self.parent]].append(self.parent) minset_map[self] = minset_map[prev] minset[minset_map[prev]].append(self) else: if isinstance(_node.parent, node.SPNode): self.parent.is_free_vertex = True free_vertexes.append(self.parent) minset_num = minset_num + 1 minset_map[self] = minset_num minset[minset_num].append(self) for child in self.child_list: child.preOptimize(free_vertexes, minset_map, minset, minset_num)
def mergeMinset(self, minset_map, minset, minset_num): if len(self.child_list) == 0: #root_mrq = self.findRoot() #root_mrq.__printAll__() return self if len(self.child_list) == 1: child = self.child_list[0] tmp = child.mergeMinset(minset_map, minset, minset_num) if tmp is not None and tmp.is_free_vertex is False and minset_map[self] == minset_map[tmp]: new_op = None st_type = Rule.get_st(tmp, self) print "1st_type:", st_type op1_child, op2_child = [], [] new_op = Op.merge(tmp, self, st_type, op1_child, op2_child) minset_map[new_op] = minset_map[self] minset.append(new_op) self = new_op return self if len(self.child_list) == 2: [lchild, rchild] = self.child_list lop = lchild.mergeMinset(minset_map, minset, minset_num) rop = rchild.mergeMinset(minset_map, minset, minset_num) if lop is not None and lop.is_free_vertex is False and minset_map[self] == minset_map[lop]: new_op = None st_type = Rule.get_st(lop, self) print "2lst_type:", st_type op1_child, op2_child = [], [] new_op = Op.merge(lop, self, st_type, op1_child, op2_child) minset_map[new_op] = minset_map[self] minset.append(new_op) self = new_op if rop is not None and rop.is_free_vertex is False and minset_map[self] == minset_map[rop]: new_op = None st_type = Rule.get_st(rop, self) print "2rst_type:", st_type op1_child, op2_child = [], [] new_op = Op.merge(rop, self, st_type, op1_child, op2_child) minset_map[new_op] = minset_map[self] minset.append(new_op) self = new_op return self '''for child in self.child_list:
op.eq, S.back_price(S.home), S.maximum(S.back_price(S.away), S.back_price(S.home), S.back_price(S.const("The Draw")))), Condition( op.eq, S.back_price(S.away), S.minimum(S.back_price(S.away), S.back_price(S.home), S.back_price(S.const("The Draw")))) ]) ], event) lay_home_gt = lambda event: Strategy([ Rule(conditions=[ Condition(op.le, S.lay_price(S.home), S.const(7)), conds.valid_prices, Condition(op.gt, S.back_price(S.home), S.back_price(S.away)), Condition(op.gt, S.back_price(S.home), S.const(2)) ], actions=[ actions.LayHome(S.liability("LAY", 100)), ], max_triggers=1), rules.GreenPrice(op.lt, S.back_price(S.home), 2), ], event) # Result -> Float -> Str def make_row(result, s): home, away, event_id, total, bets, winner, initial_prices, volume = result return ";".join([ home, away, str(event_id), f2s(total),