예제 #1
0
 public static void tableResetIterator(ref TableIterator ti)
 {
     ti.i1          = 0;
     ti.i2          = 0;
     ti.i3          = 0;
     ti.i           = 0;
     ti.CheckLevel1 = 1;
     ti.CheckLevel2 = 1;
 }
        private Dictionary <string, string> getFileDict(string docFileName, out string dh)
        {
            dh = "";
            var dict = new Dictionary <string, string>();

            if (File.Exists(docFileName))
            {
                using (Stream stream = new FileStream(docFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    HWPFDocument hd             = new HWPFDocument(stream);
                    var          paraTable      = hd.ParagraphTable;
                    Range        rang           = hd.GetRange();
                    int          paragraphCount = rang.NumParagraphs;
                    for (int i = 0; i < paragraphCount; i++)
                    {
                        var pph  = rang.GetParagraph(i);
                        var text = pph.Text.Replace(":", ":").Replace(" ", "").Trim();
                        if (text.StartsWith("档号:"))
                        {
                            dh = text.Replace("档号:", "").Trim();
                            break;
                        }
                    }
                    rang = hd.GetRange();
                    TableIterator it = new TableIterator(rang);
                    while (it.HasNext())
                    {
                        NPOI.HWPF.UserModel.Table tb = (NPOI.HWPF.UserModel.Table)it.Next();
                        for (int i = 0; i < tb.NumRows; i++)
                        {
                            var row       = tb.GetRow(i);
                            var cellCount = row.numCells();
                            if (cellCount > 1)
                            {
                                var key   = row.GetCell(0).Text.Trim().Replace("\a", "");
                                var value = row.GetCell(1).Text.Trim().Replace("\a", "");
                                if (!dict.ContainsKey(key))
                                {
                                    dict.Add(key, value);
                                }
                            }
                        }
                    }
                }
            }
            return(dict);
        }
예제 #3
0
        public static int tableIterate(TableRoot table, ref TableIterator ti, ref uint *i, ref ACTCVertex refe)
        {
            int done;

            done = 0;
            while (ti.i1 < LEVEL1COUNT)
            {
                if (ti.CheckLevel1 == 1 && table.Table[ti.i1] == null)
                {
                    ti.i += LEVEL2COUNT * LEVEL3COUNT;
                    ti.i1++;
                    continue;
                }
                else
                {
                    ti.CheckLevel1 = 0;
                }

                if (ti.CheckLevel2 == 1 && table.Table[ti.i1].Table[ti.i2] == null)
                {
                    ti.i += LEVEL3COUNT;
                    if (++ti.i2 >= LEVEL2COUNT)
                    {
                        ti.i2 = 0;
                        ti.i1++;
                        ti.CheckLevel1 = 1;
                    }
                    continue;
                }
                else
                {
                    ti.CheckLevel2 = 0;
                }

                if (ti.i3 == 0)
                {
                    ti.CurLevel3 = table.Table[ti.i1].Table[ti.i2];
                }

                if (ti.CurLevel3.IsSet[ti.i3] != false)
                {
                    if (refe != null)
                    {
                        refe = ti.CurLevel3.Table[ti.i3];
                    }
                    if (i != null)
                    {
                        *i = ti.i;
                    }
                    done = 1;
                }
                ti.i++;
                if (++ti.i3 >= LEVEL3COUNT)
                {
                    ti.i3          = 0;
                    ti.CheckLevel2 = 1;
                    if (++ti.i2 >= LEVEL2COUNT)
                    {
                        ti.i2 = 0;
                        ti.i1++;
                        ti.CheckLevel1 = 1;
                    }
                }
                if (done == 1)
                {
                    return(1);
                }
            }
            return(0);
        }
예제 #4
0
        public RisksNet(String id)
        {
            Net   = new Network("risks" + id);
            Nodes = new List <Node>();

            // Add the nodes (variables)
            String[] arrStateBool     = { "False", "True" };
            String[] arrStateLevel    = { "1", "2", "3", "4", "5" };
            String[] arrSateNodeYesNo = { "no", "yes" };

            // tạo các node với các trạng thái tương ứng
            Node node1 = new Node("node1", arrStateLevel);

            Net.Nodes.Add(node1);
            Nodes.Add(node1);

            Node node2 = new Node("node2", arrStateBool);

            Net.Nodes.Add(node2);
            Nodes.Add(node2);

            Node node3 = new Node("node3", arrSateNodeYesNo);

            Net.Nodes.Add(node3);
            Nodes.Add(node3);

            Node node4 = new Node("node4", arrStateLevel);

            Net.Nodes.Add(node4);
            Nodes.Add(node4);

            Node node5 = new Node("node5", arrSateNodeYesNo);

            Net.Nodes.Add(node5);
            Nodes.Add(node5);

            Node node6 = new Node("node6", arrStateBool);

            Net.Nodes.Add(node6);
            Nodes.Add(node6);

            Node node7 = new Node("node7", arrStateBool);

            Net.Nodes.Add(node7);
            Nodes.Add(node7);

            Node node8 = new Node("node8", arrStateBool);

            Net.Nodes.Add(node8);
            Nodes.Add(node8);

            Node node9 = new Node("node9", arrStateBool);

            Net.Nodes.Add(node9);
            Nodes.Add(node9);

            Node node10 = new Node("node10", arrStateBool);

            Net.Nodes.Add(node10);
            Nodes.Add(node10);

            Node node11 = new Node("node11", arrStateLevel);

            Net.Nodes.Add(node11);
            Nodes.Add(node11);

            Node node12 = new Node("node12", arrStateBool);

            Net.Nodes.Add(node12);
            Nodes.Add(node12);

            Node node13 = new Node("node13", arrStateBool);

            Net.Nodes.Add(node13);
            Nodes.Add(node13);

            Node node14 = new Node("node14", arrSateNodeYesNo);

            Net.Nodes.Add(node14);
            Nodes.Add(node14);

            Node node15 = new Node("node15", arrStateBool);

            Net.Nodes.Add(node15);
            Nodes.Add(node15);

            Node node16 = new Node("node16", arrStateBool);

            Net.Nodes.Add(node16);
            Nodes.Add(node16);

            Node node17 = new Node("node17", arrStateBool);

            Net.Nodes.Add(node17);
            Nodes.Add(node17);

            Node node18 = new Node("node18", arrStateBool);

            Net.Nodes.Add(node18);
            Nodes.Add(node18);

            Node node19 = new Node("node19", arrStateBool);

            Net.Nodes.Add(node19);
            Nodes.Add(node19);

            Node node20 = new Node("node20", arrStateBool);

            Net.Nodes.Add(node20);
            Nodes.Add(node20);

            Node node21 = new Node("node21", arrStateBool);

            Net.Nodes.Add(node21);
            Nodes.Add(node21);

            Node node22 = new Node("node22", arrStateBool);

            Net.Nodes.Add(node22);
            Nodes.Add(node22);

            Node node23 = new Node("node23", arrStateBool);

            Net.Nodes.Add(node23);
            Nodes.Add(node23);

            Node node24 = new Node("node24", arrStateBool);

            Net.Nodes.Add(node24);
            Nodes.Add(node23);


            Node risk = new Node("risk", arrStateBool);

            Net.Nodes.Add(risk);
            Nodes.Add(risk);

            // Add các link cho các node trong mạng
            Net.Links.Add(new Link(node1, risk));
            Net.Links.Add(new Link(node3, node7));
            Net.Links.Add(new Link(node3, node9));
            Net.Links.Add(new Link(node3, node12));
            Net.Links.Add(new Link(node3, node17));
            Net.Links.Add(new Link(node3, node23));
            Net.Links.Add(new Link(node3, node24));
            Net.Links.Add(new Link(node3, risk));
            Net.Links.Add(new Link(node4, node2));
            Net.Links.Add(new Link(node4, node3));
            Net.Links.Add(new Link(node4, node5));
            Net.Links.Add(new Link(node5, node1));
            Net.Links.Add(new Link(node9, node6));
            Net.Links.Add(new Link(node9, node8));
            Net.Links.Add(new Link(node9, node11));
            Net.Links.Add(new Link(node9, node16));
            Net.Links.Add(new Link(node9, node17));
            Net.Links.Add(new Link(node9, node22));
            Net.Links.Add(new Link(node9, risk));
            Net.Links.Add(new Link(node10, node11));
            Net.Links.Add(new Link(node11, risk));
            Net.Links.Add(new Link(node12, node13));
            Net.Links.Add(new Link(node13, risk));
            Net.Links.Add(new Link(node14, node3));
            Net.Links.Add(new Link(node14, node15));
            Net.Links.Add(new Link(node14, risk));
            Net.Links.Add(new Link(node18, node1));
            Net.Links.Add(new Link(node18, risk));
            Net.Links.Add(new Link(node19, node1));
            Net.Links.Add(new Link(node20, node1));
            Net.Links.Add(new Link(node21, node16));

            // thêm bảng phân phối xác suất cho các node
            int           index     = 0;
            Table         table1    = node1.NewDistribution().Table;
            TableIterator iterator1 = new TableIterator(table1, new Node[] { node1, node5, node18, node19, node20 });

            double[] dist = ListDistribution[index++];
            dist = normalize(dist, 5, dist.Length / 5);
            iterator1.CopyFrom(dist);
            node1.Distribution = table1;

            Table         table2    = node2.NewDistribution().Table;
            TableIterator iterator2 = new TableIterator(table2, new Node[] { node2, node4 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator2.CopyFrom(dist);
            node2.Distribution = table2;

            Table         table3    = node3.NewDistribution().Table;
            TableIterator iterator3 = new TableIterator(table3, new Node[] { node3, node4, node14 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator3.CopyFrom(dist);
            node3.Distribution = table3;

            Table         table4    = node4.NewDistribution().Table;
            TableIterator iterator4 = new TableIterator(table4, new Node[] { node4 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 5, dist.Length / 5);
            iterator4.CopyFrom(dist);
            node4.Distribution = table4;

            Table         table5    = node5.NewDistribution().Table;
            TableIterator iterator5 = new TableIterator(table5, new Node[] { node5, node4 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator5.CopyFrom(dist);
            node5.Distribution = table5;

            Table         table6    = node6.NewDistribution().Table;
            TableIterator iterator6 = new TableIterator(table6, new Node[] { node6, node9 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator6.CopyFrom(dist);
            node6.Distribution = table6;

            Table         table7    = node7.NewDistribution().Table;
            TableIterator iterator7 = new TableIterator(table7, new Node[] { node7, node3 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator7.CopyFrom(dist);
            node7.Distribution = table7;

            Table         table8    = node8.NewDistribution().Table;
            TableIterator iterator8 = new TableIterator(table8, new Node[] { node8, node9 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator8.CopyFrom(dist);
            node8.Distribution = table8;

            Table         table9    = node9.NewDistribution().Table;
            TableIterator iterator9 = new TableIterator(table9, new Node[] { node9, node3 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator9.CopyFrom(dist);
            node9.Distribution = table9;

            Table         table10    = node10.NewDistribution().Table;
            TableIterator iterator10 = new TableIterator(table10, new Node[] { node10 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator10.CopyFrom(dist);
            node10.Distribution = table10;

            Table         table11    = node11.NewDistribution().Table;
            TableIterator iterator11 = new TableIterator(table11, new Node[] { node11, node9, node10 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 5, dist.Length / 5);
            iterator11.CopyFrom(dist);
            node11.Distribution = table11;

            Table         table12    = node12.NewDistribution().Table;
            TableIterator iterator12 = new TableIterator(table12, new Node[] { node12, node3 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator12.CopyFrom(dist);
            node12.Distribution = table12;

            Table         table13    = node13.NewDistribution().Table;
            TableIterator iterator13 = new TableIterator(table13, new Node[] { node13, node12 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator13.CopyFrom(dist);
            node13.Distribution = table13;

            Table         table14    = node14.NewDistribution().Table;
            TableIterator iterator14 = new TableIterator(table14, new Node[] { node14 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator14.CopyFrom(dist);
            node14.Distribution = table14;

            Table         table15    = node15.NewDistribution().Table;
            TableIterator iterator15 = new TableIterator(table15, new Node[] { node15, node14 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator15.CopyFrom(dist);
            node15.Distribution = table15;


            Table         table16    = node16.NewDistribution().Table;
            TableIterator iterator16 = new TableIterator(table16, new Node[] { node16, node9, node21 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator16.CopyFrom(dist);
            node16.Distribution = table16;



            Table         table17    = node17.NewDistribution().Table;
            TableIterator iterator17 = new TableIterator(table17, new Node[] { node17, node3, node9 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator17.CopyFrom(dist);
            node17.Distribution = table17;

            Table         table18    = node18.NewDistribution().Table;
            TableIterator iterator18 = new TableIterator(table18, new Node[] { node18 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator18.CopyFrom(dist);
            node18.Distribution = table18;

            Table         table19    = node19.NewDistribution().Table;
            TableIterator iterator19 = new TableIterator(table19, new Node[] { node19 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator19.CopyFrom(dist);
            node19.Distribution = table19;

            Table         table20    = node20.NewDistribution().Table;
            TableIterator iterator20 = new TableIterator(table20, new Node[] { node20 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator20.CopyFrom(dist);
            node20.Distribution = table20;

            Table         table21    = node21.NewDistribution().Table;
            TableIterator iterator21 = new TableIterator(table21, new Node[] { node21 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator21.CopyFrom(dist);
            node21.Distribution = table21;

            Table         table22    = node22.NewDistribution().Table;
            TableIterator iterator22 = new TableIterator(table22, new Node[] { node22, node9 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator22.CopyFrom(dist);
            node22.Distribution = table22;

            Table         table23    = node23.NewDistribution().Table;
            TableIterator iterator23 = new TableIterator(table23, new Node[] { node23, node3 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator23.CopyFrom(dist);
            node23.Distribution = table23;

            Table         table24    = node24.NewDistribution().Table;
            TableIterator iterator24 = new TableIterator(table24, new Node[] { node24, node3 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);
            iterator24.CopyFrom(dist);
            node24.Distribution = table24;


            Table         tableRisk    = risk.NewDistribution().Table;
            TableIterator iteratorRisk = new TableIterator(tableRisk, new Node[] { risk, node1, node3, node9, node11, node13, node14, node18 });

            dist = ListDistribution[index++];
            dist = normalize(dist, 2, dist.Length / 2);

            iteratorRisk.CopyFrom(dist);
            risk.Distribution = tableRisk;
        }
예제 #5
0
        public ValueNet(String id)
        {
            Net   = new Network("value" + id);
            Nodes = new List <Node>();

            String[] arrStateString_2 = { "Low", "High" };
            String[] arrStateString_3 = { "Low", "Medium", "High" };

            //Priority
            Node priority = new Node("Priority", arrStateString_3);

            Net.Nodes.Add(priority);
            Nodes.Add(priority);

            //Experience
            Node experience = new Node("Experience", arrStateString_3);

            Net.Nodes.Add(experience);
            Nodes.Add(experience);


            //Complexity
            Node complexity = new Node("Complexity", arrStateString_3);

            Net.Nodes.Add(complexity);
            Nodes.Add(complexity);

            //Effort
            Node effort = new Node("Effort", arrStateString_3);

            Net.Nodes.Add(effort);
            Nodes.Add(effort);

            //Time
            Node time = new Node("Time", arrStateString_3);

            Net.Nodes.Add(time);
            Nodes.Add(time);

            //Labor
            Node labor = new Node("Labor", arrStateString_2);

            Net.Nodes.Add(labor);
            Nodes.Add(labor);

            //Challenges
            Node challenges = new Node("Challenges", arrStateString_2);

            Net.Nodes.Add(challenges);
            Nodes.Add(challenges);

            //Task value
            Node value = new Node("Value", arrStateString_2);

            Net.Nodes.Add(value);
            Nodes.Add(value);

            //Add links
            Net.Links.Add(new Link(priority, value));
            Net.Links.Add(new Link(labor, value));
            Net.Links.Add(new Link(challenges, value));
            Net.Links.Add(new Link(experience, labor));
            Net.Links.Add(new Link(complexity, labor));
            Net.Links.Add(new Link(time, challenges));
            Net.Links.Add(new Link(effort, challenges));

            //Distributions
            Table         table1    = labor.NewDistribution().Table;
            TableIterator iterator1 = new TableIterator(table1, new Node[] { labor, experience, complexity });

            double[] dist = ListDistribution[0];
            dist = normalize(dist, 2, 9);
            iterator1.CopyFrom(dist);
            labor.Distribution = table1;

            Table         table2    = challenges.NewDistribution().Table;
            TableIterator iterator2 = new TableIterator(table2, new Node[] { challenges, time, effort });

            dist = ListDistribution[1];
            dist = normalize(dist, 2, 9);
            iterator2.CopyFrom(dist);
            challenges.Distribution = table2;

            Table         table3    = value.NewDistribution().Table;
            TableIterator iterator3 = new TableIterator(table3, new Node[] { value, priority, labor, challenges });

            dist = ListDistribution[2];
            dist = normalize(dist, 2, 12);
            iterator3.CopyFrom(dist);
            value.Distribution = table3;
        }