예제 #1
0
        public static void Distribute(Volunteer period)
        {
            Organization[] array = AddOrganizationFromList();

            List <OrganizationImportance> organizationList = new List <OrganizationImportance>();

            for (int i = 0; i < array.Length; i++)
            {
                if (Haversine(array[i].Latitude, array[i].Longitude, period.Latitude, period.Longitude) < period.Radius)
                {
                    OrganizationImportance newOrganization = new OrganizationImportance(array[i].Name, Importance(array[i]));
                    organizationList.Add(newOrganization);
                    //WriteLine( newOrganization);
                }
            }

            OrganizationImportance[] sortedImportance = organizationList.ToArray();
            InsertionSort(sortedImportance);

            double importanceSum = 0;

            foreach (OrganizationImportance x in sortedImportance)
            {
                //WriteLine( x );
                importanceSum += x.Importance;
            }

            ReturnAmounts(sortedImportance, importanceSum, period.Inventory);
        }
예제 #2
0
        /// <summary>
        /// Overarching function call to calculate supply distribution
        /// </summary>
        /// <param name="person">Volunteer user configuration</param>
        public static void Distribute(Volunteer person)
        {
            // Get organizations from database
            Organization[] array = AddOrganizationFromList();
            // Instantiate empty importance object for each organization
            List <OrganizationImportance> organizationList = new List <OrganizationImportance>();

            // Compute distance and relative benefit for supply distribution for each organization
            for (int i = 0; i < array.Length; i++)
            {
                // Only consider if within worthwhile location
                if (Haversine(array[i].Latitude, array[i].Longitude, person.Latitude, person.Longitude) < person.Radius)
                {
                    OrganizationImportance newOrganization = new OrganizationImportance(array[i].Name, Importance(array[i]));
                    organizationList.Add(newOrganization);
                }
            }
            // Rank organizations by optimal benefit
            OrganizationImportance[] sortedImportance = organizationList.ToArray();
            // Fun implementation of insertion sort just because!
            InsertionSort(sortedImportance);
            // Compile total 'importance weighting' to use in later calculations
            double importanceSum = 0;

            foreach (OrganizationImportance x in sortedImportance)
            {
                importanceSum += x.Importance;
            }
            // Determine distribution based on benefit
            ReturnAmounts(sortedImportance, importanceSum, person.Inventory);
        }
예제 #3
0
        public static void InsertionSort(OrganizationImportance[] recordsArray)
        {
            for (int firstUnsortedIndex = 1; firstUnsortedIndex < recordsArray.Length; firstUnsortedIndex++)
            {
                int hole = firstUnsortedIndex;
                OrganizationImportance temp = recordsArray[hole];

                while (hole > 0 && temp.Importance > recordsArray[hole - 1].Importance)
                {
                    recordsArray[hole] = recordsArray[hole - 1];
                    hole--;
                }

                recordsArray[hole] = temp;
            }
        }