private List <RelationshipCandidate[]> GetAllPossibleVectors() { List <RelationshipCandidate[]> candidates = new List <RelationshipCandidate[]>(); int totalCombinationsCount = 1; foreach (var end in this.ends) { totalCombinationsCount *= end.Candidates.Count; } for (int i = 0; i < totalCombinationsCount; i++) { RelationshipCandidate[] relationshipGroup = new RelationshipCandidate[this.ends.Count]; int factor = 1; for (int j = 0; j < this.ends.Count; j++) { int index = (i / factor) % this.ends[j].Candidates.Count; factor *= this.ends[j].Candidates.Count; relationshipGroup[j] = this.ends[j].Candidates[index]; } if (!this.usedVectors.Any(c => this.IsSameKey(c, relationshipGroup))) { candidates.Add(relationshipGroup); } } return(candidates); }
private void RemoveCandidate(RelationshipCandidate toRemove) { toRemove.Parent.Candidates.Remove(toRemove); if (this.endsWhichFormTheKey.Contains(toRemove.Parent)) { var rowsToRemove = this.usedVectors.Where(v => v.Contains(toRemove)).ToList(); foreach (var row in rowsToRemove) { this.usedVectors.Remove(row); } } }
/// <summary> /// Considers the candidate for this relationship. /// </summary> /// <param name="entitySet">The entity set.</param> /// <param name="entityType">Type of the entity.</param> /// <param name="key">The entity data key of the candidate.</param> public void ConsiderCandidate(EntitySet entitySet, EntityType entityType, EntityDataKey key) { foreach (RelationshipGroupEnd end in this.ends.Where(e => e.EntitySet == entitySet && entityType.IsKindOf(e.EntityType))) { CapacityRange capacityRange = end.CapacitySelector(); if (capacityRange != CapacityRange.Zero) { this.RemoveCandidatesOnTargetBasedOnTreshhold(end); RelationshipCandidate candidate = new RelationshipCandidate(end, key, capacityRange); end.Candidates.Add(candidate); } } }
private void IncrementRelatedCount(RelationshipCandidate candidate) { bool isMinimumRequirementAlreadyMet = candidate.IsMinimumRequirementMet; candidate.IncrementRelatedCount(); if (candidate.IsCapacityReached) { this.RemoveCandidate(candidate); } else if (!isMinimumRequirementAlreadyMet && candidate.IsMinimumRequirementMet) { this.RemoveCandidatesOnTargetBasedOnTreshhold(candidate.Parent); } }
/// <summary> /// Considers the candidate for this relationship. /// </summary> /// <param name="entitySet">The entity set.</param> /// <param name="entityType">Type of the entity.</param> /// <param name="key">The entity data key of the candidate.</param> public void ConsiderCandidate(EntitySet entitySet, EntityType entityType, EntityDataKey key) { foreach (RelationshipGroupEnd end in this.ends.Where(e => e.EntitySet == entitySet && entityType.IsKindOf(e.EntityType))) { CapacityRange capacityRange = end.CapacitySelector(); if (capacityRange != CapacityRange.Zero) { this.RemoveCandidatesOnTargetBasedOnTreshhold(end); RelationshipCandidate candidate = new RelationshipCandidate(end, key, capacityRange); end.Candidates.Add(candidate); } } }
private bool IsSameKey(RelationshipCandidate[] vector1, RelationshipCandidate[] vector2) { foreach (RelationshipGroupEnd end in this.endsWhichFormTheKey) { EntityDataKey key1 = vector1.Where(r => r.Parent == end).Select(r => r.EntityDataKey).Single(); EntityDataKey key2 = vector2.Where(r => r.Parent == end).Select(r => r.EntityDataKey).Single(); if (key1 != key2) { return false; } } return this.endsWhichFormTheKey.Count > 0; }
private void RegisterAsUsedVectorIfNeeded(RelationshipCandidate[] vector) { if (this.endsWhichFormTheKey.Count > 0) { this.usedVectors.Add(vector); } }
private void RemoveCandidate(RelationshipCandidate toRemove) { toRemove.Parent.Candidates.Remove(toRemove); if (this.endsWhichFormTheKey.Contains(toRemove.Parent)) { var rowsToRemove = this.usedVectors.Where(v => v.Contains(toRemove)).ToList(); foreach (var row in rowsToRemove) { this.usedVectors.Remove(row); } } }
private void IncrementRelatedCount(RelationshipCandidate candidate) { bool isMinimumRequirementAlreadyMet = candidate.IsMinimumRequirementMet; candidate.IncrementRelatedCount(); if (candidate.IsCapacityReached) { this.RemoveCandidate(candidate); } else if (!isMinimumRequirementAlreadyMet && candidate.IsMinimumRequirementMet) { this.RemoveCandidatesOnTargetBasedOnTreshhold(candidate.Parent); } }
private IList<RelationshipDescription> GetRelationshipDescriptions(RelationshipCandidate[] group) { List<RelationshipDescription> relationships = new List<RelationshipDescription>(); List<KeyValuePair<AssociationSet, AssociationSetEnd>> processedSetEndPairs = new List<KeyValuePair<AssociationSet, AssociationSetEnd>>(); foreach (RelationshipCandidate toSide in group) { foreach (var setEndPair in toSide.Parent.AssociationSetEnds.Where(p => !processedSetEndPairs.Contains(p))) { // Find the "from" side of the relationship foreach (var from in group.Where(c => c != toSide).Select(c => new { FromSide = c, OtherSetEndPair = c.Parent.AssociationSetEnds.Where(p => p.Key == setEndPair.Key).SingleOrDefault() }) .Where(a => a.OtherSetEndPair.Key != null)) { relationships.Add(new RelationshipDescription( setEndPair.Key, from.FromSide.EntityDataKey, setEndPair.Value.AssociationEnd.RoleName, toSide.EntityDataKey)); processedSetEndPairs.Add(setEndPair); processedSetEndPairs.Add(from.OtherSetEndPair); } } } return relationships; }
private List<RelationshipCandidate[]> GetAllPossibleVectors() { List<RelationshipCandidate[]> candidates = new List<RelationshipCandidate[]>(); int totalCombinationsCount = 1; foreach (var end in this.ends) { totalCombinationsCount *= end.Candidates.Count; } for (int i = 0; i < totalCombinationsCount; i++) { RelationshipCandidate[] relationshipGroup = new RelationshipCandidate[this.ends.Count]; int factor = 1; for (int j = 0; j < this.ends.Count; j++) { int index = (i / factor) % this.ends[j].Candidates.Count; factor *= this.ends[j].Candidates.Count; relationshipGroup[j] = this.ends[j].Candidates[index]; } if (!this.usedVectors.Any(c => this.IsSameKey(c, relationshipGroup))) { candidates.Add(relationshipGroup); } } return candidates; }