Package eas.math.fundamentalAlgorithms.graphBased.pdfProcessors

Examples of eas.math.fundamentalAlgorithms.graphBased.pdfProcessors.GraphViz


    public static void extractPDF(
            final String datNam,
            final EndlicherAutomat aut,
            final ParCollection params,
            final String graphVizTempDir) {
        GraphViz gv = generateGraphViz(aut, params, graphVizTempDir);
       
        String type = "pdf";
        File out = new File(params.getStdDirectory() + "/" + datNam + "." + type);
        params.logInfo("Extracting PDF to '" + out + "'.");
       
        gv.writeGraphToFile(gv.getGraph( gv.getSourceString(), type ), out);
    }
View Full Code Here


        gv.writeGraphToFile(gv.getGraph( gv.getSourceString(), type ), out);
    }

    public static GraphViz generateGraphViz(final EndlicherAutomat aut,
            final ParCollection params, final String graphVizTempDir) {
        GraphViz gv = new GraphViz(graphVizTempDir);
        gv.addln(gv.startDigraph());
//        gv.addln("rankdir=LR;");
  
        // Startzustand.
        //node0 [ label ="<f0> | <f1> J | <f2> "];
       
        gv.addln("node [shape = diamond];");
       
        if (aut.holeStartzustand() != null) {
            gv.addln("node"
                    + aut.holeStartzustand().holeName()
                    + " [label=\""
                    + aut.holeStartzustand().getKnotenBeschriftungForGraphviz(params)
                    + "\"];");
        }
       
        gv.addln("node [shape = ellipse];");
       
        for (int kname1 : aut.getKnList()) {
            // Knoten.
            Knoten k1 = aut.holeKnoten(kname1);
           
            if (aut.holeStartzustand() == null || aut.holeStartzustand().holeName() != kname1) {
                gv.addln("node"
                        + kname1
                        + " [label=\""
                        + k1.getKnotenBeschriftungForGraphviz(params)
                        + "\"];");
            }
           
            // Kanten.
            int i = 0;
            for (Transition t : k1.getInfo().getBedingungen()) {
                i++;
                Knoten k2 = aut.holeKnoten(t.getFolgezustand());
                gv.addln("\"node" + k1.holeName() + "\" -> \"node" + k2.holeName() + "\" [label=\"(" + i + ") " + t.getCond() + "\"];");
            }
        }
       
        gv.addln(gv.endGraph());
        return gv;
    }
View Full Code Here

        return i;
    }
   
    private void createPDFFromCurrentState(String datnam, int i, String tempDir) {
        this.dontSimplifyToFinalOnGVGeneration = true;
        GraphViz gv = this.generatePDFcode(tempDir);
        this.dontSimplifyToFinalOnGVGeneration = false;
       
        String realName = datnam;
        realName += "-" + i;
       
        try {
            gv.storeAsPDF(realName, tempDir);
        } catch (Exception e) {
        }
    }
View Full Code Here

    @Override
    public GraphViz generatePDFcode(String pdfPath) {
        if (!dontSimplifyToFinalOnGVGeneration) {
            this.simplifyToFinal();
        }
        GraphViz gv;
        gv = new GraphViz(pdfPath);
       
        gv.addln(gv.startDigraph());
       
        List<String> instructions = this.getGraphVizInstructions();
       
        LinkedList<String> inst0 = new LinkedList<String>();
        LinkedList<String> inst1 = new LinkedList<String>();
        LinkedList<String> inst01 = new LinkedList<String>();
       
        for (String line : instructions) {
            if (line.contains("[label=\" 0 \"]")) {
                inst0.add(line);
            } else if (line.contains("[label=\" 1 \"]")) {
                inst1.add(line);
            } else if (line.contains("[label=\" 0/1 \"]")) {
                inst01.add(line);
            } else {
                gv.addln(line);
            }
        }
  
        // Sortiere 0- und 1-Kanten.
        for (String line : inst0) {gv.addln(line);}
        for (String line : inst1) {gv.addln(line);}
        for (String line : inst01) {gv.addln(line);}
       
        gv.addln(gv.endGraph());

        return gv;
    }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    @Override
    public GraphViz generatePDFcode(String pdfPath) {
        GraphViz gv = new GraphViz(pdfPath);
       
        try {
            gv.addln("digraph G {");

            if (this.isDeterministic()) {
                for (int j = 0; j < this.tapes.length; j++) {
                    this.initialize();
                    this.input = this.tapes[j];
                   
                    int i = 1;
                    Trace trace = this.simulateDeterministic();
                    gv.addln("a" + j + " [shape=boxed, label=\"");
                    for (TraceElement el : trace) {
                        try {
                            gv.addln("("
                                    + i
                                    + ")  "
                                    + StaticMethodsKA.printInputWithHead(el.getHeadPos(), this.input)
                                    + "  ||  "
                                    + el.getKeller()
                                    + "  ||  "
                                    + (el.getTransition() + "").toString().replace(
                                            "=>", " =\\> ") + "\\n");
                        } catch (Exception e) {
                            gv.addln("accepted");
                        }
                        i++;
                    }
                    gv.addln("\"]");
                }
            } else {
                this.simulateNonDeterministic(gv);
            }

            gv.addln("};");
            this.input = this.tapes[0];
        } catch (Exception e) {
            e.printStackTrace();
        }
       
View Full Code Here

    }

    @Override
    public GraphViz generatePDFcode(String pdfPath) {
        this.quiet = true;
        GraphViz gv = new GraphViz(pdfPath);
       
        gv.addln("digraph G {");

        if (this.isDeterministic()) {
            for (int j = 0; j < this.tapes.length; j++) {
                this.tape = this.tapes[j];
                int i = 1;
                Trace trace = this.runDeterministic(this.runStepsScript);
                gv.addln("a" + j + " [shape=boxed, label=\"");
                for (TraceElement el : trace) {
                    if (el.getNum() != i) {
                        gv.addln("...\\n");
                    }
                   
                    i = el.getNum() + 1;
                   
                    String transition = ("" + el.getTransition()).toString(); // Lass das "" stehen, du Esel!
                    gv.addln("(" + el.getNum() + ")  " + this.printTapeWithHead(el.getTapeContents()) + "  ||  " + transition.replace("=>", " =\\> ") + "\\n");
//                    i++;
                }
                gv.addln("\"];");
            }
        } else { // Use only tapes[0];
            this.tape = this.tapes[0];
            this.runNondeterministic(this.runStepsScript, gv);
        }

        gv.addln("};");
       

        this.tape = this.tapes[0];
        this.quiet = false;
        return gv;
View Full Code Here

                            // Ask for very long graphs.
                            if (pdfProcessor.getSourceString().length() > pdfProcessor.getCodeSizeToBeConsideredLarge() && !GeneralDialog.yesNoAnswer(
                                    "Large pdf processor code (greater than " + pdfProcessor.getCodeSizeToBeConsideredLarge() + " characters)",
                                    "The current script leads to a " + pdfProcessor.getClass().getSimpleName() + " code that has " + pdfProcessor.getSourceString().length() + " characters.\n"
                                    + "It might take " + pdfProcessor.getClass().getSimpleName() + " a long time to draw. Proceed?")) {
                                pdfProcessor = new GraphViz(TEMP_DIR.getAbsolutePath());
                                pdfProcessor.addln("digraph G {User aborted...}");
                            }

                            pdfProcessor.storeAsPDF("graph", GeneralDialog.promptForExternalFile(
                                    "TEMP-DIRECTORY",
View Full Code Here

                    transit.add(new Transition(true, s1, s2, newTransSymb));
                }
            }
        }
       
        GraphViz gv = new GraphViz(pdfPath);
       
        String label;
        String edgeSymbol;
       
        if (transit.size() == 0 || transit.get(0).isDirected()) {
            if (completeOutput) println("Directed graph.");
            gv.addln(gv.startDigraph());
            edgeSymbol = GraphViz.edgeSymbolDirected;
        } else {
            if (completeOutput) println("Undirected graph.");
            gv.addln(gv.startGraph());
            edgeSymbol = GraphViz.edgeSymbolUnDirected;
        }
       
        gv.addln("rankdir=LR;");
//      gv.addln("ranksep=0.12;");
//      gv.addln("splines=ortho;");
//      gv.addln("decorate=true;");
       
        // Count states.
        HashSet<String> set = new HashSet<String>();
        set.add(initialState);
        for (String s : finalStates) {
            set.add(s);
        }
        for (String s : singleStates) {
            set.add(s);
        }
        for (Transition t : transit) {
            set.add(t.getSource());
            set.add(t.getDestination());
        }
        LinkedList<String> list = new LinkedList<String>(set);
        Collections.sort(list);
        if (completeOutput) println("States (" + set.size() + "): " + list);
       
        // Non-labelled states.
        HashSet<String> nonLabelled = new HashSet<String>();
        for (String s : set) {
            if (optionalLabelMapping == null || !optionalLabelMapping.containsKey(s)) {
                nonLabelled.add(s);
            }
        }
       
        // Additional lines.
        for (String s : additionalLinesForFSM) {
            gv.addln(s);
        }
       
        // Initial state.
        if (completeOutput) println("Initial state: " + initialState);
        gv.addln("node [shape = point ]; qi");
        if (finalStates.contains(initialState)) { // Initial state is final state.
            gv.addln("node [shape = doublecircle];");
        } else {
            gv.addln("node [shape = circle];");
        }
       
        if (optionalLabelMapping == null || optionalLabelMapping.get(initialState) == null) {
            label = initialState;
        } else {
            label = optionalLabelMapping.get(initialState);
        }

        gv.addln("qi " + edgeSymbol + " " + initialState + ";");
        gv.addln(initialState + "[label=" + label + "];");

        // Single States.
        if (completeOutput) println("Single states (" + singleStates.size() + "): " + singleStates);
        gv.addln("node [shape = circle];");
        for (String s : singleStates) {
            if (optionalLabelMapping == null || optionalLabelMapping.get(s) == null) {
                label = s;
            } else {
                label = optionalLabelMapping.get(s);
            }
            gv.addln(s + "[label=" + label + "];");
        }
       
        // Final states.
        if (completeOutput) println("Final states (" + finalStates.size() + "): " + finalStates);
        gv.addln("node [shape = doublecircle];");
        for (String s : finalStates) {
            if (optionalLabelMapping == null || optionalLabelMapping.get(s) == null) {
                label = s;
            } else {
                label = optionalLabelMapping.get(s);
            }
            gv.addln(s + "[label=" + label + "];");
        }
       
        gv.addln("node [shape = circle];");

        // Transitions.
        if (completeOutput) println("Transitions (" + transit.size() + "): " + transit);
        for (Transition t : transit) {
            String s1 = t.getSource();
            String s2 = t.getDestination();
           
            if (optionalLabelMapping == null || optionalLabelMapping.get(s1) == null) {
                label = s1;
            } else {
                label = optionalLabelMapping.get(s1);
            }
            gv.addln(s1 + "[label=" + label + "];");

            if (optionalLabelMapping == null || optionalLabelMapping.get(s2) == null) {
                label = s2;
            } else {
                label = optionalLabelMapping.get(s2);
            }
            gv.addln(s2 + "[label=" + label + "];");
            gv.addln(t.toString());
        }

        gv.addln(gv.endGraph());

        if (completeOutput) println("Not explicitly labelled states (" + nonLabelled.size() + "): " + nonLabelled);

//        try {
//            gv.storeGraphViz(datNam, pdfPath);
View Full Code Here

        println("\n% Script (nondet): \n" + this.createFSMScriptString().replace("\n", "\n% "));
       
        if (this.isDeterministic()) {
            println("% Automaton is already deterministic (storing only once).");
        } else {
            GraphViz gv = this.generateGVcode(pdfPath, mapping, false);         // Speichere Graph.
            gv.storeAsPDF(filename1, pdfPath);
            println("% Power set construction of deterministic automaton:");
            this.makeDeterministic();                                       // Erzeuge deterministische Version und gib Tabelle aus.
        }
       
        sizeDet = this.getAllStates().size();
       
        if (this.isMinimal()) {
            println("%\n% Automaton is already minimal (storing only once).");
        } else {
            GraphViz gv = this.generateGVcode(pdfPath, mapping, false);         // Speichere Graph.
            gv.storeAsPDF(filename2, pdfPath);
            println("% Deterministic state transition table:");
            this.printTransitionTableLatex();                               // Gib deterministische Transitionstabelle aus.
            println("\n% Script (det): \n" + this.createFSMScriptString().replace("\n", "\n% "));
        }

        HashMap<StatePair, ?> map = this.minimize();

        println("%\n% Minimization table:");
        if (map.size() > 0) {
            this.printTriangleTableLaTeX(map); // Minimiere und gib Tabelle aus.
        } else {
            println("% Do you really need help with this trivial table (hint: just make it all empty...)?");
        }
   
        sizeMin = this.getAllStates().size();
        GraphViz gv = this.generateGVcode(pdfPath, mapping, false);         // Speichere Graph.
        gv.storeAsPDF(filename3, pdfPath);
        println("% Minimized state transition table:");
        this.printTransitionTableLatex();                               // Gib minimierte Transitionstabelle aus.
        println("%\n% Script (detmin): \n" + this.createFSMScriptString().replace("\n", "\n% "));
       
        println("%\n% States (plain / det / min): " + sizePlain + " / " + sizeDet + " / " + sizeMin);
View Full Code Here

        if (!new File(pdfPath).exists()) {
            new File(pdfPath).mkdir();
            System.out.println("Directory " + pdfPath + " created.");
        }
       
        GraphViz gv = new GraphViz(pdfPath);

        gv.add(gv.startDigraph());
       
        for (String s : instructions) {
            gv.addln(s);
        }
       
        gv.add(gv.endGraph());
       
        return gv;
    }
View Full Code Here

TOP

Related Classes of eas.math.fundamentalAlgorithms.graphBased.pdfProcessors.GraphViz

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.