Exemple #1
0
        static int Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start().Stop().Reset().Start();

            // For Recodex
            foreach (string arg in args)
            {
                if (arg == "--dev")
                {
                    printToConsole = true;
                }
            }

            WarehouseState state = null, nextState = null;
            var            warehouse = new Warehouse(reader.ReadRest().Replace("\n", ""));
            var            tracker   = warehouse.Tracker();
            var            queue     = new LinkedList <WarehouseState>();

            int iterations = 0;

            tracker.RegisterState(warehouse.InitialState);
            queue.InsertLast(warehouse.InitialState);

            while (!queue.Empty)
            {
                iterations++;

                state = queue.ExtractFirst();

                if (state.Box == warehouse.Target)
                {
                    break;
                }

                var mutations = state.Mutate().Iterator();
                while (!mutations.Done)
                {
                    nextState = mutations.Next().Value;
                    if (!tracker.StateDiscovered(nextState))
                    {
                        tracker.RegisterState(nextState);
                        queue.InsertLast(nextState);
                    }
                }
            }

            Console.WriteLine(state != null && state.Box == warehouse.Target ? state.Moves : -1);

            if (MainClass.printToConsole)
            {
                Console.WriteLine("Finished in {0} iterations", iterations);
                Console.WriteLine("Executed in {0} ms", stopwatch.Stop().Milliseconds);
            }

            return(0);
        }
Exemple #2
0
        public IWarehouseState Get(string id)
        {
            IWarehouseState state = CurrentSession.Get <WarehouseState> (id);

            if (state == null)
            {
                state = new WarehouseState();
                (state as WarehouseState).WarehouseId = id;
            }
            return(state);
        }
        public static IEnumerable <IWarehouseState> ToWarehouseStateCollection(IEnumerable <string> ids)
        {
            var states = new List <WarehouseState>();

            foreach (var id in ids)
            {
                var s = new WarehouseState();
                s.WarehouseId = id;
                states.Add(s);
            }
            return(states);
        }
Exemple #4
0
        public IWarehouseState Get(string id, bool nullAllowed)
        {
            IWarehouseState state = CurrentSession.Get <WarehouseState> (id);

            if (!nullAllowed && state == null)
            {
                state = new WarehouseState();
                (state as WarehouseState).WarehouseId = id;
            }
            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <IWarehouseState>(state, new Type[] {  }, _readOnlyPropertyNames));
            }
            return(state);
        }
        public virtual void DeleteWarehouseSatte(WarehouseState warehouseState)
        {
            if (warehouseState == null)
            {
                throw new ArgumentNullException("warehouseState");
            }

            _warehouseStateRepository.Delete(warehouseState);

            //clear cache
            _cacheManager.RemoveByPattern(WAREHOUSESTATE_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityDeleted(warehouseState);
        }
Exemple #6
0
        private List <WarehouseState> GetWarehousesStates(List <Material> correctMaterials)
        {
            var result = new List <WarehouseState>();

            foreach (var correctMaterial in correctMaterials)
            {
                foreach (var warehouse in correctMaterial.Warehouses)
                {
                    var warehouseState = result.FirstOrDefault(x => new String(x.Name.Where(y => Char.IsLetterOrDigit(y)).ToArray()) == new String(warehouse.Name.Where(y => Char.IsLetterOrDigit(y)).ToArray()));

                    if (warehouseState == null)
                    {
                        warehouseState = new WarehouseState()
                        {
                            Name           = warehouse.Name,
                            MaterialStates = new Dictionary <string, int>()
                            {
                                { correctMaterial.Id, warehouse.Amount }
                            }
                        };

                        result.Add(warehouseState);
                    }
                    else
                    {
                        if (warehouseState.MaterialStates.ContainsKey(correctMaterial.Id))
                        {
                            warehouseState.MaterialStates[correctMaterial.Id] += warehouse.Amount;
                        }
                        else
                        {
                            warehouseState.MaterialStates.Add(correctMaterial.Id, warehouse.Amount);
                        }
                    }
                }
            }

            return(result);
        }
Exemple #7
0
 public bool StateDiscovered(WarehouseState state)
 {
     return(this.discovered[state.Storekeeper, state.Box]);
 }
Exemple #8
0
 public void RegisterState(WarehouseState state)
 {
     this.discovered[state.Storekeeper, state.Box] = true;
 }