示例#1
0
        private void fillColumns()
        {
            currentRow = 0;

            while (currentRow < nbrOfSamples)
            {
                int[][] orderArray = null;
                if (!allowDiffVoterOrder)
                {
                    int[,] availOrders = SupportFunction.GetPermutations(nbrOfNominees);
                    int[] voterPreferenceDistributon = SupportFunction.CreatePreferenceDistribution(availOrders.GetLength(0), nbrOfVoters, rnd);
                    orderArray = SupportFunction.CreateOrderArray(availOrders, voterPreferenceDistributon, RandomOrder(nbrOfVoters));
                }

                // Fill current row
                int[] order = null;
                for (int currentVoter = 0; currentVoter < nbrOfVoters; currentVoter++)
                {
                    if (!allowDiffVoterOrder)
                    {
                        order = orderArray[currentVoter];
                    }
                    fillRankingColumns(nbrOfNominees * currentVoter, order);
                }
                currentRow++;

                // Add last row again with differenet sorting of voters
                if (allowDiffVoterOrder)
                {
                    AddExtraRows();
                }
            }
        }
示例#2
0
        private bool orderIsOkay()
        {
            int[,] availOrders = SupportFunction.GetPermutations(nbrOfNominees);
            int[] voterPreferenceDistributon = new int[availOrders.GetLength(0)];
            for (int prefID = 0; prefID < voterPreferenceDistributon.Length; prefID++)
            {
                voterPreferenceDistributon[prefID] = 0;
            }
            // Loop through current row, and count the different preference orders
            int[][] currentOrderArray = new int[nbrOfVoters][];
            for (int voterID = 0; voterID < nbrOfVoters; voterID++)
            {
                // Create Order Array from current Row
                currentOrderArray[voterID] = new int[nbrOfNominees];
                for (int nomineeID = 0; nomineeID < nbrOfNominees; nomineeID++)
                {
                    currentOrderArray[voterID][nomineeID] = data[currentRow, nbrOfNominees *voterID + nomineeID];
                }
                // Find the ID of the matching order
                for (int orderID = 0; orderID < availOrders.GetLength(0); orderID++)
                {
                    bool isMatch = true;
                    for (int nomineeID = 0; nomineeID < nbrOfNominees; nomineeID++)
                    {
                        if (currentOrderArray[voterID][nomineeID] != availOrders[orderID, nomineeID])
                        {
                            isMatch = false;
                            break;
                        }
                    }
                    if (isMatch)
                    {
                        voterPreferenceDistributon[orderID]++;
                        break;
                    }
                }
            }
            // Get the allowed order array
            int[][] allowedOrderArray = SupportFunction.CreateOrderArray(availOrders, voterPreferenceDistributon, RandomOrder(nbrOfVoters));
            // Check whether the two order array match
            bool isOkay = true;

            for (int orderID = 0; orderID < allowedOrderArray.Length; orderID++)
            {
                for (int nomineeID = 0; nomineeID < allowedOrderArray[orderID].Length; nomineeID++)
                {
                    if (allowedOrderArray[orderID][nomineeID] != currentOrderArray[orderID][nomineeID] - 1)
                    {
                        isOkay = false;
                        break;
                    }
                }
            }
            return(isOkay);
        }