Exemplo n.º 1
0
        private void CreateGeneratorSets(ProgramAst prg)
        {
            Queue <NodeVector> w_queue = VariableGeneratorSets(prg);

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

                IaNode from = pair.Node;
                foreach (IaEdge edge in from.Edges)
                {
                    IaNode to = edge.To;

                    if ((edge.Ast != null) && (edge.Ast.AstType == AstNodeTypes.FunctionCall))
                    {
                        IaNode fncBegin = prg.Graph[edge.Ast.TokenText];
                        if (fncBegin.GeneratorSet == null)
                        {
                            fncBegin.GeneratorSet = new GeneratorSet(fncBegin, bg);
                        }

                        if (fncBegin.GeneratorSet.AddVector(pair.Vector))
                        {
                            if (printG)
                            {
                                fncBegin.GeneratorSet.Print();
                            }

                            w_queue.Enqueue(new NodeVector {
                                Node = fncBegin, Vector = pair.Vector
                            });
                        }
                    }

                    foreach (long[][] a_mtx in edge.MatrixSet.TMatrixes)
                    {
                        long[]     xi = bg.MatrixMultiVector(a_mtx, pair.Vector.Vr, bg.var_m);
                        LeadVector x  = new LeadVector(xi);
                        if (x.Lidx >= 0)
                        {
                            if (to.GeneratorSet == null)
                            {
                                to.GeneratorSet = new GeneratorSet(to, bg);
                            }

                            if (to.GeneratorSet.AddVector(x))
                            {
                                if (printG)
                                {
                                    to.GeneratorSet.Print();
                                }

                                w_queue.Enqueue(new NodeVector {
                                    Node = to, Vector = x
                                });
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private Queue <NodeVector> VariableGeneratorSets(ProgramAst prg)
        {
            Queue <NodeVector> w_queue = new Queue <NodeVector>();
            IaNode             main    = prg.Graph["main"];

            main.GeneratorSet = new GeneratorSet(main, bg);

            Queue <NodeVector> vq = new Queue <NodeVector>();

            prg.VarGraph.GeneratorSet = new GeneratorSet(prg.VarGraph, bg);
            AddIdentityVectors(vq, prg.VarGraph);

            while (vq.Count > 0)
            {
                NodeVector pair = vq.Dequeue();

                IaNode from = pair.Node;
                if (from.Edges.Count() > 0)
                {
                    foreach (IaEdge edge in from.Edges)
                    {
                        IaNode to = edge.To;

                        foreach (long[][] a_mtx in edge.MatrixSet.TMatrixes)
                        {
                            long[]     xi = bg.MatrixMultiVector(a_mtx, pair.Vector.Vr, bg.var_m);
                            LeadVector x  = new LeadVector(xi);
                            if (x.Lidx >= 0)
                            {
                                if (to.GeneratorSet == null)
                                {
                                    to.GeneratorSet = new GeneratorSet(to, bg);
                                }

                                if (to.GeneratorSet.AddVector(x))
                                {
                                    if (printG)
                                    {
                                        to.GeneratorSet.Print();
                                    }

                                    vq.Enqueue(new NodeVector {
                                        Node = to, Vector = x
                                    });
                                }
                            }
                        }
                    }
                }
                else
                {
                    // konec definice promennych
                    main.GeneratorSet.AddVector(pair.Vector);
                    w_queue.Enqueue(new NodeVector {
                        Node = main, Vector = pair.Vector
                    });
                }
            }

            return(w_queue);
        }