package figures;

import java.io.File;

import jimena.analysis.ConvergenceComparator;
import jimena.binaryrn.NetworkNode;
import jimena.binaryrn.RegulatoryNetwork;
import jimena.calculationparameters.SSSSearchParameters;
import jimena.calculationparameters.StandardSSSSearchParameters;
import jimena.simulationmethods.SQUADMethod;

public class FigurePlotInfGraphsAllData {

    /**
     * @param args
     */
    public static void main(String[] args) {
        RegulatoryNetwork network = new RegulatoryNetwork();
//        network.loadYEdFile(new File("I:\\realnetworks\\Th\\Th 2010 Version corrected layouted squeezed.graphml"));
//         network.loadYEdFile(new File("I:\\realnetworks\\Th\\Th 2010 Version corrected layouted loops.graphml"));
         network.loadYEdFile(new File("I:\\realnetworks\\Chondrocyte\\Chondrocytenewlayout_2.graphml"));
        // network.loadYEdFile(new File("I:\\realnetworks\\Arabidopsis thaliana root stem cell niche\\updates.graphml"));
        // network = ImportYeast.yeastNetwork();
        // network.loadYEdFile(new File("I:\\Naseem\\naseem6 with loops Paper Layout.graphml"));
        // network.loadYEdFile(new
        // File("I:\\realnetworks\\Thaliana\\Arabidopsis Floral Organ Fate Determination 2010 Real Boolean Functions.graphml"));
        // network.loadYEdFile(new File("I:\\realnetworks\\Fission yeast cell cycle\\Figure1corrected.graphml"));

        SSSSearchParameters parameters = new StandardSSSSearchParameters(new SQUADMethod(), 0.05);
        ConvergenceComparator comparator = new ConvergenceComparator(1, parameters); // SPEED
        int dcOuterSimulations = 1; // SPEED
        int dcInnerSimulations = 1; // SPEED

//        for (int i = 0; i < network.nodeCount(); i++) {
////            System.out.println(network.getNetworkNodes()[i].getSQUADSteepness());
//             network.getNetworkNodes()[i].setSQUADSteepness(50); // Führt zu Foxp3 verlust
//
//        }

//        RandomSearcher searcher = new RandomSearcher();
//        SSSSearchResult result = searcher.searchSSStates(network, 1000, parameters);
//        for (int i = 0; i < result.getCounter().size(); i++) {
//            System.out.print(result.getCounter().get(i) + ": ");
//            System.out.println(Arrays.toString(result.getResults().get(i)));
//        }
//
//        System.out.println(Arrays.toString(network.getNodeNames()));

//         System.out.println("\n\n== VC on RESISTANCE  ==");
//         int target = network.getNodeIndexByName("RESISTANCE");
//         double[][] matrixVC = FunctionsAnalysis.totalCentralityMatrix(network, comparator);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(matrixVC[i][target]));
//         }
        
//         int source = network.getNodeIndexByName("IL6");
//         int target = network.getNodeIndexByName("IL17");
//        
//         double[][] result = FunctionsAnalysis.totalCentralityMatrix(network, comparator);
//         System.out.println(result[source][target]);
//         for (int i = 0; i < result.length; i++) {
//         System.out.println(result[i][target]);
//         }
         
//         System.out.println("== TC of the inputs ==");
//         for (NetworkInput input : network.getInputs()) {
//         double influence = FunctionsAnalysis.totalCentrality(network, input, comparator);
//         System.out.print(",{" + network.getInputString(input) + "," + math(influence) + "}");
//         }
//        
//         System.out.println("\n\n== VC of the inputs ==");
//         for (NetworkInput input : network.getInputs()) {
//         double influence = FunctionsAnalysis.nonDynamicCentrality(network, input, comparator.getSimulations(), parameters);
//         System.out.print(",{" + network.getInputString(input) + "," + math(influence) + "}");
//         }
//        
//         System.out.println("\n\n== DC of the inputs ==");
//         for (NetworkInput input : network.getInputs()) {
//         double influence = FunctionsAnalysis.dynamicCentrality(network, input, dcOuterSimulations, dcInnerSimulations, parameters);
//         System.out.print(",{" + network.getInputString(input) + "," + math(influence) + "}");
//         }
//        
//         System.out.println("\n\n== TC of the nodes ==");
//         double[][] matrixTC = FunctionsAnalysis.totalCentralityMatrix(network, comparator);
//         double[] tcCentralities = FunctionsAnalysis.centralitiesFromMatrix(matrixTC);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(tcCentralities[i]));
//         }
//        
//         System.out.println("\n\n== TC-sensitivities of the nodes ==");
//         double[] tcSensitivities = FunctionsAnalysis.sensitivitiesFromMatrix(matrixTC);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(tcSensitivities[i]));
//         }
//        
//         System.out.println("\n\n== VC of the nodes ==");
//         double[][] matrixVC = FunctionsAnalysis.nonDynamicCentralityMatrix(network, comparator.getSimulations(), parameters);
//         double[] vcCentralities = FunctionsAnalysis.centralitiesFromMatrix(matrixVC);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(vcCentralities[i]));
//         }
//        
//         System.out.println("\n\n== VC-sensitivities of the nodes ==");
//         double[] vcSensitivities = FunctionsAnalysis.sensitivitiesFromMatrix(matrixVC);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(vcSensitivities[i]));
//         }
//        
//         System.out.println("\n\n== DC of the nodes ==");
//         double[] dcCentralities = FunctionsAnalysis.dynamicCentralities(network, dcOuterSimulations, dcInnerSimulations, parameters);
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.print(", \"" + network.getNodeNames()[i] + "\", " + math(dcCentralities[i]));
//         }
//        
         System.out.println("\n\n== Positions ==");
         final double SCALE = 120;
         for (int i = 0; i < network.getNetworkNodes().length; i++) {
         NetworkNode node = network.getNetworkNodes()[i];
         System.out.print(", \"" + network.getNodeNames()[i] + "\" -> {" + math(node.getRectangle().getX() / SCALE) + ", "
         + math(node.getRectangle().getY() / SCALE) + "}");
         }
//        
//         System.out.println("\n\n== Inhibiting ==");
//         for (NetworkInput input : network.getInputs()) {
//         if (!((ActivatorInhibitorFunction) network.getNetworkNodes()[input.getNode()].getFunction()).getActivators()[input.getInput()]) {
//         System.out.print(", " + "{" + network.getInputString(input, ", ") + "}");
//         }
//         }
//        
//         System.out.println("\n\n== Table ==");
//         System.out.println("nodes name\ttc\tvc\tdc\ttc-sensitivity\tvc-sensitivity\toutgoing\tincoming\tloop");
//         for (int i = 0; i < network.getNetworkNodes().length; i++) {
//         System.out.println(network.getNodeNames()[i] + "\t" + tcCentralities[i] + "\t" + vcCentralities[i] + "\t" + dcCentralities[i]
//         + "\t" + tcSensitivities[i] + "\t" + vcSensitivities[i] + "\t" + network.getInputsBySource(i).size() + "\t"
//         + network.getInputsByTarget(i).size() + "\t" + network.hasLoop(i));
//         }
    }

    public static String math(double input) {
        return (String.valueOf(input)).replaceAll("E", "\\*^");
    }
}
