Exemple #1
0
        private static void WriteToConsole(string message, OutType outType = OutType.Info)
        {
            var backupBackground = Console.BackgroundColor;
            var backupForeground = Console.ForegroundColor;

            Console.BackgroundColor = OutColors[outType];
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write($"[{outType.ToString().ToUpper()}]");
            Console.BackgroundColor = backupBackground;

            Console.ForegroundColor = OutColors[outType];
            var spaces = Enumerable.Repeat(" ", 8 - outType.ToString().Length).Aggregate((acc, item) => acc + item);

            Console.WriteLine($"{spaces}{message}");
            Console.ForegroundColor = backupForeground;
        }
Exemple #2
0
        /// <summary>
        /// G3 finds all unique singular group numbers that are
        /// </summary>
        public static List <DataOutStruct> G3(List <List <DataOutStruct> > initList, Partition healthyPartition,
                                              Partition infectedPartition, OutType type)
        {
            List <DataOutStruct> healthy      = new List <DataOutStruct>();
            List <DataOutStruct> infected     = new List <DataOutStruct>();
            List <DataOutStruct> healthyList  = new List <DataOutStruct>();
            List <DataOutStruct> infectedList = new List <DataOutStruct>();

            foreach (Cluster cluster in healthyPartition.Clusters)
            {
                if (cluster.Points.Count == 1)
                {
                    DataOutStruct singleNode = new DataOutStruct();
                    singleNode.Bacteria    = healthyPartition.Graph.Nodes[cluster.Points[0].Id].sharedName;
                    singleNode.ClusterType = type.ToString();
                    singleNode.GroupNum    = "";
                    healthy.Add(singleNode);
                }
            }

            foreach (Cluster cluster in infectedPartition.Clusters)
            {
                if (cluster.Points.Count == 1)
                {
                    DataOutStruct singleNode = new DataOutStruct();
                    singleNode.Bacteria    = infectedPartition.Graph.Nodes[cluster.Points[0].Id].sharedName;
                    singleNode.ClusterType = type.ToString();
                    singleNode.GroupNum    = "";
                    infected.Add(singleNode);
                }
            }

            List <String> commonHealthy =
                healthy.Select(x => x.Bacteria).Intersect(initList[1].Select(i => i.Bacteria)).ToList();
            List <String> commonInfected =
                infected.Select(x => x.Bacteria).Intersect(initList[0].Select(i => i.Bacteria)).ToList();

            infectedList = infected.Except(healthy).Distinct().Where(x => commonInfected.Any(n => n.Equals(x.Bacteria)))
                           .ToList();
            healthyList = healthy.Except(infected).Distinct().Where(x => commonHealthy.Any(n => n.Equals(x.Bacteria)))
                          .ToList();
            List <DataOutStruct> outList = healthyList.Union(infectedList).Distinct().OrderBy(x => x.Bacteria).ToList();

            return(outList);
        }
Exemple #3
0
        private static List <DataOutStruct> GroupNumberInitializer(Partition p, int[] cluster, String fileName,
                                                                   String fileEnd,
                                                                   OutType type)
        {
            List <DataOutStruct> dataOut = new List <DataOutStruct>();

            for (int i = 0; i < p.DataCount; i++)
            {
                cluster[i] = -1;
            }

            for (int i = 0; i < p.Clusters.Count(); i++)
            {
                for (int j = 0; j < p.Clusters[i].Points.Count(); j++)
                {
                    cluster[p.Clusters[i].Points[j].Id] = p.Clusters[i].Points[j].ClusterId;
                }
            }

            for (int i = 0; i < p.DataCount; i++)
            {
                DataOutStruct outObj = new DataOutStruct();
                outObj.Bacteria    = p.Graph.Nodes[i].sharedName;
                outObj.ClusterType = type.ToString();
                if (cluster[i] != -1)
                {
                    outObj.GroupNum = cluster[i].ToString();
                }
                else
                {
                    outObj.GroupNum = "N/A";
                }

                dataOut.Add(outObj);
            }
            using (StreamWriter sw = new StreamWriter($"Data/{fileName}{fileEnd}"))

                for (int i = 0; i < dataOut.Count(); i++)
                {
                    {
                        sw.WriteLine(dataOut[i].Bacteria + "," + dataOut[i].GroupNum + "," + dataOut[i].ClusterType);
                    }
                }

            return(dataOut);
        }