Beispiel #1
0
        public void NewAlgorithmModel()
        {
            NewModel();
            SetupModel setupModel = _model.NewSetupModel();

            setupModel.Initialize();
            ParticipantsModel participantsModel = _model.NewParticipantsModel();

            participantsModel.Initialize();
            PreferencesModel preferencesModel = _model.NewPreferencesModel();

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = _model.NewAlgorithmModel();

            algorithmModel.Initialize();
            _context.AlgorithmsChanged = false;

            algorithmModel.CreateGaleShapleyAlgorithm();
            Assert.AreEqual(1, _context.Algorithms.Count());

            AlgorithmVisitor _visitor = new AlgorithmVisitor(null, () => Assert.Fail());

            _visitor.Visit(_context.Algorithms[0].Element);
            Assert.IsTrue(_context.AlgorithmsChanged);
        }
Beispiel #2
0
        public void LoadData()
        {
            SaveData data;

            NewModel();
            SetupModel setupModel = new SetupModel(_context);

            setupModel.Initialize();
            ParticipantsModel participantsModel = new ParticipantsModel(_context);

            participantsModel.Initialize();
            PreferencesModel preferencesModel = new PreferencesModel(_context);

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = new AlgorithmModel(_context);

            algorithmModel.Initialize();

            _model.SaveAsData("");
            data = _persistence.MockData;

            NewModel();
            _persistence.MockData = data;
            _model.LoadData("");
            Assert.AreEqual(data, _persistence.Data);
        }
        public void RefreshPage()
        {
            if (_context.PreferencesChanged)
            {
                _model.Initialize();
            }

            AlgorithmOptions.Clear();
            AlgorithmElements.Clear();
            for (int i = 0; i < _context.GetAlgorithms.Count; i++)
            {
                IAlgorithmData data = _context.GetAlgorithms[i];
                _model.VisitAlgorithm(i,
                                      (x) => RefreshGaleShapley(data.Name, i),
                                      (x) => RefreshGenetic(data.Name, i, x.Settings));
            }
            OnPropertyChanged("AlgorithmOptions");
        }
Beispiel #4
0
        public void NewRunModel()
        {
            StablePairsEvaluation          stablePairsEvaluation          = new StablePairsEvaluation();
            GroupHappinessEvaluation       groupHappinessEvaluation       = new GroupHappinessEvaluation();
            EgalitarianHappinessEvaluation egalitarianHappinessEvaluation = new EgalitarianHappinessEvaluation();

            NewModel();
            SetupModel setupModel = _model.NewSetupModel();

            setupModel.Initialize();
            ParticipantsModel participantsModel = _model.NewParticipantsModel();

            participantsModel.Initialize();
            PreferencesModel preferencesModel = _model.NewPreferencesModel();

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = _model.NewAlgorithmModel();

            algorithmModel.Initialize();
            RunModel runModel = _model.NewRunModel();

            runModel.Initialize();

            int  receivedEvents = 0;
            Task task;

            NewModel();

            runModel.AlgorithmStarted  += (object sender, AlgorithmEventArgs e) => receivedEvents++;
            runModel.AlgorithmFinished += (object sender, AlgorithmEventArgs e) =>
            {
                receivedEvents++;
                Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(stablePairsEvaluation), e.StablePairs);
                Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(groupHappinessEvaluation), e.GroupHappiness);
                Assert.AreEqual(_context.Algorithms[e.Index].Algorithm.Evaluate(egalitarianHappinessEvaluation), e.EgalitarianHappiness);
            };
            task = Task.Run(async() => {
                await runModel.RunSingleAlgorithm(0);
                Assert.AreEqual(2, receivedEvents);
            });
        }
Beispiel #5
0
        private void NewModel()
        {
            _context = new ModelContext();
            SetupModel setupModel = new SetupModel(_context);

            setupModel.Initialize();
            ParticipantsModel participantsModel = new ParticipantsModel(_context);

            participantsModel.Initialize();
            PreferencesModel preferencesModel = new PreferencesModel(_context);

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = new AlgorithmModel(_context);

            algorithmModel.Initialize();
            algorithmModel.CreateGaleShapleyAlgorithm();
            algorithmModel.CreateGeneticAlgorithm();
            _model = new RunModel(_context);
            _model.Initialize();
            _context.AlgorithmsChanged = false;
        }
        private void NewViewModel()
        {
            _context   = new ModelContext();
            _model     = new RunModel(_context);
            _viewModel = new RunViewModel(_model, _context);

            SetupModel setupModel = new SetupModel(_context);

            setupModel.Initialize();
            ParticipantsModel participantsModel = new ParticipantsModel(_context);

            participantsModel.Initialize();
            PreferencesModel preferencesModel = new PreferencesModel(_context);

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = new AlgorithmModel(_context);

            algorithmModel.Initialize();

            algorithmModel.CreateGaleShapleyAlgorithm();
            algorithmModel.CreateGeneticAlgorithm();

            _viewModel.RefreshPage();
        }
Beispiel #7
0
        public void SaveData()
        {
            NewModel();
            SetupModel setupModel = new SetupModel(_context);

            setupModel.Initialize();
            ParticipantsModel participantsModel = new ParticipantsModel(_context);

            participantsModel.Initialize();
            PreferencesModel preferencesModel = new PreferencesModel(_context);

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = new AlgorithmModel(_context);

            algorithmModel.Initialize();

            _model.SaveAsData("");
            Assert.IsNotNull(_persistence.MockData);
            Assert.IsNotNull(_persistence.MockData.Group1Name);
            Assert.IsNotNull(_persistence.MockData.Group2Name);
            Assert.IsNotNull(_persistence.MockData.Participants);
            Assert.IsNotNull(_persistence.MockData.Preferences);
            Assert.IsNotNull(_persistence.MockData.Algorithms);
        }
        private void NewModel()
        {
            List <Participant> participants = new List <Participant>();

            for (int i = 0; i < 5; i++)
            {
                participants.Add(new Participant(i, "test" + i, MarriageGroup.Group1));
            }
            for (int i = 5; i < 10; i++)
            {
                participants.Add(new Participant(i, "test" + i, MarriageGroup.Group2));
            }

            _context = new ModelContext
            {
                TotalSize           = 10,
                Participants        = participants,
                SetupChanged        = true,
                ParticipantsChanged = true,
                PreferencesChanged  = true,
            };

            _context.Priorities = new Priorities(new Dictionary <int, UnitSet>());
            foreach (Participant participant in _context.Group1Participants)
            {
                _context.Priorities[participant.ID] = new UnitSet(_context.Group2Participants.Select(x => x.ID).ToList());
            }
            foreach (Participant participant in _context.Group2Participants)
            {
                _context.Priorities[participant.ID] = new UnitSet(_context.Group1Participants.Select(x => x.ID).ToList());
            }

            _model = new AlgorithmModel(_context);
            _model.Initialize();
            _context.AlgorithmsChanged = false;
        }