Ejemplo n.º 1
0
        private void NetworkFromFile(string fileName)
        {
            StreamReader file = new StreamReader(fileName);

            if (file == null)
            {
                throw new FileNotFoundException();
            }
            int numberOfPС = Convert.ToInt32(file.ReadLine());

            //Fill adjacency matrix.
            adjacencyMatrix = new bool[numberOfPС, numberOfPС];
            for (int i = 0; i < numberOfPС; i++)
            {
                string[] temp = file.ReadLine().Split(' ');
                for (int j = 0; j < numberOfPС; j++)
                {
                    adjacencyMatrix[i, j] = Convert.ToBoolean(Convert.ToInt32(temp[j]));
                }
            }

            //Fill list of OS.
            int numberOfOS = Convert.ToInt32(file.ReadLine());

            OSList = new OS[numberOfOS];
            for (int i = 0; i < numberOfOS; i++)
            {
                string[] temp = file.ReadLine().Split(' ');
                OSList[i] = new OS(temp[0], Convert.ToInt32(temp[1]));
            }

            //Fill list of PS.
            PСList = new PС[numberOfPС];
            for (int i = 0; i < numberOfPС; i++)
            {
                PСList[i] = new PС(false, OSByName(file.ReadLine()));
            }

            //Count alredy infected compters.
            string[] tempor = file.ReadLine().Split(' ');
            if (tempor[0] != "0")
            {
                numberOfInfectedPС = tempor.Length;
                for (int i = 0; i < numberOfInfectedPС; i++)
                {
                    PСList[Convert.ToInt32(tempor[i]) - 1].Infected = true;
                }
            }
            file.Close();
        }
Ejemplo n.º 2
0
        private void NetworkFromFile(string fileName)
        {
            StreamReader file = new StreamReader(fileName);
            if (file == null)
            {
                throw new FileNotFoundException();
            }
            int numberOfPС = Convert.ToInt32(file.ReadLine());

            //Fill adjacency matrix.
            adjacencyMatrix = new bool[numberOfPС, numberOfPС];
            for (int i = 0; i < numberOfPС; i++)
            {
                string[] temp = file.ReadLine().Split(' ');
                for (int j = 0; j < numberOfPС; j++)
                {
                    adjacencyMatrix[i, j] = Convert.ToBoolean(Convert.ToInt32(temp[j]));
                }
            }

            //Fill list of OS.
            int numberOfOS = Convert.ToInt32(file.ReadLine());
            OSList = new OS[numberOfOS];
            for (int i = 0; i < numberOfOS; i++)
            {
                string[] temp = file.ReadLine().Split(' ');
                OSList[i] = new OS(temp[0], Convert.ToInt32(temp[1]));
            }

            //Fill list of PS.
            PСList = new PС[numberOfPС];
            for (int i = 0; i <numberOfPС; i++)
            {
                PСList[i] = new PС(false, OSByName(file.ReadLine()));
            }

            //Count alredy infected compters.
            string[] tempor = file.ReadLine().Split(' ');
            if (tempor[0] != "0")
            {
                numberOfInfectedPС = tempor.Length;
                for (int i = 0; i < numberOfInfectedPС; i++)
                {
                    PСList[Convert.ToInt32(tempor[i]) - 1].Infected = true;
                }
            }
            file.Close();
        }
Ejemplo n.º 3
0
 private bool OSAllowToinfect(PС pсToCheck)
 {
     return(random.Next(99) <= pсToCheck.OSType.Probability);
 }
Ejemplo n.º 4
0
 private bool OSAllowToinfect(PС pсToCheck)
 {
     return random.Next(99) <= pсToCheck.OSType.Probability;
 }