algorithm - Union grouping in bipartite graphs? -
I am trying to find a good (and faster) solution to the following problem:
My There are two models with whom I am working, let's call them players and teams, one player can be on several teams and there are many players in the team). I am working on creating a UI element that allows a user to select multiple teams (checkboxes). As the user chooses (or unselected) teams, I want to show teams grouped by players.
For example:
-
If there is no player involved in selected teams, each team has its own section
-
If the user selects two teams and they have the same player, then in one section both the teams and all the players will be named.
-
If players in TEAM_A [1, 2, 4, 5] and TEAM_B are players [1, 3, 5, 6]. The following sections will be: SECTION_X = [TEAM_A, TEAM_B, 1, 5], SECTION_Y = [TEAM_A, 2, 3], SECTION _Z = [TEAM_B, 3, 5]
I hope it is clear, essentially, I want to find teams that are similar to players and in the group. I was thinking that there is a way to do this by navigating on a bilateral graph? Not sure exactly how and I can finish it. I was hoping to do this by creating some kind of data structure on the server and using it on the client. I would love to hear your suggestions and I appreciate any help you have!
There is a solution that each player cover keeps track of selected teams
class PlayerWrapper {player player; List of teamlists team; } Class TeamList {Private list & lt; Team & gt; Teams; Intent hash value = // hash value teams added to zero (team team) {teams.add (team); Hash value = // update hash value}} Then maintain a hash table of player sets and a hash table of player wrapper
hashtable & lt ; TeamList, Set & lt; Player & gt; & Gt; PlayerSat hashtable & lt; Player, Player & gt; Player Warper
When the user selects a new team, repeats through team players and retrieves the player wrapper from
playerWrappers . For each player cover, set
to
- ; Player & gt; Get
playerSets from the set and remove the player from the set, then add a new team at the wrapper
TeamList ,
to < Player> Set the player set and add the player to the set. Zero Update Player (Team Team, Player Player) {PlayerWrapper wrapper = playerWrappers.get (player); Set up & lt; Player & gt; Set = playerSets.get (wrapper.teamList); Set.remove (player); wrapper.teamList.add (team); Set = playerSets.get (wrapper.teamList); Set.add (player); }
Believing that you set
set & lt; Player & gt; are using the hash set, on this, a team player must be constantly required for the process of the process. A team will be selected in the same manner, except that instead of adding it, Remove from code> wrapper.teamList , and you
TeamList to locate and delete the team. Using the
teamlist in
list assumes that the UI will stop duplicate teams; Instead be careful using a
set , as it can be more difficult to ensure that the two wrappers'
team list will have the same hash value (i.e. You may need to take steps to do that both wrapper '
team list return your teams in the same order - such a move would be like Java)
- ; Player & gt; Get
Comments
Post a Comment