예제 #1
0
        private void Default()
        {
            int w = 32;
            int n = 2;

            b     = new BaseFunctions(w, n);
            var_w = b.var_w;
            var_n = b.var_n;
            var_m = b.var_m;

            A = new long[][] { new long[] { 1, 0, 0 }, new long[] { 5, 0, 0 }, new long[] { 0, 38271610, 0 } };

            //A = new long[var_n][];
            //IaNode node = new IaNode();
            //long[][] vectors = new long[][] { new long[] { 1, 4, 2, 3 }, new long[] { 0, 6, 7, 4 }, new long[] { 0, 0, 3, 1 }, new long[] { 0, 0, 0, 5 } };
            //node.GeneratorSet = new GeneratorSet(node, b);

            //foreach (long[] vector in vectors)
            //{
            //    LeadVector lv = new LeadVector(vector);
            //    node.GeneratorSet.AddVector(lv);
            //    node.GeneratorSet.Print();
            //}

            //for (int i = 0; i < var_n; i++)
            //{
            //    A[i] = vectors[i];
            //}
            //PrintMatrix("A", A);

            T = b.GetIdentity(var_n);
        }
예제 #2
0
 private void AddIdentityVectors(Queue <NodeVector> w_queue, IaNode node)
 {
     long[][] id = bg.GetIdentity(bg.var_n);
     for (int i = 0; i < bg.var_n; i++)
     {
         LeadVector vr = new LeadVector(id[i]);
         node.GeneratorSet.AddVector(vr);
         w_queue.Enqueue(new NodeVector {
             Node = node, Vector = vr
         });
     }
 }
예제 #3
0
        private void AddMatrixesForUnknownExpr(int vi)
        {
            long[][] mtx = null;
            mtx         = b.GetIdentity(var_n);
            mtx[vi][vi] = 0;
            TMatrixes.Add(mtx);

            mtx         = b.GetIdentity(var_n);
            mtx[vi][vi] = 0;
            mtx[0][vi]  = 1;
            TMatrixes.Add(mtx);
        }
예제 #4
0
        private void CreateFunctionMatrixes(ProgramAst prg)
        {
            List <IaEdge> fncCallEdges = new List <IaEdge>();

            CreateEmptyFunctionG(prg, fncCallEdges);

            Queue <NodeMatrix> w_queue = new Queue <NodeMatrix>();

            foreach (string name in prg.OrigFncs.Keys)
            {
                w_queue.Enqueue(new NodeMatrix {
                    Node = prg.Graph[name], Matrix = bfm.GetIdentity(bg.var_n)
                });
            }

            while (w_queue.Count > 0)
            {
                NodeMatrix pair = w_queue.Dequeue();

                IaNode from = pair.Node;
                if ((from.Next != null) || (from.IsTrue != null) || (from.IsFalse != null))
                {
                    foreach (IaEdge edge in from.Edges)
                    {
                        if ((edge.Ast == null) || (edge.Ast.AstType != AstNodeTypes.FunctionCall))
                        {
                            IaNode to = edge.To;

                            // pruchod hranou s maticemi
                            foreach (long[][] a_mtx in edge.MatrixSet.TMatrixes)
                            {
                                long[][]   mtx = bg.MatrixMultiMatrix(a_mtx, pair.Matrix, bfm.var_m);
                                long[]     xi  = bg.MatrixToVector(mtx);
                                LeadVector x   = new LeadVector(xi);
                                if (x.Lidx >= 0)
                                {
                                    if (to.FunctionGSet.AddVector(x))
                                    {
                                        if (printG)
                                        {
                                            to.FunctionGSet.Print();
                                        }

                                        w_queue.Enqueue(new NodeMatrix {
                                            Node = to, Matrix = mtx
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // pokud se jedna o konecny uzel funkce
                    foreach (IaEdge edge in fncCallEdges)
                    {
                        if ((edge.Ast == null) || (edge.Ast.AstType != AstNodeTypes.FunctionCall))
                        {
                            throw new ApplicationException();
                        }

                        if (edge.Ast.TokenText == from.FncName)
                        {
                            IaNode to = edge.To;

                            int i = 0;
                            while (edge.From.FunctionGSet.GArr[i] != null)
                            {
                                LeadVector vector = edge.From.FunctionGSet.GArr[i];
                                long[][]   matrix = bfm.VectorToMatrix(vector.Vr, bg.var_n);

                                long[][]   mtx = bg.MatrixMultiMatrix(pair.Matrix, matrix, bfm.var_m);
                                long[]     xi  = bg.MatrixToVector(mtx);
                                LeadVector x   = new LeadVector(xi);
                                if (x.Lidx >= 0)
                                {
                                    if (to.FunctionGSet.AddVector(x))
                                    {
                                        if (printG)
                                        {
                                            to.FunctionGSet.Print();
                                        }

                                        w_queue.Enqueue(new NodeMatrix {
                                            Node = to, Matrix = mtx
                                        });
                                    }
                                }
                                i++;
                            }
                        }
                    }
                }
            }
            // distribuce mnozin zmenovych matic z vystupnich uzlu na hrany volajici funkce
            foreach (string fncName in prg.LastNode.Keys)
            {
                IaNode last = prg.LastNode[fncName];

                List <long[][]> mtxs = new List <long[][]>();
                int             i    = 0;
                while (last.FunctionGSet.GArr[i] != null)
                {
                    mtxs.Add(bfm.VectorToMatrix(last.FunctionGSet.GArr[i].Vr, bg.var_n));
                    i++;
                }
                if (mtxs.Count > 0)
                {
                    foreach (IaEdge edge in fncCallEdges)
                    {
                        if ((edge.Ast == null) || (edge.Ast.AstType != AstNodeTypes.FunctionCall))
                        {
                            throw new ApplicationException();
                        }

                        if (edge.Ast.TokenText == last.FncName)
                        {
                            edge.MatrixSet.TMatrixes.Clear();
                            edge.MatrixSet.TMatrixes.AddRange(mtxs);
                        }
                    }
                }
            }
        }