From: <mcu...@us...> - 2007-08-30 17:27:44
|
Revision: 1103 http://orm.svn.sourceforge.net/orm/?rev=1103&view=rev Author: mcurland Date: 2007-08-30 10:27:46 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Fixed bug that was causing us to only ever get one Permutation out of FindSmallestPermutationsInTermsOfConceptTypes(). Added EliminatePermutationsWithIdenticalResults(). refs #327 Modified Paths: -------------- trunk/Oial/ORMOialBridge/ORMOialBridgePermuter.cs Modified: trunk/Oial/ORMOialBridge/ORMOialBridgePermuter.cs =================================================================== --- trunk/Oial/ORMOialBridge/ORMOialBridgePermuter.cs 2007-08-30 17:26:19 UTC (rev 1102) +++ trunk/Oial/ORMOialBridge/ORMOialBridgePermuter.cs 2007-08-30 17:27:46 UTC (rev 1103) @@ -278,6 +278,7 @@ PermuteFactTypeMappings(chain.PossiblePermutations, chain.UndecidedOneToOneFactTypeMappings, newlyDecidedFactTypeMappings, deeplyMappedObjectTypes, 0); EliminateInvalidPermutations(chain); FindSmallestPermutationsInTermsOfConceptTypes(chain); + EliminatePermutationsWithIdenticalResults(chain); // Add each mapping from the optimal permutation to the "global" set of decided mappings. foreach (FactTypeMapping optimalMapping in ChooseOptimalPermutation(chain).Mappings) @@ -441,7 +442,7 @@ else { // We have the same number of top-level concept types as the minimum, so we need to check the number of non-top-level concept types. - if (nonTopLevelConceptTypes.Count > minTopLevelConceptTypesCount) + if (nonTopLevelConceptTypes.Count > minNonTopLevelConceptTypesCount) { // This isn't an optimal permutation, so go on to the next one. continue; @@ -458,8 +459,55 @@ } } + /// <summary> + /// Eliminates <see cref="Permutation"/>s that have the same set of top-level concept types and non-top-level concept types, + /// which will always result in the same OIAL. + /// </summary> + private static void EliminatePermutationsWithIdenticalResults(Chain chain) + { + PermutationList smallestPermutationsInTermsOfConceptTypes = chain.SmallestPermutationsInTermsOfConceptTypes; + for (int currentPermutationIndex = 0; currentPermutationIndex < smallestPermutationsInTermsOfConceptTypes.Count - 1; currentPermutationIndex++) + { + Permutation currentPermutation = smallestPermutationsInTermsOfConceptTypes[currentPermutationIndex]; + for (int comparisonPermutationIndex = smallestPermutationsInTermsOfConceptTypes.Count - 1; comparisonPermutationIndex > currentPermutationIndex; comparisonPermutationIndex--) + { + Permutation comparisonPermutation = smallestPermutationsInTermsOfConceptTypes[comparisonPermutationIndex]; + bool hasIdenticalConceptTypes = true; + // Check if comparisonPermutation has the same top-level concept types. + foreach (ObjectType topLevelConceptType in currentPermutation.TopLevelConceptTypes.Keys) + { + if (!comparisonPermutation.TopLevelConceptTypes.ContainsKey(topLevelConceptType)) + { + hasIdenticalConceptTypes = false; + break; + } + } + if (hasIdenticalConceptTypes) + { + // Check if comparisonPermutation has the same non-top-level concept types. + foreach (ObjectType nonTopLevelConceptType in currentPermutation.NonTopLevelConceptTypes.Keys) + { + if (!comparisonPermutation.NonTopLevelConceptTypes.ContainsKey(nonTopLevelConceptType)) + { + hasIdenticalConceptTypes = false; + break; + } + } + if (hasIdenticalConceptTypes) + { + // comparisonPermutation has the same set of top-level and non-top-level concept types, so we can get rid of it. + // It is entirely arbitrary which one we get rid of, so we'll keep the first since it is easier. + smallestPermutationsInTermsOfConceptTypes.RemoveAt(comparisonPermutationIndex); + } + } + } + } + } + + + private static Permutation ChooseOptimalPermutation(Chain chain) { // UNDONE: This should do something smart! This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |