error: Division by an OptimizationVariable not supported.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone, I met a error mentioned in my title, however, i don't think my code could be organized by a solver-based approach. (I am trying with the problem-based approach).
y=optimvar('y',[4,1,4],'Type','integer','LowerBound',0,'UpperBound',1);
yi=[y(1,1,1),y(2,1,1),y(3,1,1),y(4,1,1);y(2,1,1),y(2,1,1),y(3,1,1),y(4,1,1);y(3,1,1),y(3,1,1),y(3,1,1),y(4,1,1);y(4,1,1),y(4,1,1),y(4,1,1),y(4,1,1)]; %create binary decision variable yit
yi(:,:,2)=[y(1,1,2),y(2,1,2),y(3,1,2),y(4,1,2);y(2,1,2),y(2,1,2),y(3,1,2),y(4,1,2);y(3,1,2),y(3,1,2),y(3,1,2),y(4,1,2);y(4,1,2),y(4,1,2),y(4,1,2),y(4,1,2)];
yi(:,:,3)=[y(1,1,3),y(2,1,3),y(3,1,3),y(4,1,3);y(2,1,3),y(2,1,3),y(3,1,3),y(4,1,3);y(3,1,3),y(3,1,3),y(3,1,3),y(4,1,3);y(4,1,3),y(4,1,3),y(4,1,3),y(4,1,3)];
yi(:,:,4)=[y(1,1,4),y(2,1,4),y(3,1,4),y(4,1,4);y(2,1,4),y(2,1,4),y(3,1,4),y(4,1,4);y(3,1,4),y(3,1,4),y(3,1,4),y(4,1,4);y(4,1,4),y(4,1,4),y(4,1,4),y(4,1,4)];
qijTemp=randi(10,4); %create a 4x4 OD matrix with random volumes between 0-10
qij0=tril((qijTemp-diag(diag(qijTemp))),-1)+((tril(qijTemp-diag(diag(qijTemp)),-1))).'
r1=0.05;%annual demand growth rate
r2=0.1;%annual demand growth rate caused by the completion of rail routes
d=[0 20 30 35].';%di distance beween links 1-4. d1=0 since link 0-1 does not exist.
Hb0=0.25;% Bus headway in time period 0 (starting time period) 0.25hrs/bus
Hr0=0;% Train headway in time perid 0 (starting time period) 0 hrs/train since rail starts
ub=10;%cost of buses in $/hour
nc=6;%number of cars per train
uc=50;%cost of rail cars in $/car
L=500;%rail maintenance cost in $/mile
k=1000;%rail construction cost in $/mile
td=0.08;%dwell time for bus and rail in hours
vb=40;% bus operating speed
vr=60;% train operating speed
u=10; %user value of time in dollars per hour
N=4;
qij=zeros(4,4,N);
hb=optimexpr(4);
hr=optimexpr(4);
for t=1:N
if t==1
qij(:,:,t)=qij0;
yi(:,:,t)=zeros(4,4);
sij(:,:,t)=zeros(4,4);
else
qij(:,:,t)=qij(:,:,t-1)*(1+r1).^t*((1/8)*(1+sij(:,:,t)).^t);
end
hb(t)=2*sqrt(2*(1-yi(1,:,t))*d/vb+sum((1-yi(1,:,t))*td)*ub/(sum((1-yi(:,:,t)).*qij(:,:,t)))); %error
hr(t)=2*sqrt((2*yi(1,:,t)*d/vr+sum(yi(1,:,t)*td))*nc*uc/sum(y(:,:,t).*qij(:,:,t))); %error
end
% Thank you so much for helping me check this code. The error happened at hb(t) and hr(t)
1 commentaire
Torsten
le 26 Juil 2019
I think it would help to present your optimization problem in a mathematical notation.
Réponses (1)
Harsha Priya Daggubati
le 8 Août 2019
You can refer to the following link where a similar error was resolved:
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!