Example #1
0
        public Dictionary <string, string> CalculateDistance(Session session, Tumourus specificCell)
        {
            double xDiff = 0, yDiff = 0, zDiff = 0;
            Dictionary <string, string> distances = new Dictionary <string, string>();

            if (session.RedBloodCells.Any())
            {
                foreach (Cell item in session.RedBloodCells) // calculates the distance between the tumourus cell and the red blood cell
                {
                    xDiff = Math.Pow(int.Parse(item.Location.XCoordinate) - int.Parse(specificCell.Location.XCoordinate), 2);
                    yDiff = Math.Pow(int.Parse(item.Location.YCoordinate) - int.Parse(specificCell.Location.YCoordinate), 2);
                    zDiff = Math.Pow(int.Parse(item.Location.ZCoordinate) - int.Parse(specificCell.Location.ZCoordinate), 2);
                    distances.Add(item.ID, xDiff.ToString() + " " + yDiff.ToString() + " " + zDiff.ToString());
                }
                distances = distances.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value); // sort the dictonary to put the shortest distance first
                return(distances);
            }
            else if (session.WhiteBloodCells.Any())
            {
                foreach (Cell item in session.WhiteBloodCells)
                {
                    xDiff = Math.Pow(int.Parse(item.Location.XCoordinate) - int.Parse(specificCell.Location.XCoordinate), 2);
                    yDiff = Math.Pow(int.Parse(item.Location.YCoordinate) - int.Parse(specificCell.Location.YCoordinate), 2);
                    zDiff = Math.Pow(int.Parse(item.Location.ZCoordinate) - int.Parse(specificCell.Location.ZCoordinate), 2);
                    distances.Add(item.ID, xDiff.ToString() + " " + yDiff.ToString() + " " + zDiff.ToString());
                }
                distances = distances.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value); // sort the dictonary to put the shortest distance first
                return(distances);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public Session KillCell(Session session, Tumourus tumourus)
        {
            Dictionary <string, string> distances = new Dictionary <string, string>();

            distances = CalculateDistance(session, tumourus);
            try
            {
                var firstElement = distances.FirstOrDefault();
                try
                {
                    if (session.RedBloodCells.Any())
                    {
                        foreach (Cell item in session.RedBloodCells)
                        {
                            if (firstElement.Key == item.ID)
                            {
                                session.RedBloodCells.Remove(item);
                                session.TumourusCells.Add(new Tumourus(item.ID, "Tumourus", item.Location));
                            }
                        }
                    }
                    else
                    {
                        foreach (Cell item in session.WhiteBloodCells)
                        {
                            if (firstElement.Key == item.ID)
                            {
                                session.WhiteBloodCells.Remove(item);
                                session.TumourusCells.Add(new Tumourus(item.ID, "Tumourus", item.Location));
                            }
                        }
                    }

                    return(session);
                }
                catch (Exception e)
                {
                    return(session);
                }
            }
            catch (Exception e)
            {
                return(session);
            }
        }
Example #3
0
        public void GenerateCells()
        {
            bool            isValid = false;
            int             probablity = 0, totalRBC = 0, totalWBC = 0, totalTC = 0, totalNV = 1, lifeCycles = 0;
            List <Location> locationsTaken = new List <Location>();
            Location        location;
            string          xCoordinate, yCoordinate, zCoordinate;

            for (int i = 0; i < 100; i++)
            {
                probablity  = rand.Next(1, 100);
                xCoordinate = rand.Next(1, 5000).ToString();
                yCoordinate = rand.Next(1, 5000).ToString();
                zCoordinate = rand.Next(1, 5000).ToString();
                location    = new Location(xCoordinate, yCoordinate, zCoordinate);
                isValid     = CheckValidLocation(location, locationsTaken);
                if (isValid)
                {
                    locationsTaken.Add(location);
                    if (probablity > 0 || probablity <= 5)
                    {
                        totalTC++;
                        Tumourus tumourus = new Tumourus
                        {
                            ID   = rand.Next(1, 5000).ToString(),
                            Name = "Tumorous"
                        };
                        tumourus.Location.XCoordinate = location.XCoordinate;
                        tumourus.Location.YCoordinate = location.YCoordinate;
                        tumourus.Location.ZCoordinate = location.ZCoordinate;
                        tumourusCells.Add(tumourus);
                    }
                    else if (Convert.ToInt32(probablity) > 5 || Convert.ToInt32(probablity) <= 25)
                    {
                        totalWBC++;
                        Cell cell = new Cell
                        {
                            ID   = rand.Next(1, 5000).ToString(),
                            Type = "White Blood"
                        };
                        cell.Location.XCoordinate = location.XCoordinate;
                        cell.Location.YCoordinate = location.YCoordinate;
                        cell.Location.ZCoordinate = location.ZCoordinate;
                        whiteBloodCells.Add(cell);
                    }
                    else
                    {
                        totalRBC++;
                        Cell cell = new Cell
                        {
                            ID   = rand.Next(1, 5000).ToString(),
                            Type = "Red Blood"
                        };
                        cell.Location.XCoordinate = location.XCoordinate;
                        cell.Location.YCoordinate = location.YCoordinate;
                        cell.Location.ZCoordinate = location.ZCoordinate;
                        redBloodCells.Add(cell);
                    }
                }
            }
            session  = new Session(totalRBC, totalWBC, totalNV, totalTC, lifeCycles, tumourusCells, redBloodCells, whiteBloodCells, nanoVirusCells);
            rootNode = new Node(totalRBC, totalWBC, totalNV, totalTC, lifeCycles);
        }