Ejemplo n.º 1
0
        private void GiveInitialMandatesOnNationalLevel(int mirsCount, int partiesCountTable1, int[,] votesTable2, Party[] partiesTable2, int partiesCountInTable2, int partiesCountTable2, int allMandatesAfterStep0, int allVotesTable2, out List <PartyCalcInfo> partiesWithCalcInfo, out List <MirCalcInfo> mirsWithCalcInfo, out int mandatesLeft)
        {
            Logger.Info("\r\n==Разпределяне на мандатите на национално ниво==");
            decimal globalHareQuote = (decimal)allVotesTable2 / allMandatesAfterStep0;

            Logger.logger.InfoFormat("Квота на Хеър = {0} = {1}/{2}", globalHareQuote, allVotesTable2, allMandatesAfterStep0);

            //parties with calc info
            partiesWithCalcInfo = new List <PartyCalcInfo>();
            for (int i = 0; i < partiesCountInTable2; i++)
            {
                var partyWithCalcInfo = new PartyCalcInfo()
                {
                    Index   = i,
                    PartyId = partiesTable2[i].Id,
                };
                partiesWithCalcInfo.Add(partyWithCalcInfo);
            }

            //calculate party mir mandates
            mirsWithCalcInfo = new List <MirCalcInfo>();
            for (int i = 0; i < mirsCount; i++)
            {
                var mirCalcInfo = new MirCalcInfo()
                {
                    MirId    = _mirsAll[i].Id,
                    MirIndex = i,
                };
                mirsWithCalcInfo.Add(mirCalcInfo);
            }

            //calculate mir and partyVotes votes
            int[] mirVotesCountTable2   = new int[mirsCount];
            int[] partyVotesCountTable2 = new int[partiesCountTable1];
            for (int i = 0; i < mirsCount; i++)
            {
                for (int j = 0; j < partiesCountTable2; j++)
                {
                    //mir votes
                    mirVotesCountTable2[i]              += votesTable2[i, j];
                    mirsWithCalcInfo[i].Votes            = mirVotesCountTable2[i];
                    mirsWithCalcInfo[i].MandatesLimit    = _mirMandatesAvailable[i];
                    mirsWithCalcInfo[i].MandateHareQuote = _mirMandatesAvailable[i] != 0 ? decimal.Divide(mirVotesCountTable2[i], _mirMandatesAvailable[i]) : 0;
                    //party votes
                    partyVotesCountTable2[j]    += votesTable2[i, j];
                    partiesWithCalcInfo[j].Votes = partyVotesCountTable2[j];
                }
            }

            //mandates that every party should have
            for (int i = 0; i < partiesCountTable2; i++)
            {
                decimal mandateCoefHare = decimal.Divide(partyVotesCountTable2[i], globalHareQuote);
                int     mandatesInit    = (int)mandateCoefHare;
                partiesWithCalcInfo[i].MandatesGivenInit = mandatesInit;
                decimal mandateCoefHareR = mandateCoefHare - mandatesInit;
                partiesWithCalcInfo[i].MandateCoefHareR = mandateCoefHareR;
            }

            //summary init mandates given
            int mandatesInitGiven = partiesWithCalcInfo.Sum(p => p.MandatesGivenInit);

            mandatesLeft = allMandatesAfterStep0 - mandatesInitGiven;

            Logger.logger.Info("Начални мандати по партии:");
            LogNationalMandatesByParties(partiesWithCalcInfo);
        }
Ejemplo n.º 2
0
        private void GiveInitialMandatesOnNationalLevel(int mirsCount, int partiesCountTable1, int[,] votesTable2, Party[] partiesTable2, int partiesCountInTable2, int partiesCountTable2, int allMandatesAfterStep0, int allVotesTable2, out List<PartyCalcInfo> partiesWithCalcInfo, out List<MirCalcInfo> mirsWithCalcInfo, out int mandatesLeft)
        {
            Logger.Info("\r\n==Разпределяне на мандатите на национално ниво==");
            decimal globalHareQuote = (decimal)allVotesTable2 / allMandatesAfterStep0;
            Logger.logger.InfoFormat("Квота на Хеър = {0} = {1}/{2}", globalHareQuote, allVotesTable2, allMandatesAfterStep0);

            //parties with calc info
            partiesWithCalcInfo = new List<PartyCalcInfo>();
            for (int i = 0; i < partiesCountInTable2; i++)
            {
                var partyWithCalcInfo = new PartyCalcInfo()
                {
                    Index = i,
                    PartyId = partiesTable2[i].Id,
                };
                partiesWithCalcInfo.Add(partyWithCalcInfo);

            }

            //calculate party mir mandates
            mirsWithCalcInfo = new List<MirCalcInfo>();
            for (int i = 0; i < mirsCount; i++)
            {
                var mirCalcInfo = new MirCalcInfo()
                {
                    MirId = _mirsAll[i].Id,
                    MirIndex = i,
                };
                mirsWithCalcInfo.Add(mirCalcInfo);
            }

            //calculate mir and partyVotes votes
            int[] mirVotesCountTable2 = new int[mirsCount];
            int[] partyVotesCountTable2 = new int[partiesCountTable1];
            for (int i = 0; i < mirsCount; i++)
            {
                for (int j = 0; j < partiesCountTable2; j++)
                {
                    //mir votes
                    mirVotesCountTable2[i] += votesTable2[i, j];
                    mirsWithCalcInfo[i].Votes = mirVotesCountTable2[i];
                    mirsWithCalcInfo[i].MandatesLimit = _mirMandatesAvailable[i];
                    mirsWithCalcInfo[i].MandateHareQuote = _mirMandatesAvailable[i] != 0 ? decimal.Divide(mirVotesCountTable2[i], _mirMandatesAvailable[i]) : 0;
                    //party votes
                    partyVotesCountTable2[j] += votesTable2[i, j];
                    partiesWithCalcInfo[j].Votes = partyVotesCountTable2[j];
                }
            }

            //mandates that every party should have
            for (int i = 0; i < partiesCountTable2; i++)
            {
                decimal mandateCoefHare = decimal.Divide(partyVotesCountTable2[i], globalHareQuote);
                int mandatesInit = (int)mandateCoefHare;
                partiesWithCalcInfo[i].MandatesGivenInit = mandatesInit;
                decimal mandateCoefHareR = mandateCoefHare - mandatesInit;
                partiesWithCalcInfo[i].MandateCoefHareR = mandateCoefHareR;
            }

            //summary init mandates given
            int mandatesInitGiven = partiesWithCalcInfo.Sum(p => p.MandatesGivenInit);
            mandatesLeft = allMandatesAfterStep0 - mandatesInitGiven;

            Logger.logger.Info("Начални мандати по партии:");
            LogNationalMandatesByParties(partiesWithCalcInfo);
        }