package graphtea.extensions.reports.others;

import graphtea.extensions.AlgorithmUtils;
import graphtea.extensions.algorithms.shortestpath.algs.FloydWarshall;
import graphtea.extensions.reports.topological.ZagrebIndexFunctions;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.RenderTable;
import graphtea.graph.graph.Vertex;
import graphtea.platform.lang.CommandAttitude;
import graphtea.plugins.reports.extension.GraphReportExtension;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ali Rostami
 */
@CommandAttitude(name = "AllEccen", abbreviation = "_AllEccen")
public class AllEccen implements GraphReportExtension<RenderTable> {
    public String getName() {
        return "AllEccen";
    }

    public String getDescription() {
        return " AllEccen ";
    }

    public RenderTable calculate(GraphModel g) {
        ZagrebIndexFunctions zif = new ZagrebIndexFunctions(g);
        RenderTable ret = new RenderTable();
        List<String> titles = new ArrayList<>();
        titles.add(" m ");
        titles.add(" n ");
        titles.add(" total eccentricity ");
        titles.add(" eccentric connectivity index ");
        titles.add(" connective eccentricity index ");
        ret.setTitles(titles);

        double m = g.getEdgesCount();
        if (m == 10) {
            return null;
        }
        double n = g.getVerticesCount();

        List<Object> v = new ArrayList<>();
        v.add(m);
        v.add(n);

        FloydWarshall fw = new FloydWarshall();
        int[][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
        int total_eccentricity = 0;
        for (Vertex ver : g) {
            total_eccentricity += Eccentricity.eccentricity(g, ver.getId(), dist);
        }
        v.add(total_eccentricity);

        int eccentric_connectivity_index = 0;
        for (Vertex ver : g) {
            eccentric_connectivity_index += Eccentricity.eccentricity(g, ver.getId(), dist) * g.getDegree(ver);
        }
        v.add(eccentric_connectivity_index);

        double connective_eccentric_index = 0;
        for (Vertex ver : g) {
            connective_eccentric_index += (double) g.getDegree(ver) / Eccentricity.eccentricity(g, ver.getId(), dist);
        }
        v.add(connective_eccentric_index);
        ret.add(v);
        return ret;
    }

    @Override
    public String getCategory() {
        return "Verification-Checking";
    }
}
