Esempio n. 1
0
        public void ExecuteAction(Agent <VacuumLocation, VacuumPerception, VacuumAction> agent, VacuumAction action)
        {
            if (action == VacuumAction.Suck)
            {
                if (this.state[agent.Location] == VacuumStatus.Dirty)
                {
                    agent.Performance         += 10;
                    this.state[agent.Location] = VacuumStatus.Clean;
                }

                return;
            }

            if (action == VacuumAction.Left)
            {
                agent.Performance -= 1;
                agent.Location     = VacuumLocation.A;
                return;
            }

            if (action == VacuumAction.Right)
            {
                agent.Performance -= 1;
                agent.Location     = VacuumLocation.B;
                return;
            }
        }
Esempio n. 2
0
        public static void VacuumProc()
        {
            // Attente de l'initialisation de l'environnement
            while (!Environment._init)
            {
            }
            Init();

            Console.WriteLine(3 & Environment.DIRT);

            Stack <VacuumAction> intent = new Stack <VacuumAction>();

            _actionCycle = 0;
            while (true)
            {
                if (intent.Count == 0 || _actionsCount >= _actionCycle)
                {
                    // Récupération de l'état actuel de l'environnement
                    int[,] belief = Environment._grid;
                    CustomEnvState currentState = new CustomEnvState(belief, _pos);
                    // L'agent ne se déplace que si l'une des pièces est sale
                    if (currentState.NbOfDirtyRoom > 0)
                    {
                        if (_nextAlgo != _currentAlgorithm)
                        {
                            _currentAlgorithm = _nextAlgo;
                            MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.UpdateAlgo(_currentAlgorithm.ToString()));
                        }

                        // Mesure de performance
                        if (_actionsCount != 0)
                        {
                            if (_learningCount >= _learningCycle - 1)
                            {
                                _optimalActionCycle = ComputeOptimalActionCycle();
                                MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.UpdateOptimalActions());
                                _learningCount = 0;
                            }
                            else
                            {
                                _learningCount++;
                            }
                            _lastActionsCycleTrack.Add(new KeyValuePair <int, float>(_actionsCount, Environment.GivePerf()));
                            MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.AddLearnedAction(_actionsCount, Environment.GivePerf()));
                            Environment.ResetPerf();
                            _actionsCount = 0;
                        }

                        // Formulation du but
                        // Nous définissons le but de cet agent comme étant de nettoyer une seule pièce
                        CustomEnvState wishedState = new CustomEnvState(belief, _pos);
                        wishedState.DefineWishedRoomDirtyAs(currentState.NbOfDirtyRoom - 1);
                        wishedState.MarkAttributeForEquality(CustomEnvState.NUMBER_DIRTY_ROOM_ATTRIBUTE);
                        // Formulation du problème
                        Problem problem = new Problem(currentState, wishedState);
                        // Exploration
                        intent = Explore(problem, _currentAlgorithm);
                        // Mise à jour du cycle d'action optimal
                        _actionCycle = _optimalActionCycle == 0 ? intent.Count : _optimalActionCycle + WeightedRandom(0, Math.Max(intent.Count - _optimalActionCycle, 0));
                        MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.UpdateActionCycle());
                        MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.UpdateComputingState(""));
                    }
                }
                else if (_actionsCount < _actionCycle)
                {
                    _actionsCount++;
                    // Exécuter et retirer une action du plan d'actions
                    VacuumAction action = intent.Pop();
                    Execute(action);
                    Thread.Sleep(700);
                }
            }
        }