-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEOMM.py
67 lines (55 loc) · 2.06 KB
/
EOMM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
The Matchmaking Algorithms (i.e. matchmakers)
Author: Linxia GONG 巩琳霞 ([email protected])
Date: 2020-11-20 14:40:30
LastEditors: Linxia GONG 巩琳霞
LastEditTime: 2020-12-10 17:56:18
'''
import random
import networkx as nx
from networkx.algorithms.matching import max_weight_matching, is_perfect_matching
from matchmaking_simulator import PlayersGraph
from utils.loggingAgent import logger
# TODO 写一个Matchmaker的父类,作为接口类
class RandomMM(object):
def __repr__(self):
return "RandomMM"
def run(self, players):
pair_num = int(len(players)/2)
res = []
players_sort = list(players)
random.shuffle(players_sort)
for i in range(pair_num):
pair = (players_sort.pop().player_id, players_sort.pop().player_id)
res.append(pair)
return res
class SkillMM(object):
def __repr__(self):
return "SkillMM"
def run(self, players):
pair_num = int(len(players)/2)
res = []
players_sort = sorted(players, key=lambda p: p.mmr)
for i in range(pair_num):
pair = (players_sort.pop().player_id, players_sort.pop().player_id)
res.append(pair)
return res
class WorstMM(object):
def __repr__(self):
return "WorstMM"
def run(self, players):
if not isinstance(players, PlayersGraph):
players = PlayersGraph().load_players(players)
return max_weight_matching(players, maxcardinality=False, weight="churn_weight")
class EOMM(object):
def __repr__(self):
return "EOMM"
def run(self, players):
# logger.info('isinstance(players, PlayerGraph)= '+str(isinstance(players, PlayerGraph)))
if not isinstance(players, PlayersGraph):
# logger.info(type(players))
players = PlayersGraph().load_players(players)
return max_weight_matching(players, maxcardinality=False, weight="retain_weight")
# return max_weight_matching(players.G, maxcardinality=False, weight="weight")