diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 992f8f7..4a14937 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,16 +4,8 @@
-
-
-
-
-
-
+
-
-
-
@@ -22,7 +14,7 @@
@@ -43,49 +35,6 @@
"second": "2afc8825-f511-4d8a-8cc1-901875567c84"
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -103,7 +52,7 @@
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"full.screen.before.presentation.mode": "false",
- "git-widget-placeholder": "main",
+ "git-widget-placeholder": "5-top-skill-issue-raphael",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
@@ -113,11 +62,11 @@
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
- "settings.editor.selected.configurable": "preferences.pluginManager",
+ "settings.editor.selected.configurable": "preferences.lookFeel",
"vue.rearranger.settings.migration": "true"
}
}]]>
-
+
@@ -135,6 +84,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -186,11 +152,11 @@
-
+
+
-
@@ -212,6 +178,7 @@
+
@@ -221,7 +188,55 @@
1704734947115
-
+
+
+ 1704749802065
+
+
+
+ 1704749802065
+
+
+
+ 1704749806556
+
+
+
+ 1704749806556
+
+
+
+ 1704749811525
+
+
+
+ 1704749811525
+
+
+
+ 1704750289780
+
+
+
+ 1704750289780
+
+
+
+ 1704752332678
+
+
+
+ 1704752332678
+
+
+
+ 1704752420737
+
+
+
+ 1704752420737
+
+
@@ -230,26 +245,19 @@
-
+
+
+
+
-
- file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java
- 171
-
-
file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java
15
-
- file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
- 347
-
-
diff --git a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
index 03d74d2..a12af3e 100644
--- a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
+++ b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
@@ -3,16 +3,15 @@ package ab1.impl.GRUPPE;
import ab1.FinalizedStateException;
import ab1.NFA;
import ab1.Transition;
-import lombok.Getter;
import java.util.*;
public class NFAImpl implements NFA {
- private Set states;
- private Set transitions;
+ private final Set states;
+ private final Set transitions;
- private String initialState;
- private Set acceptingStates;
+ private final String initialState;
+ private final Set acceptingStates;
private Set alphabet;
@@ -25,6 +24,10 @@ public class NFAImpl implements NFA {
this.transitions = new HashSet<>();
this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>();
+ Set completeAlphabet = new HashSet<>();
+ for (char ch = 'a'; ch <= 'z'; ch++) {
+ completeAlphabet.add(ch);
+ }
this.isFinalized = false;
}
@@ -34,11 +37,13 @@ public class NFAImpl implements NFA {
return this.states;
}
+ /*
public void safeAddStates(Set states, Set toCheck, NFAImpl nfa) {
for (String state : states) {
nfa.states.add(changeIfNecessary(state, toCheck));
}
}
+ */
@Override
public Collection getTransitions() {
@@ -211,28 +216,55 @@ public class NFAImpl implements NFA {
return intersectionNFA;
}
- // #TODO
@Override
public NFA concatenation(NFA other) throws FinalizedStateException {
if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
+
NFAImpl concatenationNFA = new NFAImpl(this.initialState);
+ // Add states from 'this'
concatenationNFA.states.addAll(this.states);
- concatenationNFA.states.addAll(other.getStates());
+ // Add states from 'other', with renaming if necessary
+ Map renamedStates = new HashMap<>();
+ for (String state : other.getStates()) {
+ String newState = changeIfNecessary(state, concatenationNFA.states);
+ renamedStates.put(state, newState); // Old state name -> New state name
+ concatenationNFA.states.add(newState);
+ }
+
+ // Add transitions from 'this'
concatenationNFA.transitions.addAll(this.transitions);
- concatenationNFA.transitions.addAll(other.getTransitions());
- for (String accceptingState : this.acceptingStates) {
- Transition epsilon = new Transition(accceptingState, null, other.getInitialState());
+ // Add transitions from 'other', updating state names
+ for (Transition transition : other.getTransitions()) {
+ String newFromState = renamedStates.getOrDefault(transition.fromState(), transition.fromState());
+ String newToState = renamedStates.getOrDefault(transition.toState(), transition.toState());
+ Transition newTransition = new Transition(newFromState, transition.readSymbol(), newToState);
+ concatenationNFA.transitions.add(newTransition);
+ }
+
+ // Connect accepting states of 'this' to the initial state of 'other' with epsilon transitions
+ String newOtherInitialState = renamedStates.getOrDefault(other.getInitialState(), other.getInitialState());
+ for (String acceptingState : this.acceptingStates) {
+ Transition epsilon = new Transition(acceptingState, null, newOtherInitialState);
concatenationNFA.transitions.add(epsilon);
}
+ // Set accepting states of the concatenated NFA to be the accepting states of 'other'
+ concatenationNFA.acceptingStates.clear();
+ for (String acceptingState : other.getAcceptingStates()) {
+ concatenationNFA.acceptingStates.add(renamedStates.getOrDefault(acceptingState, acceptingState));
+ }
+
+ concatenationNFA.finalizeAutomaton();
+
return concatenationNFA;
}
+
@Override
public NFA kleeneStar() throws FinalizedStateException {
if (!this.isFinalized) {
@@ -256,6 +288,7 @@ public class NFAImpl implements NFA {
nfa.transitions.add(loopBackTransition);
}
+ nfa.finalizeAutomaton();
return nfa;
}
@@ -293,6 +326,8 @@ public class NFAImpl implements NFA {
}
*/
+ nfa.finalizeAutomaton();
+
return nfa;
}
@@ -314,15 +349,15 @@ public class NFAImpl implements NFA {
// state -> accepting
// accepting -> state
- Set newAcceptingstate = new HashSet<>();
+ Set newAcceptingState = new HashSet<>();
for (String state : fakeNFA.getStates()) {
if (!fakeNFA.getAcceptingStates().contains(state)) {
- newAcceptingstate.add(state);
+ newAcceptingState.add(state);
}
}
fakeNFA.acceptingStates.clear();
- fakeNFA.addAllAcceptingStates(newAcceptingstate);
+ fakeNFA.addAllAcceptingStates(newAcceptingState);
Set originalAlphabet = new HashSet<>(fakeNFA.alphabet);
@@ -388,6 +423,8 @@ public class NFAImpl implements NFA {
currentStates = epsilonClosure(currentStates, this);
}
+
+
return isAcceptingState(currentStates, this);
}
diff --git a/target/classes/ab1/impl/GRUPPE/NFAImpl.class b/target/classes/ab1/impl/GRUPPE/NFAImpl.class
index a9e53a8..b98f6e4 100644
Binary files a/target/classes/ab1/impl/GRUPPE/NFAImpl.class and b/target/classes/ab1/impl/GRUPPE/NFAImpl.class differ