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

11 Ansichten (letzte 30 Tage)
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;

Antworten (2)

Walter Roberson
Walter Roberson am 8 Jan. 2023
Bearbeitet: Walter Roberson am 8 Jan. 2023
Do not preallocate YD_1 as zeros, use optimexpr()
  8 Kommentare
Laura Grönniger
Laura Grönniger am 8 Jan. 2023
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 am 8 Jan. 2023
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);

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 8 Jan. 2023
Bearbeitet: Matt J am 9 Jan. 2023
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]

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by