使用 CPLEX 更新多 objective 二进制整数问题的动态权重
Dynamic weights update for multi-objective binary integer problem using CPLEX
我正在使用 IBM CPLEX v12 优化双objective 问题。 CPLEX 有一个 属性 来混合两个 objective 函数,当它们被赋予相同的优先级时。然后根据最初为两个 objective 设置的权重求解混合 objective。
我提供了一些初始权重,但是,我想在优化过程中根据找到的两个 objective 的现任值和界限更新它们。为此,我正在使用 CPLEX 提供的回调。我的问题是我能够提取最初设置的权重并显示它们。我使用 IloObjective 的 getWeight() 函数。但是,我不知道如何更新权重,因为我找不到任何类似的 setWeight() 函数。
回调实现如下所示:
class weightUpdateCallack: public IloCplex::Callback::Function
{
public:
// Constructor with data
weightUpdateCallack(IloCplex cplex) : obj(cplex.getEnv())
{
obj = cplex.getObjective();
}
void updateWeights(const IloCplex::Callback::Context& context)
{
qDebug() << "-----------------Callback--------------";
qDebug() << "Name: " << obj.getName();
qDebug() << "weight 1: " << obj.getWeight(1);
qDebug() << "constant: " << obj.getConst();
}
virtual void invoke (const IloCplex::Callback::Context& context);
private:
IloObjective obj;
};
void weightUpdateCallack::invoke(const IloCplex::Callback::Context &context)
{
if(context.inCandidate())
updateWeights(context);
}
找到候选解时回调,如下:
// Use a callback function to update weights
weightUpdateCallack weightsUpdate(cplex);
cplex.use(&weightsUpdate, IloCplex::Callback::Context::Id::Candidate);
我使用 IloStaticLex 函数传递 bi-objective 表达式数组以及权重和公差数组。
您没有弄清楚如何执行此操作并非巧合。自 CPLEX 12.9 起,不支持在求解期间更新多 objective 模型中 objective 的权重。此外,使用面向对象的 API(即 C++、Java、.NET),不可能在 objective 创建后修改其中一个。为了在这些 API 中更改 multiobjective 模型的属性,您需要先删除原来的 objective,然后添加一个新的 multiobjective 定义(使用 IloStaticLex
和以前一样)。
请参阅 CPLEX 用户手册中有关 Generic Callbacks 的部分,了解此功能可能实现的所有功能。
我正在使用 IBM CPLEX v12 优化双objective 问题。 CPLEX 有一个 属性 来混合两个 objective 函数,当它们被赋予相同的优先级时。然后根据最初为两个 objective 设置的权重求解混合 objective。
我提供了一些初始权重,但是,我想在优化过程中根据找到的两个 objective 的现任值和界限更新它们。为此,我正在使用 CPLEX 提供的回调。我的问题是我能够提取最初设置的权重并显示它们。我使用 IloObjective 的 getWeight() 函数。但是,我不知道如何更新权重,因为我找不到任何类似的 setWeight() 函数。
回调实现如下所示:
class weightUpdateCallack: public IloCplex::Callback::Function
{
public:
// Constructor with data
weightUpdateCallack(IloCplex cplex) : obj(cplex.getEnv())
{
obj = cplex.getObjective();
}
void updateWeights(const IloCplex::Callback::Context& context)
{
qDebug() << "-----------------Callback--------------";
qDebug() << "Name: " << obj.getName();
qDebug() << "weight 1: " << obj.getWeight(1);
qDebug() << "constant: " << obj.getConst();
}
virtual void invoke (const IloCplex::Callback::Context& context);
private:
IloObjective obj;
};
void weightUpdateCallack::invoke(const IloCplex::Callback::Context &context)
{
if(context.inCandidate())
updateWeights(context);
}
找到候选解时回调,如下:
// Use a callback function to update weights
weightUpdateCallack weightsUpdate(cplex);
cplex.use(&weightsUpdate, IloCplex::Callback::Context::Id::Candidate);
我使用 IloStaticLex 函数传递 bi-objective 表达式数组以及权重和公差数组。
您没有弄清楚如何执行此操作并非巧合。自 CPLEX 12.9 起,不支持在求解期间更新多 objective 模型中 objective 的权重。此外,使用面向对象的 API(即 C++、Java、.NET),不可能在 objective 创建后修改其中一个。为了在这些 API 中更改 multiobjective 模型的属性,您需要先删除原来的 objective,然后添加一个新的 multiobjective 定义(使用 IloStaticLex
和以前一样)。
请参阅 CPLEX 用户手册中有关 Generic Callbacks 的部分,了解此功能可能实现的所有功能。