This class represents connected clusters between layers where weights are the number of shared nodes.
Connections are stored with one 'source' cluster which is connected to n 'destination' clusters, with n >= 0.
:param cluster_label: The cluster label of the 'source' cluster
:param cluster_layer: The layer name of the 'source' cluster
:param cluster_runId: The run which calculated the connections
:param cluster_containedNodesDict: Ids of nodes contained in the 'source' cluster
:param cluster_connNodesDict: Node Objects contained in 'dest' clusters, where the 'dest' cluster is uniquely identifiable by layer name and cluster label
:param cluster_connClustDict: Layer name, cluster label and weight for each 'dest' cluster
self.cluster_containedNodesDict=cluster_containedNodesDict#Keys are frozensets(touples) == frozenset(uniqueID, cluster and layer) Value is the Node UniqueId
self.cluster_connNodesDict=cluster_connNodesDict#Keys are frozensets(touples) (uniqueID:str,node_cluster:str,node_layer:str) Values are NodeC Objects
''' Calculates the similarity between clusters contained in the "inputLayerDict". Similarity is calculated for each combination of 2 clusters from the SAME layer.
:param Dict{layername: LayerC} inputLayerDict: Contains the associated Layer and Clusters objects. The dictonary KEY is layername, the Value is a LayerC Object. The LayerC object has an attribute cluster_Dict which stores the clusters in the LayerC.
:returns: Dict{tuple(cluster_label1, cluster_label2) : Dict{layername, similarityValue}}. Returns a Dictionary with a tuple of 2 clusters as KEY, and a Dictionary with the computed similarity of the clusters in regard to each layer as VALUE
:rtype: Dict{(string,string): Dict{str:float}}
'''
print("Entered calculateSimilarity")
similarityDict=dict()#the key is a frozenset(Tuple) (clusterLabel1,clusterLabel2)
clusterList=list()
forcurLayerCininputLayerDict.values():
forcurClusterincurLayerC.cluster_Dict.values():
clusterList.append(curCluster)
#print(" Nr. of clusters: "+str(len(clusterList)))
#go thru every combination of 2 clusters and calculate the similarity between them in regard to each layer
i=0
while(i<len(clusterList)):
iCluster=clusterList[i]
j=i+1
while(j<len(clusterList)):
jCluster=clusterList[j]
if(iCluster.cluster_layer==jCluster.cluster_layer):#calculate similarity only from the same layer
''' Calculates the nr of connections/weights between the clusters contained in the "inputLayerDict". Connections are made between clusters from DIFFERENT layers.
:param Dict{string: LayerC} inputLayerDict: Contains the associated LayerC and ConnClusters objects. The dictonary KEY is layername, the Value is a Layer Object. The Layer object has an attribute cluster_Dict which stores the clusters in the LayerC.
:returns: Dict{layername: LayerC}. Returns the inputLayerDict with the added connections in the attributes cluster_connClustDict and cluster_connNodesDict
:rtype: Dict{string: LayerC}
'''
#the input dictates which cluster is updated;
# #however it will update all the included clusters
# if i only want to update a single cluster without considering the rest i should create a new method?
''' Calculates the nr of connections/weights between the clusters contained in the "inputLayerDict". Connections are made between clusters from DIFFERENT layers.
:param int limitNrCluster: Limits Clusters considered. None or <0 values == No limit
:param int limitNrNodes: Limits Clusters considered. None or <0 values == No limit
:param List[str] listURLs : Specifies from which URLs to download data. If not provided/None => uses Default URLs
:returns: Dict{layername: LayerC}. Returns a Dict with the data gathered from the DB
''' Calculates the nr of connections/weights between the clusters contained in the "inputLayerDict". Connections are made between clusters from DIFFERENT layers.
:param List[string] layerNameList: Name of the layers to pull from the DB
:param int limitNrCluster: Limits Clusters considered. None or <0 values == No limit
:param int limitNrNodes: Limits Clusters considered. None or <0 values == No limit
:returns: Dict{layername: LayerC}. Returns a Dict with the data gathered from the DB
:rtype: Dict{string: LayerC}
'''
#Maximum of these nodes PER Layer will be considered
''' Gets Layer,Cluster and Node data from a JSON format, and appends it into the "layerDict" dictionary.
:param inputData: JSON data to be formated.
:param Dict{string: Layer} layerDict: If it's empty/null a new one will be created. Otherwise contains the associated Layer and Clusters objects to which JSON data is appended. The dictonary KEY is layername, the Value is a Layer Object. The Layer object has an attribute cluster_Dict which stores the clusters in the Layer.
:param int limitNrNodes: How many maximum nodes PER layer will be considered.
:returns: Dict{layername: Layer}. Returns the inputLayerDict with the added data from the JSON
''' Writes the similarityDict data to a JSON file.
:param Dict{(cluster_label1, cluster_label2): Dict{layername: value}} similarityDict: Object which contains Data about the similarity between the clusters, Clusters and Nodes
:param int limitNrNodes: How many nodes are contained in layerDict. Used in creating the name of the File
:param int limitNrCluster: How many clusters are contained in layerDict. Used in creating the name of the File
#layerDict = getClusterDataFromSwagger(limitNrCluster,limitNrNodes, URLlist) #for Swagger, Change URLs inside the function for different input Data or provide a list with URLS
totalNodes=totalNumberOfNodes(layerDict)
print("Nr. of nodes: "+str(totalNodes))
totalClusters=totalNumberOfClusters(layerDict)
print("Nr. of clusters: "+str(totalClusters))
timelist.append(currentTime())
#calculates the weights between the clusters (weight == number of connections) #return is displayed in outputLayerFunction
layerDict=calculateWeights(layerDict)
timelist.append(currentTime())
#calculates the similarity between the clusters #returns dictionary[ tuple(cluster_label1,cluster_label2),
#checking if the cluster "1" and cluster "2" from the "Location" layer have the sqrt(2) similarity values for when compared with 'Price'and 'Time'layers