Exemple #1
0
 private Boolean buscarHorariosRepetidos(List <Horario>[] ListaPorCantidadMateria)
 {
     foreach (List <Horario> horarios in ListaPorCantidadMateria)
     {
         for (int i = 0; i < horarios.Count; i++)
         {
             Horario uno   = horarios[i];
             bool    salir = false;
             for (int j = i + 1; j < horarios.Count && !salir; j++)
             {
                 Horario dos = horarios[j];
                 foreach (Grupo g in uno)
                 {
                     if (!dos.Contains(g))
                     {
                         salir = true;
                     }
                 }
                 if (!salir)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemple #2
0
        private bool verificar(Grupo grupo, Horario array, Dictionary <string, int> indicedGrupo)
        {
            int indice = indicedGrupo[grupo.Materia.Nombre + "" + grupo.Id];

            foreach (Grupo g in array)
            {
                if (!g.Compatibles[indice])
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        private int filtrarDiasCantidadLibre(List <Horario> horarios, int diasLibresEsperados, bool enSemana)
        {
            int cantidadFiltrados = 0;

            for (int i = horarios.Count - 1; i >= 0; i--)
            {
                Horario h      = horarios[i];
                int     exceso = (enSemana) ? 7 - h.CantidadDiasOcupados + (h.DiasOcupados[5] + h.DiasOcupados[6] - 2) : 7 - h.CantidadDiasOcupados;
                if (exceso < diasLibresEsperados)
                {
                    horarios.RemoveAt(i);
                    cantidadFiltrados++;
                }
            }
            return(cantidadFiltrados);
        }
Exemple #4
0
        private int filtrarPorDias(List <Horario> horarios)
        {
            int borrados = 0;

            for (int i = 0; i < DiasFiltrados.Count; i++)
            {
                int dia = DiasFiltrados[i];
                for (int j = horarios.Count - 1; j >= 0; j--)
                {
                    Horario h = horarios[j];
                    if (h.DiasOcupados[dia] == 1)
                    {
                        horarios.RemoveAt(j);
                        borrados++;
                    }
                }
            }
            return(borrados);
        }
Exemple #5
0
        private int filtrarHoraDia(List <Horario> horarios)
        {
            int cantidadFiltrados = 0;

            foreach (string s in FiltrosHoraDia)
            {
                string[] data   = s.Split(' ');
                string   dia    = data[0];
                string   inicio = data[2];
                string   fin    = data[4];
                int      intDay = (dia != "Semana") ? Clase.GetDiaFullStringToInt(dia) : -1;

                int ini  = Convert.ToInt32(inicio.Replace(":", ""));
                int fini = Convert.ToInt32(fin.Replace(":", ""));

                for (int i = horarios.Count - 1; i >= 0; i--)
                {
                    Horario h      = horarios[i];
                    bool    breaks = false;
                    if (intDay == -1 || h.DiasOcupados[intDay] != 0)
                    {
                        foreach (Grupo g in h)
                        {
                            foreach (Clase c in g.Clases)
                            {
                                if ((c.NumeroDia == intDay || intDay == -1) && Clase.cruzanHoras(ini, fini, c.HoraInicio, c.HoraFin))
                                {
                                    horarios.RemoveAt(i);
                                    breaks = true;
                                    break;
                                }
                            }
                            if (breaks)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(cantidadFiltrados);
        }
Exemple #6
0
 private void combinarHorarios(List <Horario>[] horarios, List <Horario> horariosIniciales, List <Grupo> grupos, Dictionary <string, int> indicesGrupos)
 {
     foreach (Horario horario in horariosIniciales)
     {
         int cred = horario.Creditos;
         if (horario.Count() < LIMITE_MATERIAS && cred < LIMITE_CREDITOS)
         {
             List <Horario> lista = new List <Horario>();
             for (int i = GetNextGroupIndex(indicesGrupos, horario); i < grupos.Count(); i++)
             {
                 Grupo grupo = grupos[i];
                 if (verificar(grupo, horario, indicesGrupos))
                 {
                     Horario horarT = Horario.ClonarHorario(horario);
                     horarT.Add(grupo);
                     horarT.Id      += i + ".";
                     horarT.Creditos = cred + grupo.Materia.Creditos;
                     int restr = grupo.Materia.Restriccion;
                     if (restr != int.MaxValue)
                     {
                         horarT.Restriccion[restr]++;
                     }
                     foreach (Clase c in grupo.Clases)
                     {
                         if (horarT.DiasOcupados[c.NumeroDia] == 0)
                         {
                             horarT.CantidadDiasOcupados++;
                             horarT.DiasOcupados[c.NumeroDia] = 1;
                         }
                     }
                     horarios[horarT.Count].Add(horarT);
                     lista.Add(horarT);
                 }
             }
             if (lista.Count != 0)
             {
                 combinarHorarios(horarios, lista, grupos, indicesGrupos);
             }
         }
     }
 }
Exemple #7
0
        private List <Horario> horariosInicialesDeGrupos(List <Grupo> grupos)
        {
            List <Horario> horarios = new List <Horario>();

            for (int i = 0; i < grupos.Count(); i++)
            {
                Horario h = new Horario(i + "");
                h.Add(grupos[i]);
                foreach (Clase c in grupos[i].Clases)
                {
                    if (h.DiasOcupados[c.NumeroDia] == 0)
                    {
                        h.CantidadDiasOcupados++;
                        h.DiasOcupados[c.NumeroDia] = 1;
                    }
                }
                horarios.Add(h);
            }

            return(horarios);
        }
Exemple #8
0
        public static void pintarHorariosExcel(List <Horario> horarios, List <Materia> Materias)
        {
            Excel.Application xlApp;
            Excel.Workbooks   xlWorkBooks;
            Excel.Workbook    xlWorkBook;
            object            misValue = System.Reflection.Missing.Value;

            xlApp       = new Excel.Application();
            xlWorkBooks = xlApp.Workbooks;
            xlWorkBook  = xlApp.Workbooks.Add(misValue);
            Dictionary <string, Color> coloresMateria = AsignarColores(Materias);

            Excel.Worksheet sheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            sheet.Name = "Horarios";

            int rCnt  = 1;
            int value = horarios.Count * (Materias.Count + 1 + 10);

            object[,] horariosArray = new object[value, 11];
            for (int h = 0; h < horarios.Count; h++)
            {
                Horario horario = horarios[h];
                pintarHorario(horariosArray, horario, rCnt, coloresMateria, h + 1);
                rCnt += 10;
            }
            var startCell  = (Range)sheet.Cells[1, 1];
            var endCell    = (Range)sheet.Cells[value, 11];
            var writeRange = sheet.Range[startCell, endCell];

            writeRange.Value2 = horariosArray;
            for (int i = 0; i < Materias.Count; i++)
            {
                Materia materia = Materias[i];
                validator(sheet, value, coloresMateria[materia.Nombre], materia.Nombre);
            }
            xlApp.Visible = true;
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlWorkBooks);
            Marshal.ReleaseComObject(xlApp);
        }
Exemple #9
0
        public static Horario ClonarHorario(Horario toClone)
        {
            Horario cloned = new Horario();

            foreach (Grupo g in toClone)
            {
                cloned.Add(g);
            }
            cloned.Id                   = toClone.Id;
            cloned.Restriccion          = new int[4];
            cloned.DiasOcupados         = new int[7];
            cloned.CantidadDiasOcupados = toClone.CantidadDiasOcupados;
            for (int i = 0; i < toClone.Restriccion.Length && toClone.Restriccion[i] != 0; i++)
            {
                cloned.Restriccion[i] = toClone.Restriccion[i];
            }
            for (int i = 0; i < toClone.DiasOcupados.Length; i++)
            {
                cloned.DiasOcupados[i] = toClone.DiasOcupados[i];
            }
            return(cloned);
        }
Exemple #10
0
        private void eliminarHorariosSinRestriccionesIdeales(List <Horario> horarios)
        {
            int numIdeal = 0;

            for (int i = 0; i < RestriccionIdeal.Length && RestriccionIdeal[i] != 0; i++)
            {
                numIdeal++;
            }
            for (int j = 0; j < horarios.Count; j++)
            {
                Horario h    = horarios[j];
                bool    sale = false;
                for (int k = 0; k < numIdeal && !sale; k++)
                {
                    if (h.Restriccion[k] != 0 && h.Restriccion[k] != RestriccionIdeal[k])
                    {
                        sale = true;
                        horarios.Remove(h);
                        j--;
                    }
                }
            }
        }
Exemple #11
0
 private static void pintarHorario(object[,] horariosArray, Horario horario, int rCnt, Dictionary <string, Color> colores, int counter)
 {
     string[] dias = new string[] { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes!", "Sabado", "Domingo", "", "Horario# " + counter, "Codigo: " + horario.Id };
     for (int i = 0; i < dias.Length; i++)
     {
         horariosArray[rCnt, i + 1] = dias[i];
     }
     rCnt++;
     horario.Sort((a, b) => a.Materia.Nombre.CompareTo(b.Materia.Nombre));
     for (int i = 0; i < horario.Count(); i++)
     {
         Grupo        grupo   = horario[i];
         Materia      materia = grupo.Materia;
         List <Clase> clases  = grupo.Clases;
         for (int j = 0; j < clases.Count(); j++)
         {
             Clase clase = clases[j];
             int   dia   = clase.NumeroDia + 1;
             horariosArray[rCnt, dia] = FileManager.reporteClase(grupo, clase);
         }
         rCnt++;
     }
 }
Exemple #12
0
        private int GetNextGroupIndex(Dictionary <string, int> indicesGrupos, Horario horario)
        {
            Grupo g = horario[horario.Count() - 1];

            return(indicesGrupos[g.Materia.Nombre + "" + g.Id] + 1);
        }