integerConstraint
说明
为混合整数线性规划求解器 intlinprog 指定扩展整数变量的索引。扩展整数变量的类型包括整数型、半连续型和半整数型。有关详细信息,请参阅扩展整数变量。
创建对象
描述
指定传递给 intcon = integerConstraint(Name=Value)intlinprog 的 intcon 参量中的变量为扩展整数变量。例如,如果变量 x 的前五个索引是半连续的,而接下来的五个是整数,则设置 intcon = integerConstraint(SemiContinuous=1:5,Integer=6:10)。
名称-值参数
将可选参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。
示例: intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9) 将索引 1 至 4 指定为整数变量,并将索引 5 至 9 指定为半连续变量。
整数变量的索引,指定为正整数的向量。例如,如果 1 到 21 的奇数索引的变量为整数值,则指定
intcon = integerConstraint(Integer=1:2:21);
换句话说,如果 intcon 适用于变量 x,则此约束意味着变量 x(1)、x(3)、x(5)、…、x(21) 的值为整数。
向量 Integer、SemiContinuous 和 SemiInteger 必须具有不同的条目。可变索引不能出现在多个向量中。
提示
如果只有 Integer 类型的变量,则无需使用 integerConstraint 函数,即可将索引作为整数向量 intcon 传递。
此参量设置 Integer 属性。
半连续变量的指数,指定为正整数的向量。例如,如果变量 1 到 4 为整数值,变量 5 到 9 为半连续,则指定
intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9);
此参量设置 SemiContinuous 属性。
半整数变量的索引,指定为正整数的向量。例如,如果变量 10 至 20 为半整数,变量 1 至 9 为半连续,则指定
intcon = integerConstraint(SemiInteger=10:20,SemiContinuous=1:9);
此参量设置 SemiInteger 属性。
属性
整数索引,以正整数的向量形式返回。
数据类型: double
半连续索引,以正整数的向量形式返回。
数据类型: double
半整数索引,以正整数的向量形式返回。
数据类型: double
示例
指定变量索引 1 和 2 为半整数,变量索引 3 至 5 为半连续,变量索引 10 为整数,其余索引为连续(默认值)。
intcon = integerConstraint(SemiInteger=[1,2],SemiContinuous=3:5,Integer=10)
intcon =
IntegerConstraint with properties:
Integer: 10
SemiContinuous: [3 4 5]
SemiInteger: [1 2]
intcon 是一个 IntegerConstraint 对象,其属性是扩展整数变量。
在混合整数线性规划问题中使用这些变量。请注意,intlinprog 求解器默认使用 "highs" 算法,因此接受 IntegerConstraint 对象。
lb = [4 10 3/2 5/2 7/2 zeros(1,5)];
ub = 10*(1:10);
rng default
f = 10*randn(10,1) + 12;
A = 10*rand(20,10) - 15;
b = 10*rand(20,1);
[x,fval,eflag,output] = intlinprog(f,intcon,A,b,[],[],lb,ub)Running HiGHS 1.7.1: Copyright (c) 2024 HiGHS under MIT licence terms
Coefficient ranges:
Matrix [5e+00, 1e+01]
Cost [1e+00, 5e+01]
Bound [2e+00, 1e+02]
RHS [1e+00, 1e+01]
Presolving model
10 rows, 10 cols, 20 nonzeros 0s
0 rows, 5 cols, 0 nonzeros 0s
0 rows, 0 cols, 0 nonzeros 0s
Presolve: Optimal
Solving report
Status Optimal
Primal bound -382.267036084
Dual bound -382.267036084
Gap 0% (tolerance: 0.01%)
Solution status feasible
-382.267036084 (objective)
0 (bound viol.)
0 (int. viol.)
0 (row viol.)
Timing 0.01 (total)
0.01 (presolve)
0.00 (postsolve)
Nodes 0
LP iterations 0 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06.
x = 10×1
0
0
30
0
0
60
0
0
0
0
fval = -382.2670
eflag = 1
output = struct with fields:
relativegap: 0
absolutegap: 0
numfeaspoints: 1
numnodes: 0
constrviolation: 0
algorithm: 'highs'
message: 'Optimal solution found.↵↵Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06.'
详细信息
扩展整数变量是整数值、半连续或半整数的变量。
整数值变量可以取标准双精度变量表示的任何整数值,例如 –12 或 1234567。您无需为整型变量指定任何边界。
半连续变量可以取值
0或下界到上界之间的任何实数值。边界值必须严格为正且不超过1e5。半整数变量是整数值,可以取值
0或从下界到上界的任何整数值。边界值必须严格为正且不超过1e5。
默认算法为 "highs" 的 intlinprog 求解器支持整数变量和扩展整数变量,它们都具有 MATLAB® 类型 double。使用 integerConstraint 函数指定变量类型。使用以下名称指定变量索引中为整数或扩展整数的索引:
Integer- 整数变量索引SemiContinuous- 半连续变量索引SemiInteger- 半整数变量索引
未指定变量索引的默认类型为连续,这意味着变量可以取任何实数值。
例如,要指定变量 1 至 5 为整数,11 至 20 为半连续,其余为连续:
intcon = integerConstraint(Integer=1:5,SemiContinuous=11:20);
替代功能
基于问题的扩展整数变量方法
对于基于问题的教学方法,在创建变量时,请在 optimvar 中指定变量类型。
x = optimvar("x",Type="semi-continuous",... LowerBound=3,UpperBound=10) y = optimvar("y",2,Type="semi-integer",... LowerBound=[3,5],UpperBound=[10,20])
版本历史记录
在 R2025a 中推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)