我是 PuLP 的新手,正在尝试将标准差编程为优化问题中的目标函数。我已阅读此答案,尽管我知道它是相关的,但无法将其应用于我的具体情况。
我正在尝试解决以下优化问题:最大化一组 3 个决策变量的标准差,其相关权重向量为 [0.25、0.40 和 0.35]。我的限制是每个决策变量的范围应在 0.5 到 2.0 之间。(这是一个简化的示例;实际上,我将拥有更大的决策变量集和更大的相应权重向量)。
到目前为止,我的代码如下:
from pulp import LpMaximize, LpProblem, LpVariable
# Create the model
model = LpProblem(name="max_stdev", sense=LpMaximize)
# Define the decision variables
x = {i: LpVariable(name=f"x{i}", lowBound=0.5, upBound=2.0) for i in range(3)}
# Add the constraints to the model
model += (0.25*x[0] + 0.40*x[1] + 0.35*x[2] == 1, "weight_constraint")
# Add the objective function to the model, which should be the standard deviation of the x vector …Run Code Online (Sandbox Code Playgroud)