You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修正目标函数乘积项线性化后的GAMS模型偏差?

非线性模型线性化修正思路

问题概述

在GAMS中尝试用McCormick包络线性化目标函数中的x(t)*y(t)乘积项,原模型中u(t)为二元变量(u=1表示时间步t启用x、y,u=0则x、y为0),但线性化后求解时u(t)变为连续变量(如u(t1)=0.295),且结果与原模型不符。

原模型

min Ob = sum(t, (another terms) + x(t)*y(t))  
s.t. x(t) <= u(t) * x_max
     x(t) >= u(t) * x_min
     y(t) <= u(t) * y_max
     y(t) >= u(t) * y_min
     other constraints but not any related to the product of x and y

现有线性化模型

min Ob = (another terms) + z
s.t. z(t) >= x_min * y(t) + y_min * x(t) - x_min * y_min
     z(t) >= x_max * y(t) + y_max * x(t) - x_max * y_max  
     z(t) <= x_min * y(t) + y_max * x(t) - x_min * y_max
     z(t) <= x_max * y(t) + y_min * x(t) - x_max * y_min
     x(t) <= u(t) * x_max
     x(t) >= u(t) * x_min
     y(t) <= u(t) * y_max
     y(t) >= u(t) * y_min
     other constraints but not any related to the product of x and y

核心问题分析

  1. u(t)的二元属性未明确声明:GAMS中若未显式指定u(t) binary;,求解器会默认将其视为连续变量,这是u出现非0/1值的直接原因。
  2. McCormick约束未关联u(t)的状态:现有约束未区分u(t)=0和u(t)=1的场景,当u取中间值时,z(t)的约束仍生效,给求解器留下了优化空间,导致u偏离二元属性。
  3. 目标函数写法错误:原模型是对每个t求和,现有线性化模型的目标函数未包含sum(t, ...),导致目标函数逻辑与原模型不符。

修正步骤

1. 明确u(t)的二元属性

在GAMS模型的变量声明部分,必须添加:

u(t) binary;

确保求解器将u(t)视为二元变量处理。

2. 给McCormick约束添加u(t)开关

针对u(t)的两种状态,对z(t)的约束进行松绑或强化:

  • 当u(t)=1时,启用标准McCormick包络约束;
  • 当u(t)=0时,约束z(t)=0(因x(t)=0、y(t)=0,乘积项为0)。

具体约束写法:

// 定义足够大的松弛项M(需大于z(t)的最大可能绝对值)
parameter M;
M = abs(x_max*y_max) + abs(x_min*y_min);

// 带开关的McCormick约束
z(t) >= x_min * y(t) + y_min * x(t) - x_min * y_min - (1 - u(t))*M;
z(t) >= x_max * y(t) + y_max * x(t) - x_max * y_max - (1 - u(t))*M;
z(t) <= x_min * y(t) + y_max * x(t) - x_min * y_max + (1 - u(t))*M;
z(t) <= x_max * y(t) + y_min * x(t) - x_max * y_min + (1 - u(t))*M;

// 强制u=0时z=0
z(t) <= u(t)*M;
z(t) >= -u(t)*M;

当u(t)=0时,(1-u(t))*M会让前四个约束松弛,而后两个约束直接限制z(t)=0;当u(t)=1时,开关项失效,前四个约束恢复为标准McCormick包络。

3. 修正目标函数

将线性化后的目标函数改为与原模型一致的求和形式:

min Ob = sum(t, (another terms) + z(t));

4. 验证变量边界合理性

确保x_min、x_max、y_min、y_max是u(t)=1时x(t)、y(t)的有效边界值,若存在负数边界,需确认McCormick约束的形式是否适配(标准McCormick适用于变量有上下界的情况,若边界包含负数仍可使用,但需保证M的取值足够覆盖极端情况)。


内容的提问来源于stack exchange,提问作者Thành Trần

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 14:32:34