/* Call a new car.. */ private void callNewCar() { // If there are not cars availables. if (vehiculosTemporales.Count <= 0) { return; } // Get the first car. DistribucionVehiculosGeneticos.Vehiculo tempVehiculo = vehiculosTemporales[0]; // If the car is not going to be assigned. if (vehiculosTemporales[0].GetLineaAsignada() != null) { GameObject newCar = salaObject.getCarById(tempVehiculo.GetId()); // Get the respective car of the waitRoom. if (newCar) { newCar.transform.position = new Vector3(transform.position.x, transform.position.y, newCar.transform.position.z); GameObject lineObject = getLine(tempVehiculo.GetLineaAsignada().GetId()); // Get the line of the car. lines line = lineObject.GetComponent <lines>(); // Call the script of the line. newCar.GetComponent <vehicle>().setActualLine(line); // Add to the car, the state of the actual line. line.addElement(newCar); // Add the new car to the line. vehiculosTemporales.Remove(tempVehiculo); } } else { vehiculosTemporales.Remove(tempVehiculo); // Remove the car from the possibles ... and call other. callNewCar(); } }
/**************************************************** * Asigna los vehiculos de una poblacion a las lineas * ****************************************************/ public void AsignarVehiculosALineas() { // Asigna el valor inicial a cada linea foreach (Linea l in this.lineas) { l.RestablecerTiemporestante(); l.SetNumVehiculosAsignados(0); } foreach (Vehiculo v in this.vehiculos) { v.SetLineaAsignada(null); } // Ordena la lista de menor a mayor segun las probabilidades del vehiculo IEnumerable <Vehiculo> sorted = this.vehiculos.OrderBy(x => x.GetProbAsignado()); List <Vehiculo> tempListaEspera = new List <Vehiculo>(); foreach (Vehiculo v in sorted) { tempListaEspera.Add(v); } for (int i = 0; i < tempListaEspera.Count; i++) { // Aleatorio segun la probabilidad del vehiculo int rand = rnd.Next(0, 101); if ((rand < tempListaEspera.ElementAt(i).GetProbAsignado())) { Vehiculo tempVehiculo = tempListaEspera.ElementAt(i); // Busco las lineas en que puede entrar List <Linea> tempLineas = new List <Linea>(); for (int j = 0; j < this.lineas.Count; j++) { if (this.lineas.ElementAt(j).GetEstaActiva()) { List <char> opciones = this.lineas.ElementAt(j).getTiposVehiculos(); if (opciones.Contains(tempVehiculo.GetTipo())) { if ((this.lineas.ElementAt(j).GetTiempoRestante() - tempVehiculo.GetTiempo()) >= 0) { tempLineas.Add(this.lineas.ElementAt(j)); } } } } // Lista de lineas donde el vehiculo puede entrar if (tempLineas.Count > 0) { // ver cual está vacia Linea tempMenorLinea = tempLineas.ElementAt(0); bool asignado = false; foreach (Linea l in tempLineas) { if (l.GetTiempoAtencion() == l.GetTiempoRestante()) { tempVehiculo.SetLineaAsignada(l); l.RestarTiempo(tempVehiculo.GetTiempo()); l.IncrementarVehiculos(); asignado = true; break; } int tiempoAsignado = tempMenorLinea.GetTiempoAtencion() - tempMenorLinea.GetTiempoRestante(); if (tiempoAsignado > (l.GetTiempoAtencion() - l.GetTiempoRestante())) { tempMenorLinea = l; } } // si no, ver la que tenga menor carga if (asignado == false) { int futuroValorLinea = (tempMenorLinea.GetTiempoAtencion() - tempMenorLinea.GetTiempoRestante()) + tempVehiculo.GetTiempo(); int maximoConsumo = this.GetTiempoatencionLineaMasPequena() + 20; if (futuroValorLinea <= maximoConsumo) { tempVehiculo.SetLineaAsignada(tempMenorLinea); tempMenorLinea.RestarTiempo(tempVehiculo.GetTiempo()); tempMenorLinea.IncrementarVehiculos(); } } } /*Console.WriteLine("El vehiculo: " + tempVehiculo.GetId()); * Console.WriteLine("Puede entrar en las lineas: "); * foreach (Linea l in tempLineas) * { * Console.WriteLine("Tiempo Atención--> " + l.GetTiempoAtencion()); * Console.WriteLine("Tiempo restante--> " + l.GetTiempoRestante()); * Console.WriteLine("#"); * } * Console.WriteLine("--------------------------------------"); * Console.WriteLine("--------------------------------------");*/ } } // Busca la linea con menor capacidad Linea lineaConMenoCapacidad = this.GetLineaConMenorCapacidad(); int maximoValorPorLinea = lineaConMenoCapacidad.GetTiempoAtencion(); int rango = maximoValorPorLinea + 20; this.LineasEnRango(rango); }