Attempt fix equals

This commit is contained in:
2017-06-13 11:05:56 +02:00
parent 175010c9bc
commit 5b8004d656
8 changed files with 98 additions and 27 deletions
-6
View File
@@ -1,6 +0,0 @@
DFA
B0
E1
0>a>1
1>a>2
2>a>2
-6
View File
@@ -1,6 +0,0 @@
DFA
B0
E1
0>b>1
1>b>2
2>b>2
-8
View File
@@ -1,8 +0,0 @@
NDFA
Bq1
Eq6
q1>ε>q2
q2>ε>q3
q3>ε>q4
q4>ε>q5
q5>a>q6
+10 -4
View File
@@ -117,20 +117,26 @@ public class Automata <T extends Comparable> extends Importable {
if(!(obj instanceof Automata))
return false;
if(this.type != ((Automata<T>)obj).type)
return false;
Automata<T> other = (Automata<T>) obj;
DFA<String> dfa1;
DFA<String> dfa2;
if(this.type == Type.NDFA)
{
dfa1 = ((NDFA<T>)this).toDFA().minimaliseerHopcroft();
dfa2 = ((NDFA<T>) obj).toDFA().minimaliseerHopcroft();
dfa1 = ((NDFA<String>)this).toDFA().minimaliseerHopcroft();
}
else
{
dfa1 = ((DFA<String>)this).minimaliseerHopcroft();
}
if(other.type == Type.NDFA)
{
dfa2 = ((NDFA<String>) obj).toDFA().minimaliseerHopcroft();
}
else
{
dfa2 = ((DFA<String>) obj).minimaliseerHopcroft();
}
+21 -1
View File
@@ -100,6 +100,26 @@ public class DFA<T extends Comparable> extends Automata<T> {
}
public DFA<T> ontkenning() {
DFA<T> result = new DFA<T>();
for(Transition<T> t : this.transistions)
{
result.addTransition(t);
}
for(T s : this.eindStates)
{
result.defineAsStartState(s);
}
for(T s : this.beginStates)
{
result.defineAsEndState(s);
}
return result;
/*
DFA<T> returnDFA = new DFA<T>();
SortedSet<T> newEndStates = new TreeSet<>();
@@ -122,7 +142,7 @@ public class DFA<T extends Comparable> extends Automata<T> {
returnDFA.addTransition(transistion);
}
return returnDFA;
return returnDFA;*/
}
public DFA<String> en(DFA<T> other)
+1 -1
View File
@@ -108,7 +108,7 @@ public class Graph {
try {
MutableGraph g = Parser.read(Graph.generateImageString(a));
Graphviz.fromGraph(g).width(Math.max(a.states.size() * 150, 750)).render(Format.PNG).toFile(f);
Graphviz.fromGraph(g).width(Math.min(15000, Math.max(a.states.size() * 150, 750))).render(Format.PNG).toFile(f);
} catch (IOException e) {
e.printStackTrace();
}
+66
View File
@@ -321,9 +321,75 @@ public class InputPanel extends JPanel {
}
});
JButton equalsButton = new JButton("equals");
equalsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
BackgroundWorker.instance().addWorker(new BackgroundWorker.Worker() {
@Override
public void execute() {
StatusPanel.Instance().setStatus("Parsing files", 10);
String file1 = (String)f1Combo.getSelectedItem();
String name1 = file1.replaceAll(".dot", "");
String file2 = (String)f2Combo.getSelectedItem();
String name2 = file2.replaceAll(".dot", "");
Importable p1 = FileParser.read(file1);
Importable p2 = FileParser.read(file1);
Automata<String> aut = null;
if(p1.type == Importable.Type.NDFA )
{
aut = (NDFA<String>)p1;
}
if(p1.type == Importable.Type.DFA)
{
aut = (DFA<String>)p1;
}
if(p1.type == Importable.Type.REGEX)
{
StatusPanel.Instance().setStatus("Converting REGEX to NDFA", 30);
RegExp regex = (RegExp) p1;
aut = (NDFA<String>)ThompsonConverter.convert(regex);
}
Automata<String> aut2 = null;
if(p2.type == Importable.Type.NDFA)
{
aut2 = (NDFA<String>)p2;
}
if(p2.type == Importable.Type.DFA)
{
aut2 = (DFA<String>)p2;
}
if(p2.type == Importable.Type.REGEX)
{
StatusPanel.Instance().setStatus("Converting REGEX to NDFA", 50);
RegExp regex2 = (RegExp) p2;
aut2 = (NDFA<String>)ThompsonConverter.convert(regex2);
}
StatusPanel.Instance().setStatus("Executing equals operation", 80);
boolean equals = aut.equals(aut2);
new TextPanel(name1 + " equals " + name2, (equals?"They are equal":"They are not equal"));
StatusPanel.Instance().setStatus("Done", 100);
}
});
}
});
advPanel.add(f1Combo);
advPanel.add(Box.createRigidArea(new Dimension(10, 0)));
advPanel.add(equalsButton);
advPanel.add(Box.createRigidArea(new Dimension(10, 0)));
advPanel.add(andButton);
advPanel.add(Box.createRigidArea(new Dimension(10, 0)));
advPanel.add(orButton);
-1
View File
@@ -1,7 +1,6 @@
package com.imegumii.ui;
import com.imegumii.*;
import com.sun.tools.internal.ws.wsdl.document.Import;
import javax.swing.*;
import javax.swing.border.Border;