Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (!(obj is DataOutStruct))
            {
                return(false);
            }

            DataOutStruct other = (DataOutStruct)obj;

            return(Equals(other));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private static List <DataOutStruct> CombineOuts(LightWeightGraph healthy, LightWeightGraph infected, List <DataOutStruct> outData)
        {
            List <DataOutStruct> finalOut      = new List <DataOutStruct>();
            List <DataOutStruct> healthyNodes  = new List <DataOutStruct>();
            List <DataOutStruct> infectedNodes = new List <DataOutStruct>();

            foreach (var node in healthy.Nodes)
            {
                DataOutStruct singleNode = new DataOutStruct
                {
                    GroupNum = "0", Bacteria = node.sharedName, ClusterType = ""
                };
                healthyNodes.Add(singleNode);
            }
            foreach (var node in infected.Nodes)
            {
                DataOutStruct singleNode = new DataOutStruct
                {
                    GroupNum = "0", Bacteria = node.sharedName, ClusterType = ""
                };
                infectedNodes.Add(singleNode);
            }
            foreach (DataOutStruct bacteria in outData)
            {
                foreach (DataOutStruct healthyNode in healthyNodes)
                {
                    if (bacteria.Bacteria.Equals(healthyNode.Bacteria))
                    {
                        healthyNode.GroupNum = "1";
                    }
                }
                foreach (DataOutStruct infectedNode in infectedNodes)
                {
                    if (bacteria.Bacteria.Equals(infectedNode.Bacteria))
                    {
                        infectedNode.GroupNum = "1";
                    }
                }
            }

            finalOut = healthyNodes.Union(infectedNodes).Distinct().OrderByDescending(x => x.GroupNum).ThenBy(x => x.Bacteria).ToList();
            return(finalOut);
        }
Exemplo n.º 5
0
 public bool Equals(DataOutStruct other)
 {
     return(Bacteria == other.Bacteria && ClusterType == other.ClusterType &&
            GroupNum == other.GroupNum);
 }