public InnerPartition(State s) { // State.n++; // if (states.Contains(s)) // throw new Exception(String.Format("Duplicate states ({0}) exist in a partition: {1}", s.Name, this.ToString())); states.Add(s); }
public bool Contains(State s) { bool b = false; foreach (State st in this) { // State.n++; // Console.WriteLine(" " + st); if (st.Equals(s)) { b = true; break; } } return b; }
/// <summary> /// Tests for equivalence to another state <paramref name="s"/> /// </summary> /// <param name="s">The state to test equivalence</param> /// <returns>True if the names of the output states match</returns> public bool Equals(State s) { // Console.Write("Comparing (" + this + ") with (" + s + ") "); int size = this.io.Length; bool b = false; if (size != s.io.Length) return b; for (int i = 0; i < size; i++) { // n++; b = this.io[i].output[input[i]].Name.Equals(s.io[i].output[input[i]].Name); if (!b) break; } // Console.WriteLine(b); return b; }
public void Add(State s) { this.states.Add(s); }
public InnerPartition GetInnerPartitionOf(State s) { foreach (InnerPartition p in this.partitions) { // Console.WriteLine(p.ToString() + s.ToString()); // State.n++; if (p.Contains(s)) return p; } return null; }
public bool Contains(State s) { if (GetInnerPartitionOf(s) == null) { return false; } return true; }
public IO(string input, State output) { this.output = new Dictionary<string, State>(); this.output.Add(input, output); }
/// <summary> /// Allows multiple output states /// </summary> /// <param name="p">The output string of the state</param> /// <param name="outputStates">A list of states that the state outputs to. Must be the same length as the alphabet</param> public void setOutput(string p, State[] outputStates) { this.output = p; int size = outputStates.Length; // Check to see if each state has the correct number of inputs/outputs if (size != input.Length) { string msg = this.Name + " does not have the proper amount of output states."; Console.WriteLine(msg); throw new Exception(msg); } // Initialize the map of (input, output) IO[] map = new IO[size]; for (int i = 0; i < size; i++) { // n++; // Dictionary<String, State> d = new Dictionary<String, State>(); // d.Add(input[i], outputStates[i]); map[i] = new IO(input[i], outputStates[i]); } this.io = map; }
// public State(string s, string input, string output, State outputState) // { // this.Name = s; // // init(io, 0); // this.io[0] = new IO(); // // Dictionary<String, State> outputFunction = new Dictionary<String, State>(); // outputFunction.Add(output, outputState); // this.io[0].output.Add(input, outputFunction); // // // Will this create a new reference of a state with the same name? // // I'm passing an existing state, but making a new one... // // outputState = new State(outputState.Name); // } // // public State(String s, String[] inputs, String[] outputs, State[] outputStates) // { // this.Name = s; // this.input = inputs; // this.output = outputs; // // Console.WriteLine(outputStates.Length); // int size = inputs.Length - 1; // IO[] map = new IO[size]; // // for (int i = 0; i <= size; i++) // { // Dictionary<String, State> d = new Dictionary<String, State>(); // d.Add(outputs[i], outputStates[i]); // map[i] = new IO(inputs[i], d); // } // } /// <summary> /// Method to create a sink /// </summary> /// <param name="p">The output string of the state</param> /// <param name="outputState">The sink state</param> public void setOutput(string p, State outputState) { this.output = p; int size = input.Length; // Initialize the map of (input, output) IO[] map = new IO[size]; for (int i = 0; i < size; i++) { // n++; // Dictionary<String, State> d = new Dictionary<String, State>(); // d.Add(output[i], outputState); map[i] = new IO(input[i], outputState); } this.io = map; }