Skip to content

Commit

Permalink
simulation ready! ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbuzatto committed Oct 7, 2023
1 parent 2a8fc2e commit 7034277
Show file tree
Hide file tree
Showing 25 changed files with 344 additions and 39 deletions.
6 changes: 2 additions & 4 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
Finite Automata
Highlight inacessible states (properties panel)
Highlight nondeterminisms (properties panel)

Regular Expressions
Here: https://resources.wolframcloud.com/PacletRepository/resources/KlausSutner/Automata/

Pushdown Automata
Final State to Empty Stack and vice-versa
Simulation
Final State to Empty Stack and vice-versa?
PDA to CFGs?

Turing Machines

Expand Down
16 changes: 12 additions & 4 deletions src/main/java/br/com/davidbuzatto/yaas/gui/DrawPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ protected void paintComponent( Graphics g ) {

}

// TODO update for PDA simulation (depends on accepts and instantaneous description)
if ( simulationString != null ) {
if ( faSimulationSteps != null ) {
processFASimulation( g2d );
Expand Down Expand Up @@ -228,10 +227,19 @@ private void processPDASimulation( Graphics2D g2d ) {
int ySimulationString = y2R - height / 2 - 10;
char[] cs = simulationString.toCharArray();
int i;


int currentSymbolIndex = 0;
for ( int k = 0; k < currentSimulationStep; k++ ) {
int str1Length = pdaSimulationSteps.get( k ).getId().getString().length();
int str2Length = pdaSimulationSteps.get( k+1 ).getId().getString().length();
if ( str1Length != str2Length ) {
currentSymbolIndex++;
}
}

for ( i = 0; i < cs.length; i++ ) {

if ( i == currentSimulationStep ) {
if ( i == currentSymbolIndex ) {
g2d.setColor( DrawingConstants.SYMBOL_ACTIVE_IN_SIMULATION_BACKGROUND_COLOR );
g2d.fillRoundRect( start + inc * i - 2,
ySimulationString - height / 2 - 4,
Expand All @@ -242,7 +250,7 @@ private void processPDASimulation( Graphics2D g2d ) {
ySimulationString - height / 2 - 4,
inc + 3,
height / 2 + 8, 10, 10 );
} else if ( i < currentSimulationStep ) {
} else if ( i < currentSymbolIndex ) {
g2d.setColor( DrawingConstants.SIMULATION_STRING_PROCESSED_COLOR );
} else {
g2d.setColor( DrawingConstants.SIMULATION_STRING_NON_PROCESSED_COLOR );
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/br/com/davidbuzatto/yaas/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,7 @@ public void run() {

private void openExample() {
if ( ApplicationConstants.IN_DEVELOPMENT ) {
//createFAInternalFrame( FAExamples.createDFAEndsWith00(), true, true );
//createPDAInternalFrame( PDAExamples.createPDAEvenPalindromeFinalState(), true, true );
//createPDAInternalFrame( PDAExamples.createDPDAEvenPalindromeCenterMark(), true, true );


createPDAInternalFrame( PDAExamples.createPDA01FinalState(), true, true );

createPDAInternalFrame( PDAExamples.createPDA0n1nFinalState(), true, true );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<Component id="btnResetStatesColor" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnResetTransitionsColor" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="118" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(btnResetStatesColor)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnResetTransitionsColor)
.addContainerGap(118, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FAStatePropertiesPanel extends javax.swing.JPanel {
private FAState state;

/**
* Creates new form StatePropertiesPanel
* Creates new form FAStatePropertiesPanel
*/
public FAStatePropertiesPanel( FAInternalFrame faIFrame ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class FATransitionPropertiesPanel extends javax.swing.JPanel {


/**
* Creates new form TransitionPropertiesPanel
* Creates new form FATransitionPropertiesPanel
*/
public FATransitionPropertiesPanel( FAInternalFrame faIFrame ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="Batch Test"/>
<Property name="iconImage" type="java.awt.Image" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="default"/>
</Property>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PDABatchTest extends javax.swing.JDialog {
private PDA pda;

/**
* Creates new form FABatchTest
* Creates new form PDABatchTest
*/
public PDABatchTest( Frame parent, PDAInternalFrame pdaIFrame, PDAAcceptanceType acceptanceType, boolean modal ) {
super( parent, modal );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PDAFormalDefinitionDialog extends javax.swing.JDialog {
private PDA pda;

/**
* Creates new form FAFormalDefinitionDialog
* Creates new form PDAFormalDefinitionDialog
*/
public PDAFormalDefinitionDialog( java.awt.Frame parent, boolean modal, PDA pda ) {
super( parent, modal );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="0"/>
<Property name="title" type="java.lang.String" value="Simulation ID Viewer"/>
<Property name="iconImage" type="java.awt.Image" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new javax.swing.ImageIcon( getClass().getResource( &quot;/arrow_right.png&quot; ) ).getImage()" type="code"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="true"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scrollDrawPanel" alignment="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scrollDrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="scrollDrawPanel">

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Container class="br.com.davidbuzatto.yaas.gui.pda.PDAIDViewerDrawPanel" name="drawPanel">

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="798" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="598" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (C) 2023 Prof. Dr. David Buzatto
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package br.com.davidbuzatto.yaas.gui.pda;

import br.com.davidbuzatto.yaas.model.pda.PDA;
import br.com.davidbuzatto.yaas.model.pda.PDAID;
import br.com.davidbuzatto.yaas.util.Utils;
import java.util.List;

/**
* A viewer of a ID tree for the simulation proccess.
*
* @author Prof. Dr. David Buzatto
*/
public class PDAIDSimulationViewerFrame extends javax.swing.JFrame {

private int currentSimulationStep;
private PDAInternalFrame pdaIFrame;
private PDA pda;
List<PDASimulationStep> simulationSteps;

/**
* Creates new form PDAIDSimulationViewerFrame
*/
public PDAIDSimulationViewerFrame(
PDAInternalFrame pdaIFrame,
PDA pda,
List<PDASimulationStep> simulationSteps ) {

this.pdaIFrame = pdaIFrame;
this.pda = pda;
this.simulationSteps = simulationSteps;

initComponents();
setLocationRelativeTo( pdaIFrame );
setAlwaysOnTop( true );

drawPanel.setPda( pda );
drawPanel.arrangeAndProccessIdsForSimulation( simulationSteps );
drawPanel.repaint();
drawPanel.revalidate();

setCurrentSimulationStep( currentSimulationStep );

}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings( "unchecked" )
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

scrollDrawPanel = new javax.swing.JScrollPane();
drawPanel = new br.com.davidbuzatto.yaas.gui.pda.PDAIDViewerDrawPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Simulation ID Viewer");
setIconImage(new javax.swing.ImageIcon( getClass().getResource( "/arrow_right.png" ) ).getImage());
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

javax.swing.GroupLayout drawPanelLayout = new javax.swing.GroupLayout(drawPanel);
drawPanel.setLayout(drawPanelLayout);
drawPanelLayout.setHorizontalGroup(
drawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 798, Short.MAX_VALUE)
);
drawPanelLayout.setVerticalGroup(
drawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 598, Short.MAX_VALUE)
);

scrollDrawPanel.setViewportView(drawPanel);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollDrawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollDrawPanel, javax.swing.GroupLayout.Alignment.TRAILING)
);

pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
Utils.showInformationMessage( this, "This window will close automatically when you stop the simulation." );
}//GEN-LAST:event_formWindowClosing

public void setCurrentSimulationStep( int currentSimulationStep ) {
this.currentSimulationStep = currentSimulationStep;
for ( PDASimulationStep step : simulationSteps ) {
step.getId().setActiveInSimulation( false );
}
for ( int i = 0; i <= currentSimulationStep; i++ ) {
simulationSteps.get( i ).getId().setActiveInSimulation( true );
}
drawPanel.repaint();
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private br.com.davidbuzatto.yaas.gui.pda.PDAIDViewerDrawPanel drawPanel;
private javax.swing.JScrollPane scrollDrawPanel;
// End of variables declaration//GEN-END:variables
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,20 @@ public void arrangeAndProccessIds() {

}

public void arrangeAndProccessIdsForSimulation( List<PDASimulationStep> simulationSteps ) {

ids = new ArrayList<>();
for ( PDASimulationStep step : simulationSteps ) {
ids.add( step.getId() );
}

root = ids.get( 0 );
lines = new ArrayList<>();

size = PDAArrangement.arrangeIDsInTreeFormatForSimulation(
root, ids, lines, 30, 40, 60, 20 );
setPreferredSize( new Dimension( size.width + 60, size.height + 70 ) );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scrollDrawPanel" alignment="0" pref="800" max="32767" attributes="0"/>
<Component id="scrollDrawPanel" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scrollDrawPanel" alignment="1" pref="600" max="32767" attributes="0"/>
<Component id="scrollDrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PDAIDViewerFrame extends javax.swing.JFrame {
/**
* Creates new form PDAIDViewerFrame
*/
public PDAIDViewerFrame( PDAInternalFrame pdaIFrame, PDA pda, boolean modal ) {
public PDAIDViewerFrame( PDAInternalFrame pdaIFrame, PDA pda ) {

this.pdaIFrame = pdaIFrame;
this.pda = pda;
Expand Down
Loading

0 comments on commit 7034277

Please sign in to comment.