2023 Wuyue Cup Quantum Computing Challenge APMCM Asia Pacific Region

Question 1 requires the deployment of two edge servers in a specific area to cover the maximum computing demand according to the computing demand distribution. Each edge server has a coverage radius of 1. The goal is to determine the location of two edge servers to cover the greatest computing needs. Assuming that the edge server location is at the center of the grid, the computational demand within each grid is provided in the attachment (Attachment 1_Computational Demand Distribution Data.csv).
It is required to use the QUBO model to solve this problem and use Kaiwu SDK's simulated annealing solver and CIM simulator to solve it. You need to provide the coordinates of deployed edge servers that can cover the maximum computing demand, and the corresponding total computing demand coverage.
The key to this problem lies in understanding and converting the problem into a suitable QUBO model, and effectively using Kaiwu SDK to find the best solution. Next, we start the modeling analysis by analyzing the computing demand distribution data pairs in the attachment.
The data set contains three columns:
X-axis: Represents the X-axis coordinate of the grid.
Y-axis: Indicates the Y-axis coordinate of the grid.
Amount of Computational Demands: Indicates the computational demand at this grid location.
Data visualization is as shown below

This picture shows the distribution of computing requirements at different grid locations. Each cell in the figure represents a grid point, and the depth of its color indicates the computing demand at that location. Darker areas indicate higher computational demands.
By looking at this picture, we can see that the computational requirements are unevenly distributed between different grids. This distribution is critical in determining the optimal placement of the two edge servers. Ideally, we want to deploy servers in areas where computing demand is concentrated and relatively high to maximize coverage and total computing demand.
Next, we can determine the optimal deployment location of the two edge servers based on this distribution, combined with the QUBO model and simulated annealing algorithm.
In order to solve problem one, we need to use these data to build a QUBO model to find the best locations of the two edge servers that can cover the maximum computing demand. The construction of the QUBO model will be based on the following principles:
Binary decision variable: Define a binary variable (0 or 1) for each grid location, indicating whether to deploy an edge server at that location.
Objective function: Construct an objective function to maximize the computational requirements of coverage. This will involve considering the coverage radius of the edge servers and the computing requirements of each grid.
Constraints: Although QUBO models typically do not involve explicit constraints, we need to ensure that the model reflects the condition that only two edge servers can be deployed.

The QUBO (Quadratic Unconstrained Binary Optimization) matrix is ​​constructed, which is a key step required to solve problem one. The construction of this matrix is ​​based on the following principles:
Matrix size: The size of the QUBO matrix is ​​the same as the number of grid points. In this case, each grid point corresponds to a binary decision variable (0 or 1) indicating whether to deploy an edge server at that location.
Reward mechanism: The diagonal elements of the QUBO matrix represent the rewards for deploying edge servers at the corresponding locations, which are proportional to the computing requirements at that location. Therefore, the higher the computational demand, the smaller the corresponding matrix element value (negative values ​​are used here to represent rewards, because we are minimizing QUBO).
Constraints: The off-diagonal elements of the QUBO matrix are used to enforce the constraint that only two edge servers can be deployed in total. By increasing the values ​​of the off-diagonal elements of the matrix, a penalty can be imposed for deploying more than two servers.
The next step is to use Kaiwu SDK's simulated annealing solver and CIM simulator to solve this QUBO matrix and find the optimal server deployment plan.
Search results:

Insert image description here

Optimal solution: Shows which grid locations the edge server is deployed at. True means deploying the server at the corresponding location.
Optimal value: Displays the QUBO energy value of the solution, representing the total computational requirements covered.
In the visualization, the distribution of compute demand is shown in shades of color, while the locations of edge servers are marked in red.

Question two:

Three data sets required for question 2:
User data (Attachment 2): Contains the X coordinate, Y coordinate of each user's location, and the computing requirements of that location .
Edge server data (Attachment 3): Contains the number, X coordinate, Y coordinate of each candidate edge server location, and the fixed cost of the location.
Cloud server data (Attachment 4): Contains the cloud server number, X coordinate, and Y coordinate.
In order to solve problem 2, we need to perform steps:
Data analysis and preparation: Understand and analyze the distribution of users’ computing needs, candidate locations of edge servers, and their Fixed costs, and location of cloud servers.
Problem modeling: Use the QUBO model to represent the problem, which will include determining the optimal deployment location of edge servers, computing costs, transmission costs, and ensuring that the needs of each user are met while Minimize total cost.
Solve the model: Use the simulated annealing solver or CIM simulator to solve the QUBO model to determine the optimal computing network layout.
Analysis of results: Analyze the results obtained by the solver to determine the deployment location and number of edge servers, as well as the connection methods between users and servers.
Perform data visualization first
Insert image description here

Data visualization displays the following information:
Distribution of user computing requirements: represented by points of different colors, with shades of color representing different computing requirements. These points are distributed throughout the area, showing the computational requirements at each location.
Edge server candidate locations: Indicated by red square markers. These locations are potential options for deploying edge servers, and each location has a corresponding fixed cost.
Cloud server location: indicated by a blue star mark. The location of the cloud server is fixed, and its computing resource capacity is considered unlimited
Data analysis is performed below
Computing demand distribution: demand is unevenly distributed, and some areas The demand is significantly higher than other regions. These high-demand areas should be prioritized when deciding where to deploy edge servers.
Location selection of edge servers: The selection of candidate locations needs to consider the ability to cover high-demand areas and the distance to these areas, since transmission costs are proportional to distance.
Cost-benefit analysis: Fixed costs and compute costs need to be weighed when choosing where to deploy edge servers. The closer the location is to the user, the lower the transmission costs, but may also mean higher fixed costs.

· Objective function: The objective function needs to minimize the total cost, including fixed cost, computing cost and transmission cost.
·Constraints:
Each user can only connect to one server.
The edge server's computing resource capacity must not exceed its limits.
Code writing and analysis is performed below
Fixed cost: The fixed cost of each candidate edge server location is directly added to the corresponding position of the QUBO matrix.
Computational cost and transmission cost: need to be calculated based on the connection decision between the user and the server. This can involve complex calculations, especially when dealing with user-to-edge-server and edge-server-to-cloud-server transmission costs.
Constraints: Ensure that each user only connects to one server and that the computing resource capacity of the edge server is not exceeded.
Building a complete QUBO model involves a lot of calculations and logical judgments. Considering the complexity of the model, some simplifications or approximations may be required to ensure that the model can be effectively processed by the solver.
See the introduction for complete content

Complete solution code for problem 2

First, we need to define some helper functions to calculate distance and cost

def euclidean_distance(x1, y1, x2, y2):
"""Calculate the Euclidean distance between two points"""
return round(((x1 - x2)**2 + (y1 - y2)**2)**0.5, 2)

def compute_cost(QUBO, solution, data_user, data_edge, data_cloud):
“”“计算给定解决方案的总成本”“”
total_cost = 0
N = len(data_edge)
M = len(data_user)
cloud_x, cloud_y = data_cloud.iloc[0][‘X-axis’], data_cloud.iloc[0][‘Y-axis’]

# 固定成本和计算成本
for i in range(N):
    if solution[i] == 1:
        total_cost += data_edge.iloc[i]['Fixed Cost']
        for j in range(M):
            if solution[N + i * M + j] == 1:
                total_cost += 2 * data_user.iloc[j]['Amount of Computational Demands']  # 边缘服务器计算成本

# 传输成本
for j in range(M):
    user_x, user_y = data_user.iloc[j]['X-axis'], data_user.iloc[j]['Y-axis']
    connected_to_edge = False
    for i in range(N):
        if solution[N + i * M + j] == 1:
            edge_x, edge_y = data_edge.iloc[i]['X-axis'], data_edge.iloc[i]['Y-axis']
            total_cost += euclidean_distance(user_x, user_y, edge_x, edge_y) * data_user.iloc[j]['Amount of Computational Demands']  # 用户到边缘的传输成本
            total_cost += euclidean_distance(edge_x, edge_y, cloud_x, cloud_y) * data_user.iloc[j]['Amount of Computational Demands']  # 边缘到云的传输成本
            connected_to_edge = True
            break
    if not connected_to_edge:
        total_cost += 2 * euclidean_distance(user_x, user_y, cloud_x, cloud_y) * data_user.iloc[j]['Amount of Computational Demands']  # 用户到云的传输成本

return total_cost

Build QUBO matrix

N = len(data_edge)
M = len(data_user)
num_variables = N + N * M # One variable per edge server location + Connection variables per user to each edge server
QUBO = np.zeros((num_variables, num_variables))

Populate the QUBO matrix

fixed cost

for i in range(N):
QUBO[i, i] = data_edge.iloc[i][‘Fixed Cost’]

Connection decisions (disregarding capacity limits and other constraints for now)

for i in range(N):
for j in range(M):
QUBO[N + i * M + j, N + i * M + j] = 2 * data_user.iloc[j]['Amount of Computational Demands'] # Edge server computing cost

Run the simulated annealing algorithm

init_state = np.random.choice([0, 1], size=num_variables)
result = dual_annealing(lambda x: compute_cost(QUBO, x > 0.5, data_user, data_edge, data_cloud), bounds=[(0, 1)] * num_variables, x0=init_state)

Output results

optimal_solution = result.x > 0.5
optimal_value = compute_cost(QUBO, optimal_solution, data_user, data_edge, data_cloud)

print(“Optimal Solution:”, optimal_solution)
print(“Optimal Value:”, optimal_value)

Guess you like

Origin blog.csdn.net/yeqianqian_/article/details/134838997