function [algorithmResults] = algorithmRunner(dataset, currentAlgorithm, currentPreProcessor, isThereGacPruning)

% define a variable that will keep the results for each algorithm
% initialize cells to -1, at the end all -1's should have been changed
algorithmResults = -1 * ones(1,size(dataset,1));


currentAlgorithm = char(currentAlgorithm);

% for each test instance
% run the algorithm
% and store the predictions
for i = 1:size(dataset,1)
    tempDataset = dataset;           % copy dataset to protect against deletion
    testSet = tempDataset(i,:);      % select test set/instance actually
    tempDataset(i,:) = [];           % delete selected instance from temp data
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%% code inside these lines are for gac pruning if pruning was selected
    if isThereGacPruning == 1
        [myTree, myRoot] = simpleGACGenerator(tempDataset);   % generate tree
        % prune high variance sub-trees
        [trainSet] = gacPruner(myTree, myRoot);
    else
        trainSet = tempDataset;
    end
    if size(trainSet,1) == 0 || size(dataset,1) == 0
        size(trainSet)
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % now start running the algorithms and storing the results
    if strcmp(currentAlgorithm, 'SWReg') == 1
        algorithmResults(1,i) = swRegression(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'SLReg') == 1
        algorithmResults(1,i) = slRegression(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'CART-On') == 1
        algorithmResults(1,i) = CARTOn(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'CART-Off') == 1
        algorithmResults(1,i) = CARTOff(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'PLSR') == 1
        algorithmResults(1,i) = myPLSR(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'PCR') == 1
        algorithmResults(1,i) = myPCR(testSet, trainSet);
    elseif strcmp(currentAlgorithm, '1NN') == 1
        algorithmResults(1,i) = OneNN(testSet, trainSet, currentPreProcessor);
    elseif strcmp(currentAlgorithm, 'NNet') == 1
        algorithmResults(1,i) = myNeuralNet(testSet, trainSet);
    elseif strcmp(currentAlgorithm, 'ABE0') == 1
        algorithmResults(1,i) = ABE0(testSet, trainSet, currentPreProcessor);
    elseif strcmp(currentAlgorithm, 'TEAK') == 1
        algorithmResults(1,i) = TEAK(testSet, trainSet, currentPreProcessor);
    else
        fprintf('ERROR: NO ALGORITHM WAS SELECTED TO EXECUTE!\n');
    end
end

if (sum(isnan(algorithmResults)) ~= 0) || (sum(isinf(algorithmResults)) ~= 0)
    problem = 1;
end

end