多目标优化中的帕累托最优点(3 个目标)

Pareto optimal points in multi objective optimization (3 objectives)

提问人:atco35 提问时间:1/17/2023 更新时间:8/5/2023 访问量:106

问:

我有一个包含 3 个目标的多目标优化问题。我应用了圆锥标量化,因为我不太确定它是否是凸的。无论如何,最后,我有一个 Excel 工作表,其中包含圆锥标量化的 z1、z2 和 z3 分数。但是,问题是 Excel 工作表有 6050 行。因此,我不太确定如何获得帕累托最优点和支配点以将它们绘制在 3D 图形中。当然,可以只用所有的东西来绘制图,但我想在确定帕累托最优点和主导点后使用色调来分离它们。 我将分数导出到 Excel,但我将在 Python 中绘制它们。 因此,我很高兴您可以与我分享任何代码或方法来获得 Excel 或 Python 中的帕累托最优点和主导点。

提前致谢,

注意:您可能会在 GAMS 论坛上找到我提出的相同问题。因为我用 GAMS 解决了 MOOP。但是,我不熟悉该论坛中的答案 [ 1 ]。因此,我还在这里要求它能够获得 Python 代码或解释如何将我的 Excel 文件提供给 GAMS 论坛中建议的“pareto.py”。

Python Excel 帕累托最优

评论


答:

0赞 MSS 8/5/2023 #1

您可以在 python 中将 excel 中的 z1、z2 和 z3 分数读取到 pandas 数据帧中。然后找到帕累托点和支配点,并从 python 绘制它们。

import pandas as pd
import numpy as np
import plotly.graph_objects as go

# Step 1: Read criteria from Excel file
df = pd.read_excel('criteria.xlsx')

# Step 2: Define your criteria for optimality
#  we want to minimize z1, z2, and z3.
# Hence, we'll negate the values to turn it into a maximization problem.
df['z1'] = -df['z1']
df['z2'] = -df['z2']
df['z3'] = -df['z3']

# Step 3: Normalize the data if needed
# If criteria are on different scales, you might want to normalize them.

# Step 4: Sort the DataFrame based on each criterion in descending order
df_sorted = df.sort_values(by=['z1', 'z2', 'z3'], ascending=False)

# Step 5: Find the Pareto optimal rows using vectorized operations
is_pareto_optimal = np.ones(df_sorted.shape[0], dtype=bool)
current_max_2 = float('-inf')
current_max_3 = float('-inf')

for i in range(df_sorted.shape[0]):
    if df_sorted.iloc[i]['z2'] <= current_max_2 or df_sorted.iloc[i]['z3'] <= current_max_3:
        is_pareto_optimal[i] = False
    else:
        current_max_2 = df_sorted.iloc[i]['z2']
        current_max_3 = df_sorted.iloc[i]['z3']

pareto_optimal_indices = df_sorted[is_pareto_optimal].index
dominated_indices = df_sorted[~is_pareto_optimal].index

# The `pareto_optimal_indices` array contains the index of rows that form the Pareto front in sorted dataframe.
# The `dominated_indices` array contains the index of rows that are dominated in the sorted dataframe.

# Step 6: Plot the data using Plotly
fig = go.Figure()

# Plot Pareto optimal rows
fig.add_trace(go.Scatter3d(
    x=df.loc[pareto_optimal_indices, 'z1'],
    y=df.loc[pareto_optimal_indices, 'z2'],
    z=df.loc[pareto_optimal_indices, 'z3'],
    mode='markers',
    name='Pareto Optimal',
    marker=dict(
        color='green',
        size=6
    )
))

# Plot dominated rows
fig.add_trace(go.Scatter3d(
    x=df.loc[dominated_indices, 'z1'],
    y=df.loc[dominated_indices, 'z2'],
    z=df.loc[dominated_indices, 'z3'],
    mode='markers',
    name='Dominated',
    marker=dict(
        color='red',
        size=6
    )
))

# Update layout for better visualization
fig.update_layout(scene=dict(
    xaxis_title='z1',
    yaxis_title='z2',
    zaxis_title='z3'
))

# Show the plot
fig.show()