/// <summary> /// Function for collect all information from a Sum block. /// </summary> /// <param name="sum"></param> public static void SumDatas(sumBlock sum) { string sign1; string sign2; if (sum.sign1 == -1) { sign1 = "-"; } else { sign1 = "+"; } if (sum.sign2 == -1) { sign2 = "-"; } else { sign2 = "+"; } Console.WriteLine("\n####### Details of a Sum block #######"); Console.WriteLine("sum name: {0}", sum.name); Console.WriteLine("sum graph: "); Console.WriteLine(); Console.Write("[{0}] [{1}] --> \n\t\t --> [{2}] --> [{3}] \n[{4}] [{5}] -->\n", sign1, sum.input1, sum.name, sum.output, sign2, sum.input2); Console.WriteLine(); }
/// <summary> /// Search a block by name and remove it /// Output parameter is bool, which is tell you the function is suceeded. /// </summary> /// <param name="name"></param> public static bool RemoveBlockFromList(string name) { bool found = false; tfBlock tf = new tfBlock(); if (SearchTf_byName(name, out tf)) { LinkedListNode <tfBlock> mark = lists.tflist.Find(tf); lists.tflist.Remove(mark); return(true); } sumBlock Sum = new sumBlock(); if (SearchSum_byName(name, out Sum)) { LinkedListNode <sumBlock> mark = lists.sumlist.Find(Sum); lists.sumlist.Remove(mark); return(true); } nodeBlock Node = new nodeBlock(); if (SearchNode_byName(name, out Node)) { LinkedListNode <nodeBlock> mark = lists.nodelist.Find(Node); lists.nodelist.Remove(mark); return(true); } else { return(false); } }
public static void Change_Sum(sumBlock old_sum, sumBlock new_sum) { LinkedListNode <sumBlock> mark = lists.sumlist.Find(old_sum); lists.sumlist.AddAfter(mark, new_sum); lists.sumlist.Remove(mark); }
public static void swapper(tfBlock old_tf, sumBlock old_sum) { tfBlock new_tf = old_tf; new_tf.input = old_sum.name; new_tf.output = old_sum.output; //az eredeti tf cserélése az eloltra blockmanager.Change_Tf(old_tf, new_tf); //az inverz, párhuzamos tf hozzáadása tfBlock inv_tf = inverseTf(old_tf, true); inv_tf.name = blockmanager.NameCounter(old_tf.name, Blocktypes.tf); lists.tflist.AddLast(inv_tf); //eltolt sum létrehozása és a régi törlése a listából blockmanager.RemoveBlockFromList(old_sum.name, Blocktypes.sum); new Sum(old_sum.name, old_sum.sign1, old_tf.input, old_sum.sign2, inv_tf.name, new_tf.name); //in- és outputokra kötött blokkok megfelelő PIN-jeinek átírása blockmanager.InputChange(old_tf.input, old_sum.name, old_tf.name); blockmanager.InputChange(old_sum.input2, inv_tf.name, old_sum.name); blockmanager.OutputChange(old_sum.output, new_tf.name, old_sum.name); //ellenőrzés Check.Consistency_CheckAndPause(); }
public static bool Scanning_Parallel(out tfBlock tf1, out tfBlock tf2, out nodeBlock node, out sumBlock sum) { tfBlock TempTf = tf1 = tf2 = new tfBlock(); node = new nodeBlock(); sum = new sumBlock(); foreach (tfBlock element in lists.tflist) { if ((element.input == TempTf.input) && (element.output == TempTf.output)) { tf1 = element; tf2 = TempTf; if (blockmanager.SearchSum_byName(tf1.output, out sum)) { if (blockmanager.SearchNode_byName(tf1.input, out node)) { Console.WriteLine("\tFound a parallel connection: ({0}) --> ({1}) , ({2}) --> ({3})", node.name, tf1.name, tf2.name, sum.name); return(true); } } } TempTf = element; } return(false); }
public static void swapper(sumBlock old_sum, tfBlock old_tf) { tfBlock new_tf; new_tf = old_tf; new_tf.input = old_sum.input1; new_tf.output = old_sum.name; //az eredeti tf lecserélése az eltoltra blockmanager.Change_Tf(old_tf, new_tf); string ParallelTfName = blockmanager.NameCounter(old_tf.name, Blocktypes.tf); //a párhuzamos, elolt tf létrehozása new TransferFunction(ParallelTfName, old_tf.num, old_tf.den, old_sum.input2, old_sum.name); sumBlock new_sum; new_sum.name = old_sum.name; new_sum.input1 = new_tf.name; new_sum.sign1 = old_sum.sign1; new_sum.input2 = ParallelTfName; new_sum.sign2 = old_sum.sign2; new_sum.output = old_tf.output; //az eredeti sum lecserélése az eltoltra blockmanager.Change_Sum(old_sum, new_sum); //in- és outputokra kötött blokkok megfelelő PIN-jeinek átírása blockmanager.InputChange(old_sum.input1, new_tf.name, old_sum.name); blockmanager.InputChange(old_sum.input2, ParallelTfName, old_sum.name); blockmanager.OutputChange(old_tf.output, new_sum.name, old_tf.name); //ellenőrzés, hogy minden rendben van-e Check.Consistency_CheckAndPause(); }
public static void swapper(sumBlock sum1, sumBlock sum2) { sumBlock new_sum1, new_sum2; new_sum1.sign1 = sum1.sign1; new_sum1.input1 = sum1.input1; new_sum1.sign2 = sum2.sign2; new_sum1.input2 = sum2.input2; new_sum1.name = sum2.name; new_sum1.output = sum1.name; new_sum2.sign1 = 1; new_sum2.input1 = new_sum1.name; new_sum2.sign2 = sum1.sign2; new_sum2.input2 = sum1.input2; new_sum2.name = sum1.name; new_sum2.output = sum2.output; blockmanager.Change_Sum(sum1, new_sum1); blockmanager.Change_Sum(sum2, new_sum2); blockmanager.InputChange(sum1.input1, new_sum1.name, sum1.name); blockmanager.OutputChange(sum2.output, new_sum2.name, sum2.name); Check.Consistency_CheckAndPause(); }
/// <summary> /// This function is useful for creating a new element inside the system. /// \nSearch the block, which is on the new block input, and change its output pin and return its name /// </summary> /// <param name="old_InputPin"></param> /// <param name="new_BlockName"></param> /// <param name="old_inputBlockName"></param> /// <returns></returns> public static string InputChange(string old_InputPin, string new_BlockName, string old_inputBlockName) { string newInputPin = ""; tfBlock TempTf = new tfBlock(); sumBlock TempSum = new sumBlock(); nodeBlock TempNode = new nodeBlock(); if (String.Equals(old_InputPin, "start", StringComparison.OrdinalIgnoreCase)) { return("start"); } if (SearchTf_byName(old_InputPin, out TempTf)) { LinkedListNode <tfBlock> mark = lists.tflist.Find(TempTf); TempTf.output = new_BlockName; lists.tflist.AddAfter(mark, TempTf); lists.tflist.Remove(mark); return(TempTf.name); } if (SearchSum_byName(old_InputPin, out TempSum)) { LinkedListNode <sumBlock> mark = lists.sumlist.Find(TempSum); TempSum.output = new_BlockName; lists.sumlist.AddAfter(mark, TempSum); lists.sumlist.Remove(mark); return(TempSum.name); } if (SearchNode_byName(old_InputPin, out TempNode)) { LinkedListNode <nodeBlock> mark = lists.nodelist.Find(TempNode); if (TempNode.output1 == old_inputBlockName) { TempNode.output1 = new_BlockName; } else { TempNode.output2 = new_BlockName; } lists.nodelist.AddAfter(mark, TempNode); lists.nodelist.Remove(mark); return(TempNode.name); } else { Console.WriteLine("[ERR]: could not found block with this name: {0}", old_InputPin); Console.ReadKey(); } return(newInputPin); }
/// <summary> /// Search Sum Block by name /// The output paramter is bool, becaouse it is make simple the work with this. /// The founded parameter is defined in parameters field. /// </summary> /// <param name="name"></param> /// <param name="sum"></param> /// <returns></returns> public static bool SearchSum_byName(string name, out sumBlock sum) { bool result = false; new Sum(1, "", 1, "", "", out sum); foreach (sumBlock element in lists.sumlist) { if (element.name == name) { result = true; sum = element; break; } } return(result); }
/// <summary> /// Implementation of feedback connection reducing /// </summary> /// <param name="tf1"></param> /// <param name="tf2"></param> /// <param name="sum"></param> /// <param name="node"></param> public static void feedback(tfBlock tf1, tfBlock tf2, sumBlock sum, nodeBlock node) { tfBlock tf; if (sum.sign2 < 0) { tf = parallel(identicalTf(), series(tf1, tf2, true), SIGN.plus, SIGN.plus); } else { tf = parallel(identicalTf(), series(tf1, tf2, true), SIGN.plus, SIGN.minus); } tf = series(tf1, inverseTf(tf, true), true); tf.name = blockmanager.NameCounter("feedback", Blocktypes.tf); tf.input = blockmanager.InputChange(sum.input1, tf.name, sum.name); //tf.output: blockmanager.SearchTf_byName(node.output1, out TempTf); //előfordulhat, hogy a node outpu1-én van a visszacsatolás ága! if (TempTf.name == tf2.name) //ha az első outputon van a visszacsatolási ág { tf.output = blockmanager.OutputChange(node.output2, tf.name, node.name); } else //egyébként { tf.output = blockmanager.OutputChange(node.output1, tf.name, node.name); } blockmanager.Change_Tf(tf1, tf); blockmanager.RemoveBlockFromList(tf2.name, Blocktypes.tf); blockmanager.RemoveBlockFromList(sum.name, Blocktypes.sum); blockmanager.RemoveBlockFromList(node.name, Blocktypes.node); Console.WriteLine("\tSimplified a feedback connection: ({0})", tf.name); ConsistencyResult result = Check.consistency(); if (!result.success) { Check.ReadConsistencyResult(result); Console.ReadKey(); } }
public static void Swapper_Sum(sumBlock sum1, sumBlock sum2) { sumBlock new_sum1, new_sum2; new_sum1.sign1 = sum1.sign1; new_sum1.input1 = sum1.input1; new_sum1.sign2 = sum2.sign2; new_sum1.input2 = sum2.input2; new_sum1.name = sum2.name; new_sum1.output = sum1.name; new_sum2.sign1 = 1; new_sum2.input1 = new_sum1.name; new_sum2.sign2 = sum1.sign2; new_sum2.input2 = sum1.input2; new_sum2.name = sum1.name; new_sum2.output = sum2.output; blockmanager.Change_Sum(sum1, new_sum1); blockmanager.Change_Sum(sum2, new_sum2); }
/// <summary> /// This function will be reduce a parallel connection. /// </summary> /// <param name="node"></param> /// <param name="tf1"></param> /// <param name="tf2"></param> /// <param name="sum"></param> public static void parallel(tfBlock tf1, tfBlock tf2, nodeBlock node, sumBlock sum) { tfBlock newtf = new tfBlock(); newtf.num = MathExtended.PolySum(MathExtended.convolution(tf1.num, tf2.den), MathExtended.convolution(tf2.num, tf1.den), sum.sign1, sum.sign2); newtf.den = MathExtended.convolution(tf1.den, tf2.den); newtf.name = blockmanager.NameCounter("parallel", Blocktypes.tf); newtf.input = blockmanager.InputChange(node.input, newtf.name, node.name); newtf.output = blockmanager.OutputChange(sum.output, newtf.name, sum.name); blockmanager.Change_Tf(tf1, newtf); blockmanager.RemoveBlockFromList(tf2.name, Blocktypes.tf); blockmanager.RemoveBlockFromList(node.name, Blocktypes.node); blockmanager.RemoveBlockFromList(sum.name, Blocktypes.sum); Console.WriteLine("\tSimplified a parallel connection: ({0})", newtf.name); ConsistencyResult result; result = Check.consistency(); if (!result.success) { Check.ReadConsistencyResult(result); } }
public static bool Scanning_Feedback(out tfBlock tf1, out tfBlock tf2, out nodeBlock node, out sumBlock sum) { tfBlock TempTf = tf1 = tf2 = new tfBlock(); node = new nodeBlock(); sum = new sumBlock(); foreach (tfBlock element in lists.tflist) { if ((element.input == TempTf.output) && (element.output == TempTf.input)) { if (blockmanager.SearchSum_byName(element.input, out sum)) { tf1 = element; tf2 = TempTf; //a folyamatos konzisztencia check-ek miatt nem kell külön megvizsgálni, hogy ez a node az a node-e, mert annak kell lennie. if (blockmanager.SearchNode_byName(tf1.output, out node)) { Console.WriteLine("\tFound a feedback connection: ({0}) --> ({1}) --> ({2}) --> ({3})", sum.name, tf1.name, node.name, tf2.name); return(true); } } if (blockmanager.SearchSum_byName(TempTf.input, out sum)) { tf1 = TempTf; tf2 = element; if (blockmanager.SearchNode_byName(tf1.output, out node)) { Console.WriteLine("\tFound a feedback connection: ({0}) --> ({1}) --> ({2}) --> ({3})", sum.name, tf1.name, node.name, tf2.name); return(true); } } } TempTf = element; } return(false); }
/// <summary> /// Create a new virtual sum element. This is necessary for some applications /// If the sign field is '1', the sum's sign will be '+', otherwise it will be '-' /// </summary> /// <param name="input1"></param> /// <param name="input2"></param> /// <param name="output"></param> /// <param name="sum"></param> public Sum(int sign1, string input1, int sign2, string input2, string output, out sumBlock sum) { sum.name = ""; sum.input1 = input1; sum.input2 = input2; if (sign1 == 1 || sign1 == -1) { sum.sign1 = sign1; } else { sum.sign1 = 1; } if (sign2 == 1 || sign2 == -1) { sum.sign2 = sign2; } else { sum.sign2 = 1; } sum.output = output; }