Exemple #1
0
        /// <summary>
        /// Construct a ResultSet instance from a set of Party IDs and some
        /// (optional) supplemental information about the Party-based search
        /// that was performed.
        /// </summary>
        /// <param name="searchOrigin">
        /// the centroid of the searched area; may be null
        /// </param>
        /// <param name="maxRadiusMi">
        /// the maximum distance from the origin, in statute miles, at which
        /// facilities were considered for inclusion in the Party ID set; may
        /// be null
        /// </param>
        /// <param name="partyIds">
        /// the set of Party IDs which satisfied some criteria
        /// </param>
        /// <returns></returns>
        public static ResultSet From(
            Location searchOrigin,
            double?maxRadiusMi,
            IntSet <PartyId> partyIds)
        {
            if (IntSet <PartyId> .IsEmpty(partyIds))
            {
                return(new ResultSet(0));
            }

            if (partyIds.IsUniverse)
            {
                throw new ArgumentException(
                          "partyIds may not be IntSet<PartyId>.Universe");
            }

            ResultSet resultSet = new ResultSet(partyIds.Count, searchOrigin, maxRadiusMi);

            foreach (int partyId in partyIds)
            {
                resultSet.mPartyIdToResult[partyId] = new Result();
            }

            return(resultSet);
        }
Exemple #2
0
        static void updateSuggestedBoard(string[,] assignedBoard, int[, ][,] suggestedBoard)
        {
            int emptySpots = 0;

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    if (assignedBoard[row, col] != "..") //if a number is already assinged to that position
                    {
                        suggestedBoard[row, col] = null;
                        emptySpots++;     //an empty suggested block
                    }
                    else //find the possible numbers
                    {
                        IntSet currentSet = getCurrentSet(suggestedBoard[row, col]); //what's currently already suggested (now filter this list)

                        IntSet rowSet = getRowSet(assignedBoard, row);
                        IntSet colSet = getColSet(assignedBoard, col);

                        IntSet blockSet = getBlockSet(assignedBoard, row, col);  //check the square the number is in
                        //print the block of the (row,col) point

                        // the final set of containing the suggested block
                        IntSet allSet = currentSet.Difference(rowSet.Union(colSet).Union(blockSet));
                        if (allSet.IsEmpty()) //an empty suggested block
                        {
                            emptySpots++;
                        }
                        //set the block to contain values corresponding to the SET
                        int[,] block = new int[3, 3];
                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                int numberToCheck = 3 * i + j + 1;
                                if (allSet.Contains(numberToCheck))  //check if number in the suggested set
                                {
                                    block[i, j] = numberToCheck;
                                }
                            }
                        }
                        suggestedBoard[row, col] = block;
                    }
                }
            }

            if (emptySpots == 81) //no more suggested spots
            {
                suggestedBoardEmpty = true;
            }
        }
Exemple #3
0
        //----------------------------------------------------------------------
        /// <summary>
        /// Returns a double in the range [0.0, 1.0] indicating the global
        /// density of Parties that match non-geographic search criteria.
        ///
        /// If there are no non-geographic criteria, this method always
        /// returns 1.0.
        /// </summary>
        private static double NonGeoMatchAbsDensity(
            IntSet <PartyId> matchesByMembership,
            ResultSet matchesByProfile)
        {
            bool byMembershipIsEmpty = IntSet <PartyId> .IsEmpty(matchesByMembership);

            bool byMembershipIsUniverse =
                !byMembershipIsEmpty &&
                matchesByMembership.IsUniverse;

            bool byProfileIsEmpty    = ResultSet.IsEmpty(matchesByProfile);
            bool byProfileIsUniverse =
                !byProfileIsEmpty &&
                matchesByProfile.IsUniverse;

            double nonGeoMatchCount = 0.0;

            if (byMembershipIsUniverse && byProfileIsUniverse)
            {
                return(1.0);
            }
            else if (byMembershipIsUniverse)
            {
                nonGeoMatchCount = byProfileIsEmpty ? 0 : matchesByProfile.Count;
            }
            else if (byProfileIsUniverse)
            {
                nonGeoMatchCount = byMembershipIsEmpty ? 0 : matchesByMembership.Count;
            }
            else
            {
                nonGeoMatchCount = Math.Min(
                    byMembershipIsEmpty ? 0 : matchesByMembership.Count,
                    byProfileIsEmpty ? 0 : matchesByProfile.Count);
            }

            // Ensure that the activePartyCount is never less than the number
            // of matches.  This guarantees a return value in the promised
            // range: [0.0, 1.0].
            double activePartyCount = Math.Max(
                nonGeoMatchCount,
                Cache.Cache.ActivePartyCount);

            return(nonGeoMatchCount / activePartyCount);
        }
Exemple #4
0
        public static ResultSet From(IntSet <ProfileId> profileIds)
        {
            if (IntSet <ProfileId> .IsEmpty(profileIds))
            {
                return(new ResultSet(0));
            }

            if (profileIds.IsUniverse)
            {
                return(Universe);
            }

            ResultSet             resultSet         = new ResultSet(profileIds.Count);
            Dictionary <int, int> profileToPartyMap = Snap.Cache.Cache.ProfileToPartyMap;

            foreach (int profileId in profileIds)
            {
                int partyId = Snap.Data.PartyInfo.INVALID_PARTY_ID;

                if (profileToPartyMap.TryGetValue(profileId, out partyId))
                {
                    Result r = null;

                    if (resultSet.mPartyIdToResult.TryGetValue(partyId, out r))
                    {
                        r.AddMatchingProfile(profileId);
                    }
                    else
                    {
                        Result newResult = new Result();
                        newResult.AddMatchingProfile(profileId);
                        resultSet.mPartyIdToResult.Add(
                            partyId,
                            newResult);
                    }
                }
            }

            return(resultSet);
        }
Exemple #5
0
        //----------------------------------------------------------------------
        private static ResultSet SearchByParty <ProfileType>(
            Timer t,
            IEnumerable <string> nameSearchNoiseWords,
            AddressParserResult searchLocale,
            int desiredResultCount,
            int maxResultCount,
            IntSet <PartyId> externalPartyMembershipTypeMatches,
            IntSet <PartyId> profileSpecificParties,
            double nonGeoMatchAbsDensity,
            ref Comparison <Result> sortOrder)
            where ProfileType : ISearch, new()
        {
            IntSet <PartyId> nameMatches      = null;
            IntSet <PartyId> locationMatches  = null;
            IntSet <PartyId> geoOrNameMatches = null;
            Location         centroid         = null;
            double?          maxRadiusMi      = null;
            ResultSet        rs = null;


            if (StringX.IsNotEmpty(searchLocale.PartyName))
            {
                nameMatches = SearchByName(t, searchLocale, nameSearchNoiseWords);
            }


            if (searchLocale.Type == Snap.Data.Controller.SearchType.PartyName)
            {
                geoOrNameMatches = nameMatches;
                sortOrder        = Result.NameAscending;
            }
            else
            {
                switch (new ProfileType().GeoSearch)
                {
                case GeoSearchType.Point:

                    locationMatches = SearchForLocations(
                        t, nameSearchNoiseWords, searchLocale, desiredResultCount,
                        maxResultCount, nonGeoMatchAbsDensity,
                        out centroid, out maxRadiusMi);
                    break;

                case GeoSearchType.ServiceArea:
                    locationMatches = SearchForServiceArea(t, searchLocale);
                    break;

                case GeoSearchType.All:
                    var pointMatches = SearchForLocations(
                        t, nameSearchNoiseWords, searchLocale, desiredResultCount,
                        maxResultCount, nonGeoMatchAbsDensity, out centroid, out maxRadiusMi);
                    var svcAreaMatches = SearchForServiceArea(t, searchLocale);
                    locationMatches = IntSet <PartyId> .Union(pointMatches, svcAreaMatches);

                    sortOrder = Result.ShowServiceAreaMatchesFirst(svcAreaMatches, sortOrder);
                    break;

                default:
                    throw new ArgumentException(String.Format(
                                                    "Unexpected value of 'ISearch.GeoSearch': {0}",
                                                    new ProfileType().GeoSearch.ToString()));
                }
                geoOrNameMatches = StringX.IsNotEmpty(searchLocale.PartyName) ? IntSet <PartyId> .Intersection(nameMatches, locationMatches) : locationMatches;
            }



            rs = ResultSet.From(
                centroid,
                maxRadiusMi,
                IntSet <PartyId> .IntersectionOfMany(
                    geoOrNameMatches,
                    externalPartyMembershipTypeMatches,
                    profileSpecificParties));

            if (Snap.Data.Controller.SearchType.Membership == searchLocale.Type)
            {
                rs.UnfilteredMatchCount = externalPartyMembershipTypeMatches.Count;
            }
            else if (IntSet <PartyId> .IsEmpty(geoOrNameMatches))
            {
                rs.UnfilteredMatchCount = 0;
            }
            else
            {
                rs.UnfilteredMatchCount = geoOrNameMatches.Count;
            }


            return(rs);
        }