function [NB,BSumFinal,Pattern,FinalB] = findoptimal(C,B1,B2,B3,B4,V,conserveoption) %UNTITLED2 Summary of this function goes here % Detailed explanation goes here NB=0; Pattern=zeros(2,4); %Finds optimal landscape. (X-star-i) for a=0:conserveoption(1,1); for b=0:conserveoption(1,2); for c=0:conserveoption(1,3); for d=0:conserveoption(1,4); for e=0:conserveoption(2,1); for f=0:conserveoption(2,2); for g=0:conserveoption(2,3); for h=0:conserveoption(2,4); B = B1; %User input if b==1 || e==1; B(1,1)=B2(1,1); end; if b==1 && e==1; B(1,1)=B3(1,1); end; if a==1 || c==1 || f==1; B(1,2)=B2(1,2); end; if (a==1 && c==1) || (a==1 && f==1) || (c==1 && f==1); B(1,2)=B3(1,2); end; if (a==1 && c==1 && f==1); B(1,2)=B4(1,2); end; if b==1 || d==1 || g==1; B(1,3)=B2(1,3); end; if (b==1 && d==1) || (b==1 && g==1) || (d==1 && g==1); B(1,3)=B3(1,3); end; if (b==1 && d==1 && g==1); B(1,3)=B4(1,3); end; if c==1 || h==1; B(1,4)=B2(1,4); end; if c==1 && h==1; B(1,4)=B3(1,4); end; if a==1 || f==1; B(2,1)=B2(2,1); end; if a==1 && f==1; B(2,1)=B3(2,1); end; if b==1 || e==1 || g==1; B(2,2)=B2(2,2); end; if (b==1 && e==1) || (b==1 && g==1) || (e==1 && g==1); B(2,2)=B3(2,2); end; if (b==1 && e==1 && g==1); B(2,2)=B4(2,2); end; if c==1 || f==1 || h==1; B(2,3)=B2(2,3); end; if (c==1 && f==1) || (c==1 && h==1) || (f==1 && h==1); B(2,3)=B3(2,3); end; if (c==1 && f==1 && h==1); B(2,3)=B4(2,3); end; if d==1 || g==1; B(2,4)=B2(2,4); end; if d==1 && g==1; B(2,4)=B3(2,4); end; BSum=sum(sum(B.*[a b c d; e f g h]))*V; CSum=sum(sum(C.*[a b c d; e f g h])); if BSum-CSum>NB NB = BSum-CSum; BSumFinal = BSum; Pattern=[a b c d; e f g h]; FinalB = B; end end;end;end;end;end;end;end;end; end