Skip to content

Commit

Permalink
Adding package structure
Browse files Browse the repository at this point in the history
Also created interface for minimization algorithms
  • Loading branch information
jah12014 committed Apr 2, 2018
1 parent 9ca1929 commit 7243955
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package minimization;

class DebugException extends Exception
public class DebugException extends Exception
{
private final Integer maxDepth;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package minimization;

import org.sat4j.specs.TimeoutException;

import automata.sfa.SFA;

public interface MinimizationAlgorithm <P,S>
{
public SFA<P,S> minimize() throws TimeoutException, DebugException;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package minimization;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -13,9 +14,24 @@
import automata.sfa.SFAMove;


public class MooreMinimization
public class MooreMinimization<P,S> implements MinimizationAlgorithm<P,S>
{
private static List<Integer> normalize(Integer p, Integer q)
public static <P,S> SFA<P,S> mooreMinimize(SFA<P,S> aut, BooleanAlgebra<P,S> ba) throws TimeoutException
{
MooreMinimization<P,S> moore = new MooreMinimization<P,S>(aut, ba);
return moore.minimize();
}

private SFA<P,S> aut;
private BooleanAlgebra<P,S> ba;

private MooreMinimization(SFA<P,S> aut, BooleanAlgebra<P,S> ba)
{
this.aut = aut;
this.ba = ba;
}

private List<Integer> normalize(Integer p, Integer q)
{
List<Integer> pair;
if(p<q)
Expand All @@ -29,7 +45,7 @@ private static List<Integer> normalize(Integer p, Integer q)
return pair;
}

public static <P,S> SFA<P,S> mooreMinimize(SFA<P,S> aut, BooleanAlgebra<P,S> ba) throws TimeoutException
public SFA<P,S> minimize() throws TimeoutException
{
if(aut.isEmpty())
{
Expand All @@ -41,7 +57,7 @@ public static <P,S> SFA<P,S> mooreMinimize(SFA<P,S> aut, BooleanAlgebra<P,S> ba)
}
aut = aut.mkTotal(ba);
int normalizeStateCount = (aut.stateCount()*aut.stateCount())/2;
HashSet<List<Integer>> neq = new HashSet<List<Integer>>();
HashSet<List<Integer>> neq = new HashSet<List<Integer>>(normalizeStateCount);
for (Integer p : aut.getFinalStates())
{
for (Integer q : aut.getNonFinalStates())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package minimization.incremental;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -11,14 +13,18 @@
import java.util.Set;
import java.util.Stack;

import minimization.DebugException;
import minimization.MinimizationAlgorithm;

import org.sat4j.specs.TimeoutException;

import structures.DisjointSets;
import theory.BooleanAlgebra;
import automata.sfa.SFA;
import automata.sfa.SFAInputMove;
import automata.sfa.SFAMove;

public class IncrementalMinimization <P,S>
public class IncrementalMinimization<P,S> implements MinimizationAlgorithm<P,S>
{

protected class EquivTest //tests for equality of two given states in the automata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package minimization.incremental;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Stack;

import minimization.incremental.IncrementalMinimization.EquivTest;
import minimization.incremental.IncrementalMinimization.EquivTest.EquivRecord;

import org.sat4j.specs.TimeoutException;

import structures.DisjointSets;
import structures.MintermTree;
import theory.BooleanAlgebra;
import automata.sfa.SFA;
import automata.sfa.SFAInputMove;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package minimization.incremental;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

import minimization.incremental.IncrementalMinimization.EquivTest;

import org.sat4j.specs.TimeoutException;

import structures.DisjointSets;
import theory.BooleanAlgebra;
import automata.sfa.SFA;
import automata.sfa.SFAInputMove;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package minimization.incremental;
import org.sat4j.specs.TimeoutException;

import automata.sfa.SFA;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package structures;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package structures;
import java.util.ArrayList;

import org.sat4j.specs.TimeoutException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package test;
import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import structures.DisjointSets;

public class TestDisjointSets {

DisjointSets<Integer> sets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package test;
import static org.junit.Assert.*;

import java.io.BufferedReader;
Expand All @@ -20,6 +21,14 @@
import java.util.Map.Entry;
import java.util.TreeMap;


import minimization.DebugException;
import minimization.MooreMinimization;
import minimization.incremental.IncrementalMinimization;
import minimization.incremental.IncrementalNaive;
import minimization.incremental.IncrementalRecursive;
import minimization.incremental.TimeBudgetExceededException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -37,7 +46,9 @@
import automata.sfa.SFAInputMove;
import automata.sfa.SFAMove;

public class TestIncrementalMinimization {
public class TestIncrementalMinimization
{
public static final String REGEX_FILE = "src/test/regexlib-SFA.txt";

@Test
public void testMyAut() throws TimeoutException
Expand Down Expand Up @@ -148,7 +159,7 @@ public void testCompare() throws TimeoutException, IOException
System.out.println("========================");

//import list of regex. Heavily borrowed code from symbolic automata library
FileReader regexFile = new FileReader("src/regexlib-SFA.txt");
FileReader regexFile = new FileReader(REGEX_FILE);
BufferedReader read = new BufferedReader(regexFile);
ArrayList<String> regexList = new ArrayList<String>();
String line;
Expand Down Expand Up @@ -333,7 +344,7 @@ public void testBudget() throws TimeoutException, IOException
System.out.println("=========================");

//import list of regex
FileReader regexFile = new FileReader("src/regexlib-SFA.txt");
FileReader regexFile = new FileReader(REGEX_FILE);
BufferedReader read = new BufferedReader(regexFile);
ArrayList<String> regexList = new ArrayList<String>();
String line;
Expand Down Expand Up @@ -495,15 +506,15 @@ private Double linearInterpolate(Integer x, Integer x0, Integer x1, Double y0, D
}

@Test
public void testRecord() throws IOException, DebugException
public void testRecord() throws IOException
{
//TODO: cleanup + document
System.out.println("====================");
System.out.println("STARTING RECORD TEST");
System.out.println("====================");

//import list of regex
FileReader regexFile = new FileReader("src/regexlib-SFA.txt");
FileReader regexFile = new FileReader(REGEX_FILE);
BufferedReader read = new BufferedReader(regexFile);
ArrayList<String> regexList = new ArrayList<String>();
String line;
Expand Down Expand Up @@ -737,7 +748,7 @@ public void testDepth() throws IOException, TimeoutException
System.out.println("STARTING DEPTH TEST");
System.out.println("===================");
//import list of regex
FileReader regexFile = new FileReader("src/regexlib-SFA.txt");
FileReader regexFile = new FileReader(REGEX_FILE);
BufferedReader read = new BufferedReader(regexFile);
ArrayList<String> regexList = new ArrayList<String>();
String line;
Expand Down
File renamed without changes.

0 comments on commit 7243955

Please sign in to comment.