示例#1
0
        static void MainZZZ(string[] args)
        {
            int?[][] M = new int?[7][]
            {
                new int?[] { null, null, null, null, 60, 90, null },
                new int?[] { null, 45, 75, 75, null, 105 },
                new int?[] { null, null, 0, 0, null },
                new int?[] { null, null, 0, null },
                new int?[] { null, null, 10 },
                new int?[] { null, 15 },
                new int?[] { null }
            };
            HashSet <char> allServices = new HashSet <char>()
            {
                'L', 'T', 'P'
            };

            ServiceVariantSlot[] slots = new ServiceVariantSlot[]
            {
                new ServiceVariantSlot()
                {
                    Code      = 'L',
                    StartTime = 1300,
                    EndTime   = 1330
                },
                new ServiceVariantSlot()
                {
                    Code      = 'T',
                    StartTime = 1300,
                    EndTime   = 1315
                },
                new ServiceVariantSlot()
                {
                    Code      = 'L',
                    StartTime = 1400,
                    EndTime   = 1430
                },
                new ServiceVariantSlot()
                {
                    Code      = 'L',
                    StartTime = 1430,
                    EndTime   = 1500
                },
                new ServiceVariantSlot()
                {
                    Code      = 'P',
                    StartTime = 1430,
                    EndTime   = 1450
                },
                new ServiceVariantSlot()
                {
                    Code      = 'T',
                    StartTime = 1430,
                    EndTime   = 1445
                },
                new ServiceVariantSlot()
                {
                    Code      = 'L',
                    StartTime = 1500,
                    EndTime   = 1530
                }
            };

            //var R = new Program().Run(M, allServices, slots);

            int?[][] M2 = new int?[6][]
            {
                new int?[] { null, null, null, 60, 60, null },
                new int?[] { 45, 75, 75, null, 105 },
                new int?[] { null, 0, 0, null },
                new int?[] { null, null, null },
                new int?[] { null, 10 },
                new int?[] { 15 }
            };
            var a      = new ProgramOLD();
            var matrix = a.GenerateMatrix(slots);
            var R2     = a.Run2(M2, allServices, slots);
        }
 public static string PrintServiceVariantSlot(ServiceVariantSlot slot)
 {
     return(String.Format("{0} {1} {2}", slot.Code, NumberOfMinutesToHumanTime(slot.StartTime), NumberOfMinutesToHumanTime(slot.EndTime)));
 }
示例#3
0
        private List <ServiceVariantSlot> Search(int?[][] matrix, int startIndex, HashSet <char> remainingServices, ServiceVariantSlot[] slots, ServiceVariantSlot previousService)
        {
            for (int j = 0; j < matrix[startIndex].Length && remainingServices.Count > 0; ++j)
            {
                if (matrix[startIndex][j] == null)
                {
                    continue;
                }
                var nextServiceIndex = startIndex + j + 1;
                var nextService      = slots[nextServiceIndex];
                if (!remainingServices.Contains(nextService.Code)) //ta usługa jest już dobrana
                {
                    continue;
                }
                if (nextService.StartTime < previousService.EndTime) //nie bierz, jeżeli slot zachodzi na ostatni wybrany slot
                {
                    continue;                                        //TODO: max interval - here or while generating matrix ?
                }
                if (previousService.EndTime + MAX_OFFSET_BETWEEN_SERVICES < nextService.StartTime)
                {
                    continue;
                }

                remainingServices.Remove(nextService.Code);
                if (remainingServices.Count == 0)
                {
                    return(new List <ServiceVariantSlot>()
                    {
                        nextService
                    });
                }
                ///
                if (nextServiceIndex >= matrix.Length) //są jeszcze usługi do umówienia a nie ma już slotów
                {
                    remainingServices.Add(nextService.Code);
                    return(null);
                }
                var remainingPart = Search(matrix, nextServiceIndex, remainingServices, slots, nextService);
                if (null == remainingPart) //musimy się wycofać
                {
                    remainingServices.Add(nextService.Code);
                }
                else
                {
                    List <ServiceVariantSlot> result = new List <ServiceVariantSlot>()
                    {
                        nextService
                    };
                    result.AddRange(remainingPart);
                    return(result);
                }
            }

            return(null);
        }
        List <ServiceVariantSlot> search(int?[][] matrix, int startIndex, HashSet <char> remainingServices, ServiceVariantSlot[] slots, ServiceVariantSlot previousService)
        {
            for (int j = 0; j < matrix[startIndex].Length && remainingServices.Count > 0; ++j)
            {
                if (matrix[startIndex][j] == null)
                {
                    continue;
                }
                var nextService = slots[startIndex + j + 1];
                if (!remainingServices.Contains(nextService.Code)) //ta usługa jest już dobrana
                {
                    continue;
                }
                if (nextService.StartTime < previousService.EndTime) //nie bierz, jeżeli slot zachodzi na ostatni wybrany slot
                {
                    continue;                                        //TODO: max interval - here or while generating matrix ?
                }
                if (previousService.EndTime + MAX_OFFSET_BETWEEN_SERVICES < nextService.StartTime)
                {
                    continue;
                }

                remainingServices.Remove(nextService.Code);
                if (remainingServices.Count == 0)
                {
                    return(new List <ServiceVariantSlot>()
                    {
                        nextService
                    });
                }
                ///
                var remainingPart = search(matrix, startIndex + j + 1, remainingServices, slots, nextService);
                if (null == remainingPart) //musimy się wycofać
                {
                    remainingServices.Add(nextService.Code);
                }
                else
                {
                    List <ServiceVariantSlot> result = new List <ServiceVariantSlot>()
                    {
                        nextService
                    };
                    result.AddRange(remainingPart);
                    return(result);
                }
                ///
                ////PROBA #2
                //result = new List<ServiceVariantSlot>() { nextService }; //dobieramy kolejną usługę w bloku
                //if (remainingServices.Count == 0)
                //    return result;        //pełny blok
                //var remainingPart = search(matrix, startIndex + 1, remainingServices, slots);
                //if(null == remainingPart) //musimy się wycofać
                //{
                //    remainingServices.Add(nextService.Code);
                //    continue;
                //}
                //result.AddRange(remainingPart);


                ////PROBA #1
                //remainingServices.Remove(nextService.Code);

                //result = search(matrix, startIndex+1, remainingServices, slots);
                //result.Add(nextService); //dobieramy kolejną usługę w bloku

                //if (remainingServices.Count == 0)
                //    return result;        //pełny blok
            }

            return(null);
        }