0

Here is my model:

enter image description here

Solving this problem, I used GA in matlab

function F = sim_fit(q,k,m)
%retailer
a(1,1)=3;a(2,1)=2;a(3,1)=3;a(1,2)=1;a(2,2)=1.1;a(3,2)=9;
d(1,1)=1850;d(2,1)=2000;d(3,1)=3000;d(1,2)=2100;d(2,2)=1300;d(3,2)=900;
hr(1,1)=2.4;hr(2,1)=1.3;hr(3,1)=38;hr(1,2)=4.5;hr(2,2)=3.6;hr(3,2)=45;
so(1,1)=3.5;so(2,1)=1.5;so(3,1)=2.5;so(1,2)=0.3;so(2,2)=0.6;so(3,2)=6.3;
t(1,1)=1;t(2,1)=1;t(3,1)=3;t(1,2)=1;t(2,2)=1;t(3,2)=3;
E(1,1)=2;E(2,1)=2;E(3,1)=10;E(1,2)=2;E(2,2)=2;E(3,2)=10;
Y(1,1)=3;Y(2,1)=3;Y(3,1)=11;Y(1,2)=3;Y(2,2)=3;Y(3,2)=11;

%vendor
S=100;
hv(1)=3.5;hv(2)=4;
C(1)=10; C(2)=50;
Cv(1)=2.4; Cv(2)=3;
Cf(1)=3; Cf(2)=1.2;
s(1)=0.3; s(2)=0.1;
the(1)=0.01; the(2)=0.03;
dv(1)=sum(d(1,1)+d(1,2));dv(2)=sum(d(2,1)+d(2,2));
Q(1)=sum(q(1,1)+q(1,2));Q(2)=sum(q(2,1)+q(2,2));
P(1)=10000; P(2)=8000;


%function
for j=1:2
 for i=1:2   
F= S*dv(i)/(Q(i)*m(i,j))+(hv(i)*Q(i)*((m(i)-1)*(1-dv(i)/P(i))+dv(i)/P(i)))/2+...
dv(i)*(m(i)*C(i)+m(i)*Q(i)*Cv(i)+Cf(i))+m(i)*s(i)*dv(i)*Q(i)*the(i)/2+...
a(i,j).*d(i,j)./q(i,j)+(hr(i,j).*((1-k(i,j)).^2).*q(i,j))./2+...
k(i,j).^2.*so(i,j).*q(i,j)./2+(m(i)*t(i,j).*d(i,j))./q(i,j)+(m(i)*E(i,j).*d(i,j))./q(i,j)+...
Y(i,j).*d(i,j);
 end
end
end


function [C, ceq] = sim_constraint(q,k,m)
B(:,1)=200;B(:,2)=300;
W(:,1)=100;W(:,2)=100;
b(1)=10; b(2)=14;
w(1)=1; w(2)=1.5;
P(1)=10000; P(2)=8000;
C=[(m(1).*q(1,1).*b(1)+m(2).*q(2,1).*b(2))-B(:,1);
    (m(1).*q(1,2).*b(1)+m(2).*q(2,2).*b(2))-B(:,2);
  (m(1).*q(1,1).*w(1)+m(2).*q(2,1).*w(2))-W(:,1);
    (m(1).*q(1,2).*w(1)+m(2).*q(2,2).*w(2))-W(:,2);
    m(1)*Q(1)-P(1);m(2)*Q(2)-P(2)
    k(1,1)-1;k(1,2)-1;k(2,1)-1;k(2,2)-1];
ceq=[d(1,1)+d(1,2)-dv(1);(d(2,1)+d(2,2))-dv(2);
(q(1,1)+q(1,2))-Q(1);(q(2,1)+q(2,2))-Q(2)];
end

First, I don't know how to input Xij which is binary variable in sim_fitness function.

Second, in order to solve this problem, I use Optimization Toolbox. Error message said "need more input variable."

How can I fix it?

3
  • 2
    How exactly did you use Optimization Toolbox? Which line generated the error? Also, your MATLAB version sounds suspiciously alike the little robot from "Short Circuit" :-) Commented Nov 27, 2015 at 17:41
  • Whoah, yeah, soooo many indices! Commented Nov 27, 2015 at 23:15
  • I'm missing the definition of Q, d and dv from your last function. Commented Nov 27, 2015 at 23:38

1 Answer 1

0

This is not an answer to your question. But please, please start using matlab as it was intended:) If it was this cumbersome, then people would not be using it.

The net happiness of the human race will increase if you change your existing code to something like this:

function F = sim_fit(q,k,m)
   %retailer
   a=[3 2 3; 1 1.1 9].'; %or a=[3 1; 2 1.1; 3 9];
   d=[1850 2000 3000; 2100 1300 900].';
   hr=[2.4 1.3 38; 4.5 3.6 45].';
   so=[3.5 1.5 2.5; 0.3 0.6 6.3].';
   t=[1 1 3; 1 1 3].';
   E=[2 2 10; 2 2 10].';
   Y=[3 3 11; 3 3 11].';

   %vendor
   S=100;
   hv=[3.5 4];
   C=[10 50];
   Cv=[2.4 3];
   Cf=[3 1.2];
   s=[0.3 0.1];
   the=[0.01 0.03];
   dv=sum(d(1:2,:),2).'; %row vector like the earlier ones
   Q=sum(q(1:2,:),2).';
   P=[10000 8000];


   %function
   for j=1:2
      for i=1:2   
         F= S*dv(i)/(Q(i)*m(i,j))+(hv(i)*Q(i)*((m(i)-1)*(1-dv(i)/P(i))+dv(i)/P(i)))/2+...
            dv(i)*(m(i)*C(i)+m(i)*Q(i)*Cv(i)+Cf(i))+m(i)*s(i)*dv(i)*Q(i)*the(i)/2+...
            a(i,j).*d(i,j)./q(i,j)+(hr(i,j).*((1-k(i,j)).^2).*q(i,j))./2+...
            k(i,j).^2.*so(i,j).*q(i,j)./2+(m(i)*t(i,j).*d(i,j))./q(i,j)+(m(i)*E(i,j).*d(i,j))./q(i,j)+...
            Y(i,j).*d(i,j);
      end
   end

end


function [C, ceq] = sim_constraint(q,k,m)
   B=[200 300];
   W=[100 100];
   b=[10 14];
   w=[1 1.5];
   P=[10000 8000];

   mtmp=reshape(m(1:2),1,[]); %since I don't know its size, be on the safe side
   qtmp=q(1:2,1:2); %same thing here

   %WHAT IS Q?
   %WHAT IS d?
   %WHAT IS dv?

   C=[((mtmp.*b)*qtmp - B).';
      ((mtmp.*w)*qtmp - W).';
      (mtmp.*Q-P).'; %assuming Q is of size [1, 2]
      reshape(k(1:2,1:2).',4,1)-1];

   ceq=[sum(d(1:2,1:2),2)-dv.';
        sum(q(1:2,1:2),2)-Q.']; %assuming Q is of size [1, 2]

end

Sorry, I didn't have it in me to decrypt your expression for F. I strongly suggest getting familiar with the basic array syntax of matlab, and checking for yourself whether I made any mistakes during the conversion of your code. If you learn how to work with matrices and vectors, expressions like what you have for F can be radically simplified.

Also, the definition of the variables Q, d and dv seem to be missing from your second function. Those aren't globals, are they?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.