% Delivered to the Government in Accordance with Contract FA8650-10-C-7080
% 
%  (c) 2011 Massachusetts Institute of Technology
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
%  
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as well as any drawings, specifications, and documentation (collectively "the Data"), to deal in the Data without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
% 



function [Structural_Complexity,E,connection_complexity,component_complexity,num_connections,num_components,rank_A] = structural_complexity(A,alpha,W);
%Structural Complexity metric calculation performed here...
% Input:- A: binary (0/1) Adjacency matrix (nxn) representing the physical architecture where n = #components
%       - alpha: component complexity weight vector (nx1) - default = ones(nx1) 
%       - W: connection complexity weights matrix (nxn) - default = A (optional argument)
%
%
% Output: Structural_Complexity = structural complexity
%         E = sume of singular values of adjacency matrix A
%         connection_complexity = sum of all connection weights
%         component_complexity = sum of all component weights
%         num_components = size of adjacency matrix A
%         num_connections = #interactions as expressed through adjacency matrix A
%         rank_A = rank of interaction matrix A.
%
%
% Examples:
%           [Structural_Complexity,E,connection_complexity,component_complexity,num_connections,num_components] = structural_complexity(A_GTF,alpha,W);
%
%
A=unitize(A);
if(~isconnected(A)&&(size(A,1)==size(A,2)))
    disp(['Architecture is disconnected']);
    Structural_Complexity=-100;
    num_connections=-1;
    num_components=-1;
    component_complexity=-1;
    connection_complexity = -1;
else
    %architecture is connected...
    num_components=size(A,1);
    num_connections=sum(sum(A));
    if(nargin==1)
        component_complexity=num_components;
        connection_complexity = num_connections;
    elseif(nargin==2)
        component_complexity=sum(alpha);
        connection_complexity = num_connections;
    elseif(nargin==3)
        component_complexity=sum(alpha);
        connection_complexity = sum(sum(W));
    else
        disp(['Invalid argument list']);
        message=strcat('Arguments incorrect..Please use help..');
        error(message);
    end
    E=sum(svd(A));
    rank_A=rank(A);
    Structural_Complexity=component_complexity+(connection_complexity*E)/(num_components);
end
%

