function estseqlen=predroutingseq_sixall(initexp, tktindx, tktclassasso,expclassasso,maxstep,gammapriornew,testtktvector)
globalvars_edgefile;

current=initexp;
routingseq=[];
estseqlen=0;
lastnotsolvprob=1;
tempprob=0;
estseqsolprob=[];

estseqtransprob=[];
traintktindx0=unique(ExpTransTktFile(:,1));

%load 'EdgeConnInTrainAIX';

for i=1:maxstep
    fprintf('The %d -th step\n', i);
    candidate=find(EdgeConn(current,:))';
    %setdif=setdiff(candidate,traintktindx);
        
    if (numel(candidate)==0)
        
        break;

    else
         k2TRCtran=TRCtran(current,candidate)/sum(TRCtran(current,candidate));
         k4volum=volumtran(current,candidate)/sum(volumtran(current,candidate));
         k6rand=PureRandTrans(current,candidate)/sum(PureRandTrans(current,candidate));
         
         
    end
    
    tempinput=tktclassasso(tktindx)*ones(numel(candidate),1)+ expclassasso(candidate);
    
    probest0=1./(1+exp(-tempinput));
       
    
    if (numel(candidate)>1)
        probest=probest0;


       posi11=find(probest>=0.5);
       posi12=find(probest<0.5);
       probest(posi11)=0.99;
       probest(posi12)=0.01;
       
      
        
       
%     
     if(numel(find(traintktindx0==current))==0)        
        tempphi=alphaprior/sum(alphaprior);       
     else       
        tempphi=gammapriornew(current,:)/sum(gammapriornew(current,:));        
     end  
     

     
     strategylabel=find(mnrnd(1,tempphi)==1);  %% tempphi is the mixture weight for strategies
     
     if (strategylabel==1)     
   
        candposi=find(probest'>=0.5);
        if (numel(candposi)>0)
        newcand=candidate(candposi);
         
        multidis=TRCtran(current,newcand)/sum(TRCtran(current,newcand));
         
        % multidis= multidis';
        
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=newcand(nextflag);
        nextflag=candposi(nextflag);
        
        else
           strategylabel=2; 
        end
        
     end
        
     if (strategylabel==3)     
   
        candposi=find(probest'>=0.5);
        if (numel(candposi)>0)
        newcand=candidate(candposi);
         
        multidis=volumtran(current,newcand)/sum(volumtran(current,newcand));
         
       % multidis= multidis';
        
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=newcand(nextflag);
        nextflag=candposi(nextflag);
        
        else
           strategylabel=4; 
        end
        
     end
     
     if (strategylabel==5) 
   
        candposi=find(probest'>=0.5);
        if (numel(candposi)>0)
        newcand=candidate(candposi);
         
        multidis=ones(1,numel(newcand))/numel(newcand);
         
      %  multidis= multidis';
        
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=newcand(nextflag);
        nextflag=candposi(nextflag);
        
        else
           strategylabel=6; 
        end
        
     end
     
     if (strategylabel==2)
        multidis=k2TRCtran;
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=candidate(nextflag);
     end   
        
     if (strategylabel==4)
        multidis=k4volum;
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=candidate(nextflag);
     end
     if (strategylabel==6)
         
        multidis=k6rand;   
        nextflag=mnrnd(1,multidis)==1;    
        nextexpert=candidate(nextflag);
     end 
     
    
    if numel(find(EdgeConn(nextexpert,:)))~=0
    estseqlen=estseqlen+(i+1)*lastnotsolvprob*probest0(nextflag);
    tempprob=tempprob+lastnotsolvprob*probest0(nextflag);
    lastnotsolvprob=lastnotsolvprob*(1-probest0(nextflag));
    estseqsolprob=[estseqsolprob probest0(nextflag)];
   % estseqtransprob=[estseqtransprob multidis(nextflag)];
    routingseq=[routingseq nextexpert];
    else
% % %     estseqlen=estseqlen+(i+1)*lastnotsolvprob*1;
% % %     tempprob=tempprob+lastnotsolvprob*1;
% % %     lastnotsolvprob=0;
% % %     estseqsolprob=[estseqsolprob 1];
% % %     estseqtransprob=[estseqtransprob multidis(nextflag)];
% % %     routingseq=[routingseq nextexpert];
    
    estseqlen=estseqlen+(i+1)*lastnotsolvprob*probest0(nextflag);
    tempprob=tempprob+lastnotsolvprob*probest0(nextflag);
    lastnotsolvprob=lastnotsolvprob*(1-probest0(nextflag));
    estseqsolprob=[estseqsolprob probest0(nextflag)];
   % estseqtransprob=[estseqtransprob multidis(nextflag)];
    routingseq=[routingseq nextexpert];
    
    %break;
    
    end
    
    else
        
    nextexpert=candidate;
    if numel(find(EdgeConn(nextexpert,:)))~=0
    estseqlen=estseqlen+(i+1)*lastnotsolvprob*probest0;
    tempprob=tempprob+lastnotsolvprob*probest0;
    lastnotsolvprob=lastnotsolvprob*(1-probest0);
    estseqsolprob=[estseqsolprob probest0];
    %estseqtransprob=[estseqtransprob 1];
    
    routingseq=[routingseq nextexpert];
    else
% %     estseqlen=estseqlen+(i+1)*lastnotsolvprob*1;
% %     tempprob=tempprob+lastnotsolvprob*1;
% %     lastnotsolvprob=0;
% %     estseqsolprob=[estseqsolprob 1];
% %     estseqtransprob=[estseqtransprob 1];  
% %     routingseq=[routingseq nextexpert];

    estseqlen=estseqlen+(i+1)*lastnotsolvprob*probest0;
    tempprob=tempprob+lastnotsolvprob*probest0;
    lastnotsolvprob=lastnotsolvprob*(1-probest0);
    estseqsolprob=[estseqsolprob probest0];
   % estseqtransprob=[estseqtransprob 1];  
    routingseq=[routingseq nextexpert];
    
   % break;
        
    end
    end
    
    
   
    current=nextexpert;
    
end

estseqlen=estseqlen/tempprob; 

% if (numel(candidate)==0)
%     estseqlen=-1;
% end

routingseq
 estseqsolprob
 estseqtransprob
