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

조회 수: 17 (최근 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 CenterFile Exchange에서 Get 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