Exemplo n.º 1
0
        public SelectPanel()
        {
            Graph gr = new OrientedGraph();
            InitializeComponent();
            SelectViewModel s = new SelectViewModel(gr);

            this.DataContext = s;
        }
Exemplo n.º 2
0
        public void testAddRemoveEdgesVertices()
        {
            // Not oriented graph
            Graph g = new Graph();

            for (int i = 0; i < 6; i++)
            {
                g.AddVertex();
            }
            g.AddEdge(2, 3);
            g.AddEdge(1, 3);
            g.AddEdge(2, 5);
            g.AddEdge(3, 5);
            Assert.False(g.RemoveEdge(1, 2));
            Assert.False(g.RemoveEdge(5, 1));
            Assert.True(g.RemoveEdge(1, 3));
            Assert.True(g.RemoveEdge(2, 5));
            Assert.False(g.RemoveEdge(2, 5));

            // Oriented graph
            OrientedGraph og = new OrientedGraph();

            for (int i = 0; i < 7; i++)
            {
                og.AddVertex();
            }
            og.AddEdge(1, 4, 2);
            og.AddEdge(6, 1, 3);
            og.AddEdge(1, 3, 3);
            og.AddEdge(4, 6, 1);
            og.AddEdge(6, 4, 2);
            Assert.True(og.RemoveEdge(1, 4));
            Assert.False(og.RemoveEdge(1, 4));
            Assert.False(og.RemoveEdge(1, 6));
            Assert.False(og.RemoveEdge(3, 1));
            Assert.True(og.RemoveEdge(4, 6));
            Assert.True(og.RemoveEdge(1, 3));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("\r\n");
            this.Write("\r\nusing System.Collections.Generic;\r\nusing Egar.Focus.DealModule.Fields;\r\nusing E" +
                       "gar.Focus.Framework.Types;\r\n\r\nnamespace GraphGeneratorUtil\r\n{\r\n\t");

            #line 17 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"

            foreach (var node in hierarhy)
            {
                var classInfo = node.entity;



            #line default
            #line hidden
                this.Write("\t\r\n\tpublic class ");

            #line 23 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(classInfo.className));

            #line default
            #line hidden
                this.Write("_Graph : GraphBase\r\n\t{\t\r\n\t\t(");

            #line 25 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(classInfo.classFullName));

            #line default
            #line hidden
                this.Write(")Entity;\r\n\r\n\t\tpublic ");

            #line 27 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(classInfo.className));

            #line default
            #line hidden
                this.Write("_Graph(FieldsEntity entity/*, EntityExtentionBase extention*/) :base(entity/*, ex" +
                           "tention*/)\r\n\t\t{\r\n\t\t\tthis.Entity= (");

            #line 29 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(classInfo.className));

            #line default
            #line hidden
                this.Write(")entity;\r\n\t\t}\r\n\t\t\r\n\t\t#region define order\r\n\r\n\t\tprotected Dictionary<string, List<" +
                           "CalcFieldInfo>> CreateCalcOrder()\r\n\t\t{\r\n\t\t\tvar calcOrder = new Dictionary<string" +
                           ", List<CalcFieldInfo>>()\r\n\t\t\t{\r\n\t\t\t");

            #line 38 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"

                var graph       = CreateFieldsGraph(classInfo.lFieldInfo);                 //граф зависимостей
                var startFields = new List <string>()
                {
                    ""
                };                                                                //набор стартовых филдов + "" - это типа порядок ввода + когда всю сделку нужно пересчитаться
                startFields.AddRange(classInfo.lFieldInfo.Keys);
                foreach (var startField in startFields)
                {
            #line default
            #line hidden
                    this.Write("\t\t\t\t#region ");

            #line 45 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(startField == ""?"input order":startField));

            #line default
            #line hidden
                    this.Write("\r\n                {\"");

            #line 46 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(startField));

            #line default
            #line hidden
                    this.Write("\", new List<CalcFieldInfo>()\r\n\t\t\t\t\t{\r\n\t\t\t");

            #line 48 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"

                    List <string> fieldsToCalc = null;
                    if (startField == "")
                    {
                        fieldsToCalc = new List <string>()
                        {
                            "DealType", "InstrType", "TradeType"
                        };                                                                                // хардкод ключевых полей, которые надо в первую очередь установить
                        fieldsToCalc.RemoveAll(f => !classInfo.lFieldInfo.ContainsKey(f));
                        List <string> sortOrder = new List <string>(OrientedGraph.TopologicSort(graph, null).Cast <string>().ToList());
                        fieldsToCalc.AddRange(sortOrder.Where(p => !fieldsToCalc.Contains(p)));
                    }
                    else
                    {
                        OrientedGraph subGraph = OrientedGraph.GetSubGraph(graph, startField, TransOrientation.Out);
                        subGraph.RemoveInTrans(startField);
                        fieldsToCalc = subGraph.RecursiveTopologicSort(startField).Cast <string>().ToList();
                    }

                    var visitedFields = new List <FieldInfo>(); //филды в которых мы побывали по ходу расчета
                    if (startField != "")
                    {
                        visitedFields.Add(classInfo.lFieldInfo[startField]);
                    }

                    foreach (string fldName in fieldsToCalc)
                    {
                        if (fldName == startField)       //граф возвращает стартовый филд в составе цепочки
                        {
                            continue;
                        }
                        var field = classInfo.lFieldInfo[fldName];
                        visitedFields.Add(field);

                        string funcName       = null;                   // название функции которой необходимо посчитаться
                        var    calcFromParams = new List <FieldInfo>(); //филды которые привели к пересчету данного филда
                        if (startField != "")
                        {
                            visitedFields.Add(classInfo.lFieldInfo[startField]);
                        }


                        var calcFromParamsStr = string.Join(",", calcFromParams.Select(f => f.Name).ToArray());
                        if (funcName != null)
                        {
            #line default
            #line hidden
                            this.Write("\t\t\t\t\t\t\tnew CalcFieldInfo(");

            #line 85 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(fldName));

            #line default
            #line hidden
                            this.Write(", (e)=> ");

            #line 85 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(fldName + "." + funcName));

            #line default
            #line hidden
                            this.Write("(e), new List<FieldBase>(){");

            #line 85 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(calcFromParamsStr));

            #line default
            #line hidden
                            this.Write("}),\r\n");

            #line 86 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                        }
                        else
                        {
            #line default
            #line hidden
                            this.Write("\t\t\t\t\t\t\tnew CalcFieldInfo(");

            #line 91 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(fldName));

            #line default
            #line hidden
                            this.Write(", new List<FieldBase>(){");

            #line 91 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                            this.Write(this.ToStringHelper.ToStringWithCulture(calcFromParamsStr));

            #line default
            #line hidden
                            this.Write("}),\r\n");

            #line 92 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                        }
                    }    //перебор филдов к расчету


            #line default
            #line hidden
                    this.Write("\t\r\n\t\t\t\t\t}\r\n\t\t\t\t},\r\n\t\t\t\t#endregion ");

            #line 98 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(startField == ""?"input order":startField));

            #line default
            #line hidden
                    this.Write("\r\n\t\t\t\t\t\t\r\n\t\t\t\t\r\n\r\n\t\t\t\t\r\n");

            #line 103 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
                }


            #line default
            #line hidden
                this.Write("\t\t\t\r\n\t\t\t};//new Dictionary\r\n\t\t \r\n\t\t\treturn calcOrder;\r\n\t\t}\r\n\t}\r\n\t\t#endregion //de" +
                           "fine order\r\n");

            #line 112 "C:\Users\Вера\Desktop\focus\server\TransactionService\GraphGeneratorUtil\Generator\T4Generator.tt"
            }//foreach entityInfo


            #line default
            #line hidden
            this.Write("}\r\n");
            return(this.GenerationEnvironment.ToString());
        }
Exemplo n.º 4
0
        public static FrequencyCode GetOptimalCode(string alphabet, Dictionary <char, double> frequencyList)
        {
            int q = frequencyList.Count % (alphabet.Length - 1);

            if (q == 0)
            {
                q = alphabet.Length - 1;
            }
            if (q == 1)
            {
                q = alphabet.Length;
            }
            List <NodeContent> looseVertices = new List <NodeContent>();
            OrientedGraph      graph         = new OrientedGraph();

            foreach (var item in frequencyList)
            {
                NodeContent content = new NodeContent(item.Key, item.Value);
                AddToListWithSort(looseVertices, content);
                graph.AddNode(new GraphNode(content));
            }

            while (looseVertices.Count > 1)
            {
                NodeContent newContent = new NodeContent();
                GraphNode   newNode    = new GraphNode(newContent);
                for (int i = 0; i < q; i++)
                {
                    NodeContent content = looseVertices[0];
                    newContent.Frequency += content.Frequency;
                    GraphNode node = graph.GetNode(content);
                    newNode.Connections.Add(node);
                    looseVertices.RemoveAt(0);
                }
                AddToListWithSort(looseVertices, newContent);
                graph.AddNode(newNode);
                q = alphabet.Length;
            }
            FrequencyCode     code             = new FrequencyCode();
            Queue <GraphNode> broadSearchQueue = new Queue <GraphNode>();

            broadSearchQueue.Enqueue(graph.GetNode(looseVertices[0]));

            while (broadSearchQueue.Count > 0)
            {
                GraphNode   node    = broadSearchQueue.Dequeue();
                NodeContent content = (NodeContent)node.NodeContent;
                if (node.Connections.Count == 0)
                {
                    code.Set(content.Symbol, content.Code, content.Frequency);
                }
                else
                {
                    for (int i = 0; i < node.Connections.Count; i++)
                    {
                        NodeContent childContent = (NodeContent)node.Connections[i].NodeContent;
                        childContent.Code = content.Code + alphabet[i];
                        broadSearchQueue.Enqueue(node.Connections[i]);
                    }
                }
            }
            return(code);
        }
Exemplo n.º 5
0
 public GraphInfo(OrientedGraph graph)
 {
     _adjacencyMatrix = graph.ToMatrix();
 }