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 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 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); }
/// <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); } }
/// <summary> /// Function for simplify the changing a tf an another. /// </summary> /// <param name="old_tf"></param> /// <param name="new_tf"></param> public static void Change_Tf(tfBlock old_tf, tfBlock new_tf) { LinkedListNode <tfBlock> mark = lists.tflist.Find(old_tf); lists.tflist.AddAfter(mark, new_tf); lists.tflist.Remove(mark); }
/// <summary> /// Create a virtual transfer function for calculations. This function return with a tf struct, /// but it won't be storaged in tf list. /// </summary> /// <param name="num"></param> /// <param name="den"></param> /// <param name="tf"></param> public TransferFunction(double[] num, double[] den, out tfBlock tf) { tf.name = ""; tf.input = ""; tf.output = ""; tf.num = num; tf.den = den; }
/// <summary> /// This function will be calculate one reduced transfer function from two tfs, which are connected in parallel /// This function can not modify the lists of blocks! /// </summary> /// <param name="tf1"></param> /// <param name="tf2"></param> /// <param name="sign"></param> /// <param name="newtf"></param> public static tfBlock parallel(tfBlock tf1, tfBlock tf2, SIGN sign1, SIGN sign2) { tfBlock newtf; newtf.name = ""; newtf.input = ""; newtf.output = ""; newtf.num = MathExtended.PolySum(MathExtended.convolution(tf1.num, tf2.den), MathExtended.convolution(tf2.num, tf1.den), sign1, sign2); newtf.den = MathExtended.convolution(tf1.den, tf2.den); return(newtf); }
/// <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> /// Helper Function, which creates an inverse transfer function. /// </summary> /// <param name="tf"></param> /// <param name="virtual_switcher"></param> /// <returns></returns> public static tfBlock inverseTf(tfBlock tf, params bool[] virtual_switcher) { tfBlock newtf = tf; newtf.num = tf.den; newtf.den = tf.num; if ((virtual_switcher.Length > 0) && (virtual_switcher[0] == true)) { return(newtf); } else { blockmanager.Change_Tf(tf, newtf); return(newtf); } }
/// <summary> /// Search Transfer Function 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="tf"></param> /// <returns></returns> public static bool SearchTf_byName(string name, out tfBlock tf) { bool result = false; new TransferFunction(new double[0], new double[0], out tf); foreach (tfBlock element in lists.tflist) { if (element.name == name) { result = true; tf = element; break; } } return(result); }
/// <summary> /// Simple function to show all information of a transfer function block /// </summary> /// <param name="tf"></param> public static void tfDatas(tfBlock tf) { Console.WriteLine("\n### Details of a transfer function x##"); Console.WriteLine("\ttf name: {0}", tf.name); Console.WriteLine("\ttf input: {0}", tf.input); Console.WriteLine("\ttf output: {0}", tf.output); Console.Write("\ttf numerator:\t"); foreach (double element in tf.num) { Console.Write(" {0} ", element); } Console.Write("\n\ttf denominator:\t"); foreach (double element in tf.den) { Console.Write(" {0} ", element); } Console.WriteLine(); }
/// <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(tfBlock old_tf, nodeBlock old_node) { tfBlock new_tf = old_tf; //az eredeti tf lecserélése az eltoltra a listában new_tf.input = old_node.name; new_tf.output = old_node.output1; blockmanager.Change_Tf(old_tf, new_tf); //párhuzamos tf létrehozása string para_tfname = blockmanager.NameCounter(old_tf.name, Blocktypes.tf); new TransferFunction(para_tfname, old_tf.num, old_tf.den, old_node.name, old_node.output2); //eltolt node létrehozása, és a régi törlése blockmanager.RemoveBlockFromList(old_node.name, Blocktypes.node); new Node(old_node.name, old_tf.input, old_tf.name, para_tfname); //in- és outputokra kötött blokkok megfelelő PIN-jeinek átírása blockmanager.InputChange(old_tf.input, old_node.name, old_tf.name); blockmanager.OutputChange(old_node.output1, old_tf.name, old_node.name); blockmanager.OutputChange(old_node.output2, para_tfname, old_node.name); //konzisztencia check Check.Consistency_CheckAndPause(); }
/// <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 void swapper(nodeBlock old_node, tfBlock old_tf) { tfBlock new_tf = old_tf; //az eredeti tf lecserélése az eltoltra new_tf.input = old_node.input; new_tf.output = old_node.name; blockmanager.Change_Tf(old_tf, new_tf); //párhuzamos inverz tf létrehozása tfBlock inv_tf = inverseTf(old_tf, true); inv_tf.name = blockmanager.NameCounter(old_tf.name, Blocktypes.tf); lists.tflist.AddLast(inv_tf); //eltolt node létrehozása blockmanager.RemoveBlockFromList(old_node.name, Blocktypes.node); new Node(old_node.name, new_tf.input, old_tf.output, inv_tf.name); //in- és outputokra kötött blokkok megfelelő PIN.jeinek átírása blockmanager.InputChange(old_node.input, new_tf.name, old_node.name); blockmanager.OutputChange(old_tf.output, old_node.name, old_tf.name); blockmanager.OutputChange(old_node.output2, inv_tf.name, old_node.name); //konzisztencia check Check.Consistency_CheckAndPause(); }
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); }
public static bool Scanning_Series(out tfBlock tf1, out tfBlock tf2) { tfBlock TempTf = tf1 = tf2 = new tfBlock(); foreach (tfBlock element in lists.tflist) { if ((element.input == TempTf.name) && (TempTf.output == element.name)) { tf1 = TempTf; tf2 = element; Console.WriteLine("\tFound blocks in series connection: ({0}) --> ({1})", tf1.name, tf2.name); return(true); } if ((element.output == TempTf.name) && (TempTf.input == element.name)) { tf1 = element; tf2 = TempTf; Console.WriteLine("\tFound blocks in series connection: ({0}) --> ({1})", tf1.name, tf2.name); return(true); } TempTf = element; } return(false); }
/// <summary> /// This function will be reduce a series connection. /// </summary> /// <param name="tf1"></param> /// <param name="tf2"></param> public static tfBlock series(tfBlock tf1, tfBlock tf2, params bool[] virtual_switcher) { tfBlock newtf; if ((virtual_switcher.Length > 0) && (virtual_switcher[0] == true)) { newtf.num = MathExtended.convolution(tf1.num, tf2.num); newtf.den = MathExtended.convolution(tf1.den, tf2.den); newtf.name = ""; newtf.input = ""; newtf.output = ""; } else { newtf.num = MathExtended.convolution(tf1.num, tf2.num); newtf.den = MathExtended.convolution(tf1.den, tf2.den); newtf.name = blockmanager.NameCounter("series", Blocktypes.tf); newtf.input = blockmanager.InputChange(tf1.input, newtf.name, tf1.name); newtf.output = blockmanager.OutputChange(tf2.output, newtf.name, tf2.name); blockmanager.Change_Tf(tf1, newtf); blockmanager.RemoveBlockFromList(tf2.name, Blocktypes.tf); Console.WriteLine("\tSimplified a series connection: ({0})", newtf.name); blockmanager.SystemStat(); ConsistencyResult result; result = Check.consistency(); if (!result.success) { Check.ReadConsistencyResult(result); Console.ReadKey(); } } return(newtf); }