Exemple #1
0
        public static void Main(string[] args)
        {
            // Room 1 - 8AM - 9AM, 10:30AM - 11AM, 4PM - 5 PM
            ConfRoom rc1   = new ConfRoom(1);
            Interval rc1i1 = new Interval(480, 540);
            Interval rc1i2 = new Interval(630, 660);
            Interval rc1i3 = new Interval(960, 1020);

            rc1.AddInterval(rc1i1);
            rc1.AddInterval(rc1i2);
            rc1.AddInterval(rc1i3);

            // Room 2 - 10AM - 12PM, 2:30PM - 4PM
            ConfRoom rc2   = new ConfRoom(2);
            Interval rc2i1 = new Interval(600, 720);
            Interval rc2i2 = new Interval(870, 960);

            rc2.AddInterval(rc2i1);
            rc2.AddInterval(rc2i2);

            // Room 3 - 7AM - 8:30AM, 5PM - 6PM
            ConfRoom rc3   = new ConfRoom(3);
            Interval rc3i1 = new Interval(420, 510);
            Interval rc3i2 = new Interval(1020, 1080);

            rc3.AddInterval(rc3i1);
            rc3.AddInterval(rc3i2);

            List <ConfRoom> cfs = new List <ConfRoom>();

            cfs.Add(rc1);
            cfs.Add(rc2);
            cfs.Add(rc3);

            // check for any available room for 8 AM - 9AM
            Console.WriteLine(IsAnyRoomAvailable(cfs, new Interval(480, 540)));

            // check for any available room for 3:30 PM - 5PM
            Console.WriteLine(IsAnyRoomAvailable(cfs, new Interval(930, 1021)));

            // count available rooms from 10:30AM - 11AM
            List <int> ids = GetAvailableRooms(cfs, new Interval(630, 660));

            Console.WriteLine($"total available rooms' count is {ids.Count}, ids are {string.Join(",", ids)}");


            // output:
            // true
            // false
            // 3
        }
Exemple #2
0
        public static bool IsRoomAvailable(ConfRoom cf, Interval interval)
        {
            List <Interval> itvs   = cf.Intervals;
            bool            result = false;

            foreach (Interval src in itvs)
            {
                if (IsIntervalAvailable(src, interval))
                {
                    result = true;
                }
                else
                {
                    result = false;
                    break;
                }
            }

            return(result);
        }