# Balanced Team Formation Using Hybrid Graph Convolution Networks and MILP
## 5 Proposed Balanced Team Formation Algorithm
### Experimental Work  
For experimental purposes, we have designed a network of fifteen players. Each player has a set of skills represented in vector format. The skills are ['Attack', 'Defense', 'Speed', 'Stamina', 'Teamwork']. Then, we computed a one-dimensional skill based on weights (preferences) that sums to one, e.g., [0.2, 0.3, 0.1, 0.2, 0.2], as shown in Equation (8). In this setting, we prefer the defense skill above the others.  
To sum up the proposed pipeline from end to end, the workflow fits together as follows:  
1. Input: Graph \(G=(V,E)\) is represented by an adjacency matrix \(A\) and a feature matrix \(X\). * \(A\): \(|V|\times|V|\) matrix, where \(A_{ij}=1\) if there is an edge between node \(i\) and node \(j\), otherwise 0. * \(X\): the \(|V|\times F\) matrix is the number of features per node.
2. GCN: Generate node embeddings.
3. Optimizer: Use embeddings to form balanced teams.
4. Output: Team assignments and skill balance metrics.  
Because the proposed pipeline consists of sequential stages, its overall performance is a direct result of the performance achieved at each stage. Thus, a well-trained GCN is mandatory to ensure the best encoding of the nodes to facilitate the second stage of this pipeline, i.e., the MILP optimizer. In the proposed model, the GCN provides the node embeddings that encapsulate both node features and the graph structure that are input into the optimizer. However, the quality of the embedding is key for several factors: the GCN's architecture (e.g., number of layers, hidden dimensions), the training process (e.g., loss function, optimization algorithm), and the input graph structure and node features.  
Figure 3: The interactions of the proposed GCN-MILP model.  
```
Input: Nodes and edge connections as a tensor, \(N\), number of teams, \(num\) and number of players per team \(ppr\); Initialize: Create a Data object; Create GCN model: \(model=teamGCN(params)\); Select device: \(device=torch.device\) ('cuda' iftorch.cuda.is_available() else'cpu') ; /* transfer the entire Data to the specified device */ \(data=data.to(device)\); /* transfer the model parameters and buffers to the specified device */ \(model=model.to(device)\); /* Initialize optimizer (Adam optimizer) and loss function */ \(optimizer=Adam(model.parameters(),lr=learning\_rate)\) ; \(loss=MSELoss()\); for\(epoch=0\)toepochsdo /* Set the model to training mode */ \(model.train()\); /* Reset gradients to avoid accumulation during backpropagation. */ \(gradientReset()\); /* Feed node features and edges into the model */ \(out=model(data.x,data.edge\_index)\); /* Calculate MSE */ \(loss=F.mse\_loss(out,torch.ones\_like(out))\); /* Backpropagation: Compute the gradients of the loss with respect to the model's parameters */ \(loss.backward()\); /* Use the computed gradients and learning rate to update the model's parameter */  optimizer.step() end /* Compute node embeddings */ \(node\_embeddings=getEmbeddings(data.x,data.edge\_index)\); /* Normalize input features: L2 normalization */ \(embeddings=normalize(.)\); /* Reduce embeddings */ \(reduced=reduceEmbeddings(embeddings)\); /* Create and solve MILP model */ \(solveMILP(reduced,num\_teams,members)\);
```  
**Algorithm 1**GCN-MILP algorithm to solve TFP.