I can't believe I'm asking this, but this assignment I was given is proving very difficult. I was asked to find the ECLOSE function of a given Epsilon non-deterministic finite automata. All it is is the BFS tree of a graph from a given point, provided that the vertices are connected by an epsilon edge.

The weird thing about it is that my instructor is using an ArrayList instead of a Linked List or Queue for her graph representation, which I don't like. I feel like I'm almost there as far as solving the problem, I would really appreciate a push in the right direction, however.

The eclose(int i) method is the one I'm supposed to be working on. I also made the getNeighbors(State s) method to help.


System.out.println("Size: "+eclosure.size());
for(int x = 0; x < eclosure.size(); x++)

part is just for me to see where I'm at as far as correctness.

import java.util.*;

class ENFA{	
	private int stateNum; //number of states
	private State[] states; // array of states
	//Create e-NFA with 5 states, state 4 is the accepting state
	public ENFA(){
		stateNum = 5;//number of states
		states = new State[stateNum];
		ArrayList<Integer> A, B, E;	
		for(int i=0; i<stateNum; i++){
			states[i] = new State();
			A = states[i].deltaA;
			B = states[i].deltaB;
			E = states[i].deltaE;
			if(i == 2){
			if(i == 0 || i== 2){
			if(i==0 || i==4){
			if(i == 1){
		states[stateNum-1].accepting = true;
	//Randomly creates an e-NFA with size the specified parameter  
	public ENFA(int stateNum){
		this.stateNum = stateNum;
		states = new State[stateNum];
		for(int i=0; i<stateNum; i++){
			states[i] = new State();
			ArrayList<Integer> A = states[i].deltaA;
			ArrayList<Integer> B = states[i].deltaB;
			ArrayList<Integer> E = states[i].deltaE;
			//Create transitions from state i to some states.
			for(int j = 0; j<stateNum; j++){	
				double r1 = Math.random();
				int r2 = (int)(Math.random()*stateNum);
				}else if(r1>0.8){
				}else if(r1 > 0.65){
		states[stateNum-1].accepting = true;
	//Display this e-NFA
	public void display(){
		int stateNum = states.length;
		for(int i=0; i<stateNum; i++){
			System.out.println(i +": ");
			System.out.print("\na-transitions: ");

			System.out.print("\nb-transitions: ");

			System.out.print("\ne-transitions: ");
	//Display the specified array 
	public void display(ArrayList<Integer> array){
		Iterator<Integer> iter = array.iterator();
			System.out.print(iter.next() + ", ");
	//Return the size of this e-NFA
	public int size(){
		return stateNum;
	//Compute the eclosure of state i and return it
	public ArrayList<Integer> eclose(int i){
		int count = 0;
		ArrayList<Integer> eclosure = new ArrayList<Integer>();

		for(int v = i; v < states.length; v++)
			ArrayList<Integer> n = getNeighbors(states[v]);
			for(int w = 0; w < n.size(); w++)
				for(int z = 0; z < eclosure.size(); z++)
					if(n.get(w) != eclosure.get(z))
						if(z == eclosure.size());
							count = 0;
		System.out.println("Size: "+eclosure.size());				
		for(int x = 0; x < eclosure.size(); x++)
		return eclosure;

	//helper method, gets all nodes that have an epsilon transition from s
	public ArrayList<Integer> getNeighbors(State s)
		ArrayList<Integer> neighbors = new ArrayList<Integer>();
			for( int i = 0; i<s.deltaE.size(); i++)
		return neighbors;

	//Is w a member of L? (Don't have to do it now)
	public boolean member(String w){
		return false;

Here's a basic "state" class

import java.util.*;
class State{
	ArrayList<Integer> deltaA; //a-transitions  
	ArrayList<Integer> deltaB; // b-transitions 
	ArrayList<Integer> deltaE; //epsilon-transitions  
	boolean accepting;//Is this state an accepting state?
	boolean visited;//has this state been visited? 
	public State(){
		deltaA = new ArrayList<Integer>();
		deltaB = new ArrayList<Integer>();
		deltaE = new ArrayList<Integer>();
		accepting = false;
		visited = false;

and finally, the client program

import java.util.*;

//Create an E-NFA to accept a regular language over {a, b}
class ENFAtest{	
	public static void main(String[] args){
		ENFA fa = new ENFA();
		//ENFA fa = new ENFA(10); //test with other e-NFA's too.

		//Display the e-NFA
		//Compute ECLOSE for each state
		System.out.println("\nCompute ECLOSE for each state");
		for(int i=0; i<fa.size(); i++){
			ArrayList<Integer> eclosure = fa.eclose(i);
			System.out.print("ECLOSE("+i+") is " );

Any help would be appreciated. Thanks!

Do you have any specific java programming questions?
Is your problem with designing an algorithm to solve a problem
Or do you have a design/algorithm and need help writing the java code for it?

I kinda have an algorithm, I just can't seem to implement. What's on the screen right now is basically my consolation algorithm (and I can't even get that to work). The algorithm I'm trying to implement is:

mark first node as visited
for each unvisited node that has an epsilon transition from the root
get adjacent nodes with an epsilon transition
add them to eclosure, mark them as visited
if they appeared previously, do not add them to eclosure again
return eclosure

So this is most a logic problem. You have a complicated program that needs to be debugged to find why is doesn't do what you want it to do.

For most of my debugging I use print outs of data to show how variables change and how the execution flow goes. Keep adding print outs to show the data and compare what is printed with what you expect the values to be.
Also desk checking with paper and pencil can be used to work out details of complicated logic.

thats what ive been doing. i was looking for a fresh perspective on the algorithm, i find that when i look at other peoples code i can sometimes see stupid errors or flaws in logic that the original programmer see