Skip to content

Commit

Permalink
Added prototype of Hellings algo implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorFilimonov committed May 7, 2024
1 parent 8d8e8ea commit 2860594
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import automaton.constructor.model.automaton.PushdownAutomaton
import automaton.constructor.model.element.*
import automaton.constructor.view.algorithms.HellingsAlgoExecutionView
import automaton.constructor.view.algorithms.HellingsAlgoInputView
import tornadofx.Controller
import tornadofx.observableListOf
import tornadofx.*

class HellingsTransition(
val nonterminal: Nonterminal,
Expand Down Expand Up @@ -51,6 +50,50 @@ class HellingsAlgoController(
HellingsAlgoExecutionView::r to r
))
hellingsAlgoExecutionWindow.openWindow()

hellingsAlgoExecutionWindow.nextIterationButton.action {
if (m.isEmpty()) {
hellingsAlgoExecutionWindow.close()
}
val mTransition = m.removeFirst()
val rToAdd = mutableListOf<HellingsTransition>()
do {
r.addAll(rToAdd)
rToAdd.clear()
r.filter {
it.target == mTransition.source
}.forEach { rTransition ->
grammar.productions.filter {
it.rightSide == mutableListOf(rTransition.nonterminal, mTransition.nonterminal)
}.forEach { production ->
if (r.none { it.nonterminal == production.leftSide && it.source == rTransition.source && it.target == mTransition.target } &&
rToAdd.none { it.nonterminal == production.leftSide && it.source == rTransition.source && it.target == mTransition.target }) {
val newTransition = HellingsTransition(production.leftSide, rTransition.source, mTransition.target, false)
m.add(newTransition)
rToAdd.add(newTransition)
}
}
}
} while (rToAdd.isNotEmpty())
do {
r.addAll(rToAdd)
rToAdd.clear()
r.filter {
it.source == mTransition.target
}.forEach { rTransition ->
grammar.productions.filter {
it.rightSide == mutableListOf(mTransition.nonterminal, rTransition.nonterminal)
}.forEach { production ->
if (r.none { it.nonterminal == production.leftSide && it.source == mTransition.source && it.target == rTransition.target } &&
rToAdd.none { it.nonterminal == production.leftSide && it.source == mTransition.source && it.target == rTransition.target }) {
val newTransition = HellingsTransition(production.leftSide, mTransition.source, rTransition.target, false)
m.add(newTransition)
rToAdd.add(newTransition)
}
}
}
} while (rToAdd.isNotEmpty())
}
}

fun getTestGrammar(): ContextFreeGrammar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import automaton.constructor.controller.algorithms.HellingsTransition
import automaton.constructor.model.element.AutomatonVertex
import automaton.constructor.model.element.Nonterminal
import javafx.collections.ObservableList
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.control.ListCell
import javafx.scene.control.ListView
Expand Down Expand Up @@ -34,6 +35,7 @@ class HellingsAlgoExecutionView: View() {
val r: ObservableList<HellingsTransition> by param()
private val mListView = ListView(m).apply { this.setCellFactory { HellingsTransitionCell() } }
private val rListView = ListView(r).apply { this.setCellFactory { HellingsTransitionCell() } }
val nextIterationButton = Button("Next iteration")

override val root = vbox {
hbox {
Expand All @@ -46,6 +48,6 @@ class HellingsAlgoExecutionView: View() {
add(rListView)
}
}
button("Next iteration")
add(nextIterationButton)
}
}

0 comments on commit 2860594

Please sign in to comment.