function [output] = simulate(net, filename)
%SIMULATE Summary of this function goes here
%   Detailed explanation goes here
%simulating
queryExpr = '# ....';
splitLineExpr = '\ ';
prevQueryId = '';

testfile = fopen(filename);
tline = fgetl(testfile); 
queryId = regexp(tline, queryExpr, 'match');
sum_ndcg=0;
amount = 0;
while(~feof(testfile))
    prevQueryId = queryId;   
    k=1;    
    docsCells = {};
    while (strcmp(prevQueryId,queryId))        
        
        features = regexp(tline, splitLineExpr, 'split');
        featuresList = repmat(0,[1,246]); %initialize array with zeros
        featuresList(246) = str2double(cast(features(1), 'char'));
        
        for i=2:(length(features)-2)
            tmpStr = cast(features(i), 'char');
            tmpCell = regexp(tmpStr, '\:', 'split');
            index = str2double(cast(tmpCell(1,1), 'char'));
            valueChar = cast(tmpCell(1,2), 'char');
            value = str2double(valueChar);
            featuresList(index) = value;
        end;       
        docsCells(k,1)= {featuresList}; %#ok<AGROW>
        k=k+1;
        if(~feof(testfile))
            tline = fgetl(testfile); 
            queryId = regexp(tline, queryExpr, 'match');
        else
            break;
        end;
    end;
    %place where all documents for given query were retrieved from txt file
    docsMat = cell2mat(docsCells);
    input = docsMat';
    res = repmat(0,[size(input,2),2]);
    for j=1:size(input,2)
       tmp=sim(net,input(1:245,j));
       res(j,1)=tmp(11);
       res(j,2)=input(246,j);
    end;
    res=sortrows(res,-1);
    sum_ndcg=sum_ndcg+ndcg(res);
    amount=amount+1;
end;
fclose(testfile);
output=sum_ndcg/5;

end
