/// <summary> Creates a new set relation. </summary> /// <param name="leftOperand"> The first set in the relation (order only matters for the containment relation, in which case this is the smaller (or equal) set). </param> /// <param name="rightOperand"> The second set in the relation (order only matters for the containment relation, in which case this is the larger (or equal) set).</param> /// <param name="relation"> The relation conveyed by this instance that the two specified sets have. </param> public SetRelation(Set leftOperand, Set rightOperand, SetRelationType relation) { Contract.Requires(leftOperand != null); Contract.Requires(rightOperand != null); Contract.RequiresEnumIsDefined(relation); LeftOperand = leftOperand; RightOperand = rightOperand; Relation = relation; }
public override void Add(SetRelationType relation, Set lhs, Set rhs) { Contract.Requires(lhs != null); Contract.Requires(rhs != null); Contract.Requires(lhs.IsConstant); Contract.Requires(rhs.IsConstant); Contract.RequiresEnumIsDefined(relation); SetRelations.Add(lhs, rhs, relation); }
/// <summary> Checks whether the two specified sets have the specified relation. Doesn't work for containment. </summary> private bool CheckRelation(Set firstSet, Set secondSet, SetRelationType relation) { Contract.Requires(firstSet != null); Contract.Requires(secondSet != null); Contract.RequiresEnumIsDefined(relation); //allows empty sets if (firstSet == DefaultNotions.EmptySet) return relation == SetRelationType.Subset; if (secondSet == DefaultNotions.EmptySet) return relation == SetRelationType.Disjoint; if (firstSet == DefaultNotions.Unknown) return true; if (secondSet == DefaultNotions.Unknown) return false; bool result = this.relations[firstSet][secondSet] == relation; #if DEBUG if (relation.IsAnyOf(SetRelationType.Unknown, SetRelationType.Disjoint)) { bool otherResult = this.relations[secondSet][firstSet] == relation; Contract.Assert(result == otherResult, "Relation." + relation.ToString() + " isn't stored symmetrically"); } #endif return result; }
/// <summary> Adds the specified set relation to the knowledge of this set relations tracker. </summary> public void Add(Set lhs, Set rhs, SetRelationType relation) { Contract.Requires(lhs != null); Contract.Requires(rhs != null); Contract.Requires(lhs.IsConstant); Contract.Requires(rhs.IsConstant); Contract.RequiresEnumIsDefined(relation); switch (relation) { case SetRelationType.Disjoint: AddNoOverlapRelation(lhs, rhs); break; case SetRelationType.Overlap: AddOverlapRelation(lhs, rhs); break; case SetRelationType.Subset: AddSubsetRelation(lhs, rhs); break; case SetRelationType.Unknown: throw new NotImplementedException(); default: throw new Exception(); } }