function qnew=CreateNeighbor(q,I,j)
    
    m=randi([1 3]);
    
    switch m
        case 1
            % Do Swap
            qnew=Swap(q);
            
        case 2
            % Do Reversion
            qnew=Reversion(q,I,j);
            
        case 3
            % Do Insertion
            qnew=Insertion(q);
    end

end

function qnew=Swap(q)
    n=numel(q);
    i=randsample(n,2);
    i1=i(1);
    i2=i(2);
    
    qnew=q;
    qnew([i1 i2])=q([i2 i1]);
    
end

function qnew=Reversion(q,I,j)

    type=randi([1 j]);%j is the number of vehicles

    DelPos=find(q>I);
    
    n1=[0 DelPos]+1;
    n2=[DelPos I+j]-1; 
        
    i=randi([min(n1(type),n2(type)),max(n1(type),n2(type))],1,2);
    
   % i=randsample(n,2);
    i1=max(min(i(1),i(2)),1);
    i2=min(max(i(1),i(2)),numel(q));
    
    qnew=q;
    qnew(i1:i2)=q(i2:-1:i1);

end

function qnew=Insertion(q)

    n=numel(q);
    
    i=randsample(n,2);
    i1=i(1);
    i2=i(2);
    
    if i1<i2
        qnew=[q(1:i1-1) q(i1+1:i2) q(i1) q(i2+1:end)];
    else
        qnew=[q(1:i2) q(i1) q(i2+1:i1-1) q(i1+1:end)];
    end

end
