public PreferenceMatrix InferPreferences(SpatialFile.District district)
        {
            var result = new PreferenceMatrix(this.partyNames.Count);

            for (int i = 0; i < district.ResultsByParty.Count; i++)
            {
                var voteShare = district.ResultsByParty[i];

                var relevantPrefData = (from x in this.preferenceInformation where x.FirstIndex == i select x).ToList();
                var totalWeight      = (from x in relevantPrefData select x.Weight).Sum();

                foreach (var prefOrder in relevantPrefData)
                {
                    result.VotesByParty[prefOrder.FirstIndex, prefOrder.SecondIndex, prefOrder.ThirdIndex] += prefOrder.Weight * voteShare / totalWeight;
                }
            }

            double total = 0.0;

            for (int i = 0; i < this.partyNames.Count; i++)
            {
                for (int j = 0; j < this.partyNames.Count; j++)
                {
                    for (int k = 0; k < this.partyNames.Count; k++)
                    {
                        total += result.VotesByParty[i, j, k];
                    }
                }
            }

            for (int i = 0; i < this.partyNames.Count; i++)
            {
                for (int j = 0; j < this.partyNames.Count; j++)
                {
                    for (int k = 0; k < this.partyNames.Count; k++)
                    {
                        result.VotesByParty[i, j, k] /= total;
                    }
                }
            }

            return(result);
        }
Example #2
0
        public MainPresenter(ImodeSelectionForm selectForm, IFileManager manager,
                             IMessageService service, ISelfAssesForm selfAsses, IInputForm inputForm,
                             IResultForm resultForm)
        {
            _selectForm     = selectForm;
            _manager        = manager;
            _messageService = service;
            _inputForm      = inputForm;
            _selfAsses      = selfAsses;
            _resultForm     = resultForm;

            _selectForm.FinishMatrixClick  += _selectForm_FinishMatrixClick;
            _selectForm.SelfAssesClick     += _selectForm_SelfAssesClick;
            _selectForm.AlterChangeClick   += _selectForm_AlterChangeClick;
            _inputForm.FileOpenClick       += _matrixForm_FileOpenClick;
            _inputForm.FileSaveClick       += _inputForm_FileSaveClick;
            _inputForm.ButAlterChangeClick += _inputForm_WriteAlternatives;
            _inputForm.ButProcessingClick  += _inputForm_ProcessingMatrixClick;
            _selfAsses.ChoiceClick         += _selfAsses_ChoiceClick;
            matrix = new PreferenceMatrix(manager.Alternatives.Length);
        }
            public PreferenceMatrix Evolve(double switch2nd, double switch3rd)
            {
                var result = new PreferenceMatrix(PartyCount);

                double dontSwitch = 1.0 - (switch2nd + switch3rd);

                for (int i = 0; i < PartyCount; i++)
                {
                    for (int j = 0; j < PartyCount; j++)
                    {
                        for (int k = 0; k < PartyCount; k++)
                        {
                            result.VotesByParty[i, j, k] =
                                this.VotesByParty[i, j, k] * dontSwitch +
                                this.VotesByParty[j, i, k] * switch2nd +
                                this.VotesByParty[k, i, j] * switch3rd;
                        }
                    }
                }

                return(result);
            }
Example #4
0
 private void _inputForm_WriteAlternatives(object sender, EventArgs e)
 {
     _manager.SaveContent(_inputForm.Content);
     _manager.WriteAlternatives();
     matrix = new PreferenceMatrix(_manager.Alternatives.Length);
 }