//Lectura de IntercambioBE desde Intercambio public static IntercambioBE ReadIntercambio(Intercambio i) { IntercambioBE intercambio = new IntercambioBE(); if (i != null) { intercambio = new IntercambioBE { IdIntercambio = i.IdIntercambio, IdUsuIni = i.IdUsuIni, IdUsuDestino = i.IdUsuDestino, Direccion = i.Direccion, FechaIniciado = i.FechaIniciado, FechaIntercambio = i.FechaIntercambio, IdLibroElegido = i.IdLibroElegido, IdLibroOfrecido = i.IdLibroOfrecido, HoraIntercambio = i.HoraIntercambio, Activo = i.Activo, Estado = i.Estado, LibroElegido = Utilities.ReadLibro(i.Libro), LibroOfrecido = Utilities.ReadLibro(i.Libro1), UsuInicial = Utilities.ReadUsuario(i.Usuario1), UsuDestino = Utilities.ReadUsuario(i.Usuario) }; } return(intercambio); }
public IntercambioBE Find(int id) { IntercambioBE intercambio = new IntercambioBE(); Intercambio i = context.Intercambio.Find(id); if (i != null) { intercambio = Utilities.ReadIntercambio(i); } return(intercambio); }
//Acepta o rechaza el Intercambio public void CambiaEstadoInter(int id, string estado) { Intercambio i = context.Intercambio.Find(id); i.Estado = estado; context.Entry(i).State = EntityState.Modified; context.SaveChanges(); if (estado == "02") { Libro lElegido = context.Libro.Find(i.IdLibroElegido); lElegido.Activo = "00"; Libro lOfrecido = context.Libro.Find(i.IdLibroOfrecido); lOfrecido.Activo = "00"; context.Entry(lOfrecido).State = EntityState.Modified; context.Entry(lElegido).State = EntityState.Modified; context.SaveChanges(); } }
public void Insert(IntercambioBE intercambio) { Intercambio i = new Intercambio(); if (intercambio != null) { i = new Intercambio { IdUsuIni = intercambio.IdUsuIni, IdUsuDestino = intercambio.IdUsuDestino, Direccion = intercambio.Direccion, FechaIniciado = intercambio.FechaIniciado, FechaIntercambio = intercambio.FechaIntercambio, HoraIntercambio = intercambio.HoraIntercambio, IdLibroElegido = intercambio.IdLibroElegido, IdLibroOfrecido = intercambio.IdLibroOfrecido, Activo = "01", Estado = "01" // Estado de Iniciado }; context.Intercambio.Add(i); context.SaveChanges(); } }
static void Main(string[] args) { Console.WriteLine("Ingrese los nombres del intercambio, separados por un espacio:\n"); var personas = Console.ReadLine(); string[] words = personas.Split(' '); int s = words.Count(); string[,] salida = new string[s, 2]; Random random = new Random(); int sorteo; Console.WriteLine("\n"); List <Lista> lst = new List <Lista>(); List <Intercambio> lstIntercambio = new List <Intercambio>(); //Llenado de Listas foreach (var word in words) { var n = new Lista(word, false); lst.Add(n); var m = new Intercambio(word, null); lstIntercambio.Add(m); } //Sorteo foreach (var val in lstIntercambio) { do { sorteo = random.Next(0, lstIntercambio.Count()); if (val.de != lst[sorteo].Nombre && lst[sorteo].Asignado == false) { val.para = lst[sorteo].Nombre; lst[sorteo].Asignado = true; } } while (val.para == null || val.de == lst[sorteo].Nombre && lst[sorteo].Asignado == true); } //Lleno Array for (int i = 0; i < lstIntercambio.Count; i++) { for (int j = 0; j < 2; j++) { if (j == 0) { salida[i, j] = lstIntercambio[i].de; } else { salida[i, j] = lstIntercambio[i].para; } } } //Resultados for (int i = 0; i < salida.Length / 2; i++) { for (int j = 0; j < 2; j++) { if (j == 0) { Console.Write(salida[i, j] + " -> "); } else { Console.WriteLine(salida[i, j]); } } } Console.ReadLine(); }
static void Main(string[] args) { List <Individuo> solucion = new List <Individuo>(); Seleccion seleccion; Mutacion mutacion; Reemplazo reemplazo; Cruce cruce; PaisajeAptitud paisaje; Random rand; Archivo.Archivo datosDistancia; Archivo.Archivo datosTiempo; int opc = 0; datosDistancia = new Archivo.Archivo("DataSetDistancia.txt", 0); datosTiempo = new Archivo.Archivo("DataSetTiempo.txt", 0); double[][] matrizDistacncia, matrizTiempo; matrizDistacncia = datosDistancia.getMatriz(); matrizTiempo = datosTiempo.getMatriz(); do { try { int dimensiones, numIteraciones, semilla; dimensiones = datosDistancia.cantLineas; //Parametros a afinar semilla = (new Random()).Next(1, 1001); numIteraciones = 500; if (semilla == -1) { rand = new Random(); } else { rand = new Random(semilla); } NSGAII algoritmo; algoritmo = new NSGAII(rand); paisaje = new fxAgenteViajero(opc, matrizDistacncia, matrizTiempo); cruce = new Combinado(rand, 2); mutacion = new Intercambio(rand); seleccion = new SxTorneo(rand, 2); reemplazo = new DelPeor(); algoritmo.inicializar(cruce, mutacion, seleccion, paisaje, reemplazo, numIteraciones, dimensiones, 0.50); solucion = algoritmo.ejecutar(); Console.WriteLine("Semilla: " + semilla + " Tamaño poblacion: " + algoritmo.tamañoPoblacion + " Ciudades: " + algoritmo.dimensiones); /*Console.WriteLine("Mejor individuo"); * solucion[0].mostrar(); * Console.WriteLine("Aptitud: " + solucion[0].getAptitud());*/ foreach (var ind in solucion) { Debug.WriteLine(ind.FitnessDistancia + "\t" + ind.FitnessTiempo + "\t" + ind.Rank); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); } Console.Write("Presiona 0 para salir...\nOtra tecla para volver a ejecutar..."); try { opc = Int32.Parse(Console.ReadKey(false).KeyChar.ToString()); } catch (Exception e) { opc = -1; } //Console.Clear(); } while (opc != 0); datosDistancia.close(); datosTiempo.close(); }