Example #1
0
        public object Solve()
        {
            var dependencies = new DependencyMatrix(cars);
            var lanes = new LaneList(cars);

            var initialListIsOk = lanes.TryUpdate(dependencies);
            Debug.Assert(initialListIsOk);

            foreach (var e in Events.Enumerate(cars))
            {
                Debug.Assert(e.Time >= 0);

                if (e.Type == EventType.StartOverlapping)
                {
                    if (!dependencies.TryPutCarsOnOppositeLanes(e.Car1, e.Car2))
                        return e.Time;
                }

                if (e.Type == EventType.StopOverlapping)
                {
                    dependencies.RemoveCarsOnOppositeLanes(e.Car1, e.Car2);
                }

                if (!lanes.TryUpdate(dependencies))
                    return e.Time;
            }

            return "Possible";
        }
Example #2
0
        public object Solve()
        {
            var dependencies = new DependencyMatrix(cars);
            var lanes        = new LaneList(cars);

            var initialListIsOk = lanes.TryUpdate(dependencies);

            Debug.Assert(initialListIsOk);

            foreach (var e in Events.Enumerate(cars))
            {
                Debug.Assert(e.Time >= 0);

                if (e.Type == EventType.StartOverlapping)
                {
                    if (!dependencies.TryPutCarsOnOppositeLanes(e.Car1, e.Car2))
                    {
                        return(e.Time);
                    }
                }

                if (e.Type == EventType.StopOverlapping)
                {
                    dependencies.RemoveCarsOnOppositeLanes(e.Car1, e.Car2);
                }

                if (!lanes.TryUpdate(dependencies))
                {
                    return(e.Time);
                }
            }

            return("Possible");
        }