%1-0 relocate

d=xlsread('Demand06.xlsx');
P=xlsread('Profit06.xlsx');
Z=L-1;
kostosnew=zeros(Z,1);
new_Q=zeros(Z,1);
diadromi_1=[feasible_routes(1,1:N);feasible_routes1(7,1:N)]
for h=1:Z
    j=1;
    while diadromi(h,j)~=0
        j=j+1;
    end
    j=j-1;
    for k=2:j
        DD=diadromi(h,k);
        P(DD,:)=0;
    end
end
    for v=1:2
        o=1;
        while diadromi_1(v,o)~=0
            o=o+1;
        end
        o=o-1;
        for s=2:o
            XX=diadromi_1(v,s);
            P(XX,:)=0;
        end
    end
    
            
    for i=1:20
        
         [~,n]=max(P(:,1));
         New_route=diadromi_1(1:1,1:N);
         New_apostasis=fa(1:1,1:N);
         temp_Apostasis=fa(1:1,1:N);            
      
         kk=1;
         while New_route(1,kk)~=0
             kk=kk+1;
         end
         kk=kk-1;
         tempmetavasis=zeros(kk,1);
         tempmetavasis(1,1)=inf;
         bb=1;
         for m=2:kk
             New_route=[New_route(1:m-1) 0 New_route(m:end-1)];
             New_route(1,m)=n;
             II=diadromi_1(1,m-1);
             UU=diadromi_1(1,m);
             bb=bb+1;
             
             tempmetavasis(bb,1)=[T(II,n)+T(n,UU)];
             New_route=diadromi_1(1:1,1:N);
         end
         
        [~,nodes]=min(tempmetavasis);
        New_route=[New_route(1:nodes-1) 0 New_route(nodes:end-1)];
        New_route(1,nodes)=n;
        New_apostasis=[New_apostasis(1:nodes-1) 0 New_apostasis(nodes:end-1)];
        GG=New_route(1,nodes-1);
        FF=New_route(1,nodes+1);
        New_apostasis(1,nodes)=T(GG ,n);
        New_apostasis(1,nodes+1)=T(n,FF );
        kostosnew(1,1)=sum(New_apostasis(1,:));
        New_Q=fq(1:1,1:N); 
        New_Q=[New_Q(1:nodes-1) 0 New_Q(nodes:end-1)];
        New_Q(1,nodes)=d(n);
        new_Q(1,1)=sum(New_Q(1,:));
        New_P=fp(1:1,1:N); %
        New_P=[New_P(1:nodes-1) 0 New_P(nodes:end-1)];
        New_P(1,nodes)=P(n);
         if kostosnew(1)<=200 & new_Q<=160
               kostos(1)=kostosnew(1,1);
               diadromi_1(1,:)=New_route(1,:);
               fa(1:1,1:N)=New_apostasis(1:1,1:N);
               fa2(i,:)=New_apostasis;
               fp2(i,:)=New_P;
               fq2(i,:)=New_Q;
               fq(1,:)=New_Q(1,:);
               fp(1:1,1:N)=New_P(1,:);
               feasible_P2(i,:)=sum(New_P(1,:));
               P(n,:)=0;
               feasible_routes2(i,:)=New_route;
               feasible_Q2(i,:)=new_Q;
               feasible_K2(i,:)=kostos(1);
         else
             
             New_route=diadromi_1(1,1:N);
             fa(1:1,1:N)=temp_Apostasis;
             New_Q=fq(1,1:N);
             New_P=fp(1,1:N);
             kostos(1:1,1:N)=kostosnew(1,:);
             P(n,:)=0;
         
         end
    end