function  [y,final_score] = UGM_DecodeCombine_ICMrestart(logNodePot, logEdgePot, edgeStruct, nRestarts, lang)
% INPUT
% nodePot(node,class)
% edgePot(class,class,edge) where e is referenced by V,E (must be the same
% between feature engine and inference engine)
%
% OUTPUT
% nodeLabel(node)

[nNodes,maxState] = size(logNodePot);

maxPot = -inf;

for i = 1:nRestarts
    fprintf('Decoding with ICM with restart %d...\n',i);
    % y_sub = ceil(rand(nNodes,1).*double(edgeStruct.nStates));
    y_sub = UGM_DecodeLogInput_LBP(logNodePot,logEdgePot,edgeStruct);
    [y_sub, final_score]  = UGM_DecodeCombine_ICM(logNodePot,logEdgePot,edgeStruct,y_sub,lang);
    logPot = UGM_LogConfigurationPotentialLogInput(y_sub,logNodePot,logEdgePot,edgeStruct.edgeEnds);
    if logPot > maxPot
        fprintf('New Best\n');
        maxPot = logPot;
        y = y_sub;
    end
end
