フィルターのクリア

Optimization: Unable to perform assignment because value of type 'optim.pro​blemdef.Op​timization​Expression​' is not convertible to 'double'.

22 ビュー (過去 30 日間)
Hello,
I would like to perform a multiplication with a decision variable Yi. When doing so, I get the following error:
Unable to perform assignment because value of type 'optim.problemdef.OptimizationExpression' is not convertible to 'double'.
What's the Problem and how could I convert Yi to an double?
The code is:
Yi = optimvar('Yi', ns, 1,'type','integer','LowerBound',0,'UpperBound',1);
Dij = csvread("test_distanzmatrix_20.csv",1,1);
ns = size(Dij,1);
[...]
Yi_transponiert = transpose(Yi);
YD_1 = zeros(ns);
YD_2 = zeros(ns);
for i = 1:ns
YD_1(:,i) = Yi(:) .* Dij(:,i);
end
for j = 1:ns
YD_2(j,:) = Yi_transponiert(:) .* Dij(j,:);
end
LP_Distanz = YD_1 .* YD_2;
for i = 1:ns
LP_Distanz (i,i) = 0;
end
logistikpunktsuche.Constraints.cons9 = LP_Distanz >= D^2;

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 1 月 8 日
編集済み: Walter Roberson 2023 年 1 月 8 日
Do not preallocate YD_1 as zeros, use optimexpr()
  8 件のコメント
Laura Grönniger
Laura Grönniger 2023 年 1 月 8 日
I stand corrected... Any factor other than 0 should be greater than D. Can this be represented? So: If not 0, then greater than D.
Walter Roberson
Walter Roberson 2023 年 1 月 8 日
I do not understand what you are requesting about facters other than 0 should be greater than D ??
Are you looking at
logistikpunktsuche.Constraints.cons9 = LP_Distanz >= D^2;
and saying that the real constraint is that the value is permitted to be 0 if some corresponding entry is 0, otherwise has to be >= D^2 ?
If so then I am not clear as to which value to refer to for the "factor" that is permitted to be 0 ?
If you had an array of factors the same size as LD_Distanz then
logistikpunktsuche.Constraints.cons9 = (FactorArray == 0) | (LP_Distanz >= D^2);

サインインしてコメントする。


Matt J
Matt J 2023 年 1 月 8 日
編集済み: Matt J 2023 年 1 月 9 日
Here's a way to express the constraints linearly:
Dij=rand(5); D=1; %hypothetical input data
ns = size(Dij,1);
Yi = optimvar('Yi', ns, 'type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
M = optimvar('M', [ns,ns], 'type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
YY=Yi*ones(1,ns);
logistikpunktsuche.Constraints.Mupper= M<=(YY+YY.')/2;%Mupper and Mlower together
logistikpunktsuche.Constraints.Mlower= M>=(YY+YY.')-1;%equivalent to M==Yi&Yi.'
logistikpunktsuche.Constraints.LP_Distanz = Dij.*(1-eye(ns)).*M >= D^2.*M
logistikpunktsuche = struct with fields:
Constraints: [1×1 struct]

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by