Example #1
0
        public static void Main(string[] args)
        {
            // Semente aleatória para o programa
            Random rand = new Random();

            // Tempo Servidor de Aplicações Interação 2
            Func <double> tSA2 = () =>
            {
                return(GetUniform(rand, 40, 60));
            };
            // Tempo Servidor de Aplicações Interação 3
            Func <double> tSA3 = () =>
            {
                return(GetUniform(rand, 60, 120));
            };

            // Tempo Servidor Web Interação 1
            Func <double> tSW1 = () =>
            {
                return(GetUniform(rand, 4, 6));
            };
            // Tempo Servidor Web Interação 2-2
            Func <double> tSW22 = () =>
            {
                return(GetUniform(rand, 5, 7));
            };
            // Tempo Servidor Web Interação 2-5
            Func <double> tSW25 = () =>
            {
                return(GetUniform(rand, 7, 10));
            };
            // Tempo Servidor Web Interação 3
            Func <double> tSW3 = () =>
            {
                return(GetUniform(rand, 9, 12));
            };

            // Tempo Banco de Dados
            Func <double> tBD = () =>
            {
                return(GetUniform(rand, 15, 30) + GetUniform(rand, 50, 400));
            };

            // Funções de Calcular tamanho
            Func <double> m1 = () =>
            {
                return(GetTriangular(rand, 100, 200, 250) * overHeadProtocolo);
            };
            Func <double> m2 = () =>
            {
                return(GetTriangular(rand, 100, 200, 300) * overHeadProtocolo);
            };
            Func <double> m3 = () =>
            {
                return(GetTriangular(rand, 250, 400, 450) * overHeadProtocolo);
            };
            Func <double> m4 = () =>
            {
                return(GetTriangular(rand, 1500, 2500, 3000) * overHeadProtocolo);
            };
            Func <double> m5 = () =>
            {
                return(GetTriangular(rand, 1500, 2100, 2800) * overHeadProtocolo);
            };
            Func <double> m6 = () =>
            {
                return(GetTriangular(rand, 400, 550, 800) * overHeadProtocolo);
            };
            Func <double> m7 = () =>
            {
                return(GetTriangular(rand, 2000, 3000, 3500) * overHeadProtocolo);
            };
            Func <double> m8 = () =>
            {
                return(GetTriangular(rand, 1800, 2000, 2300) * overHeadProtocolo);
            };
            Func <double> m9 = () =>
            {
                return(GetTriangular(rand, 1500, 2100, 2800) * overHeadProtocolo);
            };

            var no1 = new Activity
            {
                Nome       = "Requisição do Cliente (Nó 1)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m1();
                    return(GetTempoInternet(tamanho) + aRoteador + GetTempoLan(tamanho) + procCliente);
                }
            };

            var intersec1 = new Activity
            {
                Nome       = "Intersecção 1",
                Print      = false,
                CalcularTS = () =>
                {
                    return(0.0);
                }
            };

            var no2_int1 = new Activity
            {
                Nome       = "Servidor Web - Retornar ao Cliente (Nó 2 - Interação 1)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m2();
                    return(GetTempoLan(tamanho) + aRoteador + GetTempoInternet(tamanho) + procCliente + tSW1());
                }
            };

            var no2_int2 = new Activity
            {
                Nome       = "Servidor Web - Ir para o Servidor de Aplicação (Nó 2 - Interação 2)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m3();
                    return(GetTempoLan(tamanho) + tSW22());
                }
            };

            var no3 = new Activity
            {
                Nome       = "Cliente - Interação 1 (Nó 3)",
                Print      = true,
                CalcularTS = () =>
                {
                    return(0.0);
                }
            };

            var intersec2 = new Activity
            {
                Nome       = "Intersecção 2",
                Print      = false,
                CalcularTS = () =>
                {
                    return(0.0);
                }
            };

            var no4_int2 = new Activity
            {
                Nome       = "Servidor de Aplicação - Ir para Servidor Web (Nó 4 - Interação 2)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m4();
                    return(GetTempoLan(tamanho) + tSA2());
                }
            };

            var no4_int3 = new Activity
            {
                Nome       = "Servidor de Aplicação - Ir para Servidor de Banco de Dados (Nó 4 - Interação 3)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m6();
                    return(GetTempoLan(tamanho) + tSA3());
                }
            };

            var no5 = new Activity
            {
                Nome       = "Servidor Web - Ir para o Cliente (Nó 5)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m5();
                    return(GetTempoLan(tamanho) + aRoteador + GetTempoInternet(tamanho) + procCliente + tSW25());
                }
            };

            var no6 = new Activity
            {
                Nome       = "Cliente - Interação 2 (Nó 6)",
                Print      = true,
                CalcularTS = () =>
                {
                    return(0.0);
                }
            };

            var no7 = new Activity
            {
                Nome       = "Servidor de Banco de Dados - Ir para Servidor de Aplicação (Nó 7)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m7();
                    return(GetTempoLan(tamanho) + tBD());
                }
            };

            var no8 = new Activity
            {
                Nome       = "Servidor de Aplicação - Ir para o Servidor Web (Nó 8)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m8();
                    return(GetTempoLan(tamanho) + tSA3());
                }
            };

            var no9 = new Activity
            {
                Nome       = "Servidor Web - Ir para o Cliente (Nó 9)",
                Print      = true,
                CalcularTS = () =>
                {
                    var tamanho = m9();
                    return(GetTempoLan(tamanho) + aRoteador + GetTempoInternet(tamanho) + procCliente + tSW3());
                }
            };

            var no10 = new Activity
            {
                Nome       = "Cliente - Interação 3 (Nó 10)",
                Print      = true,
                CalcularTS = () =>
                {
                    return(0.0);
                }
            };

            var visitas      = new List <SItem>();
            var ritmoChegada = 3600.0 / 250.0;
            var chegada      = 0.0;

            // Gera As visitas
            for (int i = 0; i < 30; i++)
            {
                visitas.Add(new SItem
                {
                    Nome   = String.Format("Visita {0}", i + 1),
                    Inicio = chegada
                });
                chegada += (-ritmoChegada) * Math.Log(rand.NextDouble());
            }

            foreach (SItem visita in visitas.OrderBy(v => v.Inicio))
            {
                Console.WriteLine(string.Format("{0} chegou: {1}", visita.Nome, visita.Inicio));
            }

            Console.WriteLine();

            // Preenche a fila de chegada de a1
            no1.PreencheItensEntrada(visitas);

            // Configura as conexões entre as atividades

            // Nó 1 para a decisão entre Interação 1 e 2
            no1.AddConection(intersec1);

            // Decisão entre Interação 1 e 2
            intersec1.AddConection(no2_int1, 0.05);
            intersec1.AddConection(no2_int2);

            // Nó 2 na interação 1 indo para o Cliente
            no2_int1.AddConection(no3);

            // Nó 2 na interação 2 indo para o Servidor de Aplicação - Interseção entre Interação 2 e 3
            no2_int2.AddConection(intersec2);

            // Decisão entre Interação 2 e 3
            intersec2.AddConection(no4_int2, 0.2);
            intersec2.AddConection(no4_int3);

            // Nó 4
            no4_int2.AddConection(no5);
            no4_int3.AddConection(no7);

            // Nó 5
            no5.AddConection(no6);

            // Nó 7
            no7.AddConection(no8);

            // Nó 8
            no8.AddConection(no9);

            // Nó 9
            no9.AddConection(no10);


            // Connecta as atividades (Independente neste caso)
            no1.SetupConnections();

            // Roda a simulação;
            no1.Run();
        }
Example #2
0
        public static void Main(string[] args)
        {
            Activity.numeroAmostra = 5;
            // Criando atividades
            var entrada = new Activity
            {
                Nome    = "Entrada",
                Media   = 0,
                DesvPad = 0
            };
            var lavagem = new Activity
            {
                Nome    = "Lavagem",
                Media   = 10,
                DesvPad = 2,
                Print   = true
            };
            var sabao = new Activity
            {
                Nome    = "Sabao",
                Media   = 6,
                DesvPad = 1,
                Print   = true
            };
            var enxague = new Activity
            {
                Nome    = "Enxague",
                Media   = 12,
                DesvPad = 2,
                Print   = true
            };
            var centroManutencao = new Activity
            {
                Nome    = "Centro Manutenção",
                Media   = 18,
                DesvPad = 5,
                Print   = true
            };
            var lanchonete = new Activity
            {
                Nome    = "Lanchonete",
                Media   = 20,
                DesvPad = 4,
                Print   = true
            };
            var aspirador = new Activity
            {
                Nome    = "Aspirador",
                Media   = 16,
                DesvPad = 4,
                Print   = true
            };
            var intersec = new Activity
            {
                Nome = "Intersec"
            };
            var saida1 = new Activity
            {
                Nome = "Saída1"
            };
            var saida2 = new Activity
            {
                Nome = "Saída2"
            };
            var saida3 = new Activity
            {
                Nome = "Saída3"
            };

            // Conectando

            entrada.AddConection(lavagem, 0.7);
            entrada.AddConection(centroManutencao);
            lavagem.AddConection(sabao);
            lavagem.AddConection(aspirador, 0.5);
            sabao.AddConection(enxague);
            enxague.AddConection(aspirador);
            aspirador.AddConection(lanchonete);
            aspirador.AddConection(saida2, 0.5);
            centroManutencao.AddConection(saida1, 0.2);
            centroManutencao.AddConection(intersec);
            intersec.AddConection(lanchonete);
            intersec.AddConection(lavagem, 0.5);
            lanchonete.AddConection(saida3);

            entrada.SetupConnections();

            // Checando
            PrintActivity(lavagem);
            PrintActivity(sabao);
            PrintActivity(enxague);
            PrintActivity(aspirador);
            PrintActivity(saida2);
            PrintActivity(centroManutencao);
            PrintActivity(saida1);
            PrintActivity(lanchonete);
            PrintActivity(saida3);

            var entradas = new List <SItem>
            {
                new SItem
                {
                    Inicio = 0,
                    Nome   = "Carro1"
                },
                new SItem
                {
                    Inicio = 4,
                    Nome   = "Carro2"
                },
                new SItem
                {
                    Inicio = 7,
                    Nome   = "Carro3"
                },
                new SItem
                {
                    Inicio = 13,
                    Nome   = "Carro4"
                },
                new SItem
                {
                    Inicio = 15,
                    Nome   = "Carro5"
                }
            };



            Console.WriteLine("\n\n======Teste 2======");

            foreach (SItem i in entradas)
            {
                entrada.FilaEntrada.Add(i);
            }

            entrada.Run();
        }
Example #3
0
        public static void Main(string[] args)
        {
            var rand    = new Random();
            int n       = 10;
            var carros  = new List <SItem>();
            int chegada = 0;

            for (int i = 0; i < n; i++)
            {
                carros.Add(new SItem
                {
                    Nome   = String.Format("Carro {0}", i + 1),
                    Inicio = chegada
                });
                chegada += (int)Math.Round((-8) * Math.Log(rand.NextDouble()));
            }

            var pontoA = new Activity
            {
                Print = false
            };
            var lavaRapido = new Activity
            {
                Nome    = "Lava Rápido",
                Media   = 10,
                DesvPad = 2,
                Print   = true
            };
            var pontoC = new Activity
            {
                Print = false
            };
            var centroManutenção = new Activity
            {
                Nome    = "Centro de Manutenção",
                Media   = 18,
                DesvPad = 4,
                Print   = true
            };
            var pontoB = new Activity
            {
                Print = false
            };
            var secagem = new Activity
            {
                Nome    = "Secagem",
                Media   = 6,
                DesvPad = 2
            };
            var aspirador = new Activity
            {
                Nome    = "Aspirador",
                Media   = 12,
                DesvPad = 3
            };

            var abastecimento = new Activity
            {
                Nome  = "Abastecimento",
                Print = false
            };
            var alcool = new Activity
            {
                Nome    = "Alcool",
                Media   = 5,
                DesvPad = 0,
                Print   = true
            };
            var gasolina = new Activity
            {
                Nome    = "Gasolina",
                Media   = 5,
                DesvPad = 0,
                Print   = true
            };
            var diesel = new Activity
            {
                Nome    = "Disel",
                Media   = 8,
                DesvPad = 0,
                Print   = true
            };
            var lanchonete = new Activity
            {
                Nome    = "Lanchonete",
                Media   = 20,
                DesvPad = 2
            };
            var pagamento = new Activity
            {
                Nome    = "Pagamento",
                Media   = 10,
                DesvPad = 3
            };
            var pontoE = new Activity
            {
                Print = false
            };
            var pontoF = new Activity
            {
                Print = false
            };
            var pontoG = new Activity
            {
                Print = false
            };

            pontoA.PreencheItensEntrada(carros);

            //PontoA
            pontoA.AddConection(lavaRapido, 0.6);
            pontoA.AddConection(centroManutenção);

            //Lava Rapido
            lavaRapido.AddConection(pontoC);

            //Centro Manutenção
            centroManutenção.AddConection(pontoB);

            //PontoB
            pontoB.AddConection(lavaRapido, 0.8);

            //PontoC
            pontoC.AddConection(aspirador, 0.5);
            pontoC.AddConection(secagem);

            //Secagem
            secagem.AddConection(abastecimento);

            //Aspirador
            aspirador.AddConection(abastecimento);

            //Abastecimento e pontoD
            abastecimento.AddConection(alcool, 0.3);
            abastecimento.AddConection(gasolina, 0.8);
            abastecimento.AddConection(diesel);

            //Alcool
            alcool.AddConection(pontoE);

            //Gasolina
            gasolina.AddConection(pontoF);

            //Diesel
            diesel.AddConection(pontoG);

            //Ponto E
            pontoE.AddConection(pagamento, 0.7);
            pontoE.AddConection(lanchonete);

            //Ponto F
            pontoF.AddConection(pagamento, 0.5);
            pontoF.AddConection(lanchonete);

            //Ponto G
            pontoG.AddConection(pagamento, 0.3);
            pontoG.AddConection(lanchonete);

            //Lanchonete
            lanchonete.AddConection(pagamento);

            pontoA.SetupConnections();
            pontoA.Run();
        }