## 4 Proposed Model
### Model Validation
#### 4.4.1 Load Balancing
* current_cluster: Cluster to which the current request is assigned. * connected_clients: Set tracking clients connected to the server. The class includes the following methods:  
* Can_handle_request(): Checks if the server can handle an additional request. * Add_request(): Adds a client's request to the server, assigns them to a cluster based on conditions. * Remove_request(): Removes a client's request from the server, disconnecting them. * Choose_cluster(): Chooses a cluster for a client's request based on location. * Distance(): Calculates distance between server and client. * Is_capacity_reached(): Checks if server load has reached capacity. * get_latency(): Calculates network latency for a client. * average_latency(): Calculates average latency for all connected clients. **Load balancer class**: The load balancer class represents a load balancer in the proposed model. It distributes client requests among several servers to optimize server resource usage and reduce latency. It includes the following methods:  
* Get_best_server(): Selects the best server for a given client based on server latency and load. * Handle_request(): Manages client requests. If all servers are at full capacity, it prints a message and rechecks server capacities. **Client Class**: The client class represents each client in the proposed model. Each client can send requests to servers and has the following attributes:
* id: A unique identifier for each client. * server: Represents the server the client is currently connected to. * geo_location: Represents the geographical location of the client. * game_location: Represents the client's location within the game. * latency_log: A list recording the latency between the client and the server over time. * game_plan: An object of the class GamePlan representing an action in the client's game simulation. This class also includes the following methods:
* Connect_to_server(): Attempts to connect the client to a server. If the server can handle the request, the client connects to the server, network latency is calculated, and it is added to the client's latency log. * Move(): Allows the client to move to a new location in the game. If the client is connected to a server, it first removes the client's request from the server. Then, it updates the client's game location and attempts to add the client's request to the server again. If successful, it calculates the new latency and adds it to the latency log. If the server cannot handle the request, the method returns false. * Disconnect_from_server(): If the client is connected to a server, it removes the client's request from the server and disconnects the client from the server. * average_latency(): Calculates the average latency for the client. It sums all latencies in the client's latency log and divides by the number of latencies in the log. **GamePlan Class**: The GamePlan class represents a client's game plan in the proposed model. It is a sequence of actions that the client will perform and has the following attributes:
* actions: A list of possible actions the client can perform. * probabilities: A list of probabilities corresponding to each action in the actions list. This class also includes the method:
* get_action(): Returns an action from the actions list, randomly selected according to the given probabilities. Methods for Measuring Distance and Latency
* **Distance measurement**: The distance between the client and the server is calculated using the Euclidean distance formula in 2D or 3D space, depending on the locations. This measure is essential for assigning the client to a nearby cluster, which reduces latency. * **Latency calculation**: Latency is calculated using the following formula: \[\text{latency}=\text{distance}\times(1+\text{load factor})\times\text{network condition}\times 1000\] (1) where:
* **Distance**: The distance between the server and the client. * **Load factor**: The load on the server, represented as the number of connected clients over the server's capacity.