/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.cnr.iasi.giant.algorithm.clustering;

import it.cnr.iasi.giant.algorithm.distance.Dijkstra;
import it.cnr.iasi.giant.algorithm.distance.GraphUtil;
import it.cnr.iasi.giant.frame.SpectralInitFrame;
import it.cnr.iasi.giant.thread.NetworkLoaderThread;
import java.io.IOException;

/**
 *
 * @author Fabio Cumbo
 * @info GIANT
 * @version v1.0
 * @organization IASI-CNR : Istituto di Analisi dei Sistemi ed Informatica 
 *                  "Antonio Ruberti" - Consiglio Nazionale delle Ricerche
 * 
 */
public class SpectralClustering extends ClusteringAlgorithm {
    
    @Override
    public boolean execute() {
        try {
            
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new SpectralInitFrame().setVisible(true);
                }
            });
            
            return false;
        } catch (Exception e) {
            return false;
        }
    }
    
    public static int[][] getDistanceMatrix(String distance, GraphUtil graph, double[][] adjMatrix) throws IOException {
            int[][] result = new int[NetworkLoaderThread.getDegreeMap().keySet().size()][NetworkLoaderThread.getDegreeMap().keySet().size()];    
            if (distance.equals("SP")) {
                for (int i=0; i<graph.vertices(); i++) {
                        int[] dist = Dijkstra.dijkstra_function(graph, i);
                        for (int j=i; j<dist.length; j++) {
                            result[i][j] = dist[j];
                            result[j][i] = dist[j];
                            System.out.print(dist[j] + "  ");
                        }
                        System.out.println();
                    }
            }
            else if (distance.equals("HAMMING")) {
                for (int i=0; i<NetworkLoaderThread.getDegreeMap().keySet().size(); i++) {
                        for (int j=i; j<NetworkLoaderThread.getDegreeMap().keySet().size(); j++) {
                            int hamm = 0;
                            if (i != j) {
                                for (int k=0; k<NetworkLoaderThread.getDegreeMap().keySet().size(); k++) {
                                    if (adjMatrix[k][i] != adjMatrix[k][j])
                                        hamm++;
                                }
                            }
                            result[i][j]=hamm;
                            result[j][i]=hamm;
                            System.out.print(hamm + " ");
                        }
                        System.out.println();
                    }
            }
            return result;
    }
        
}
