public bool Equals(ConfigurationConstraint compared) { if (compared == null) { return(false); } if (this.RelationParts.Count != compared.RelationParts.Count) { return(false); } for (int i = 0; i < this.RelationParts.Count; i++) { if (this.RelationParts[i].GetType().Equals(compared.RelationParts[i].GetType())) { if (this.RelationParts[i] is MetricRelationPart && !(this.RelationParts[i] as MetricRelationPart).Equals(compared.RelationParts[i])) { return(false); } if (this.RelationParts[i] is AttributeRelationPart && !(this.RelationParts[i] as AttributeRelationPart).Equals(compared.RelationParts[i])) { return(false); } if (this.RelationParts[i] is ComponentRelationPart && !(this.RelationParts[i] as ComponentRelationPart).Equals(compared.RelationParts[i])) { return(false); } } } return(this.AllowedRelations.Intersect(compared.AllowedRelations).Count() == this.AllowedRelations.Count && this.DomainConstraint.CanBeViolated == compared.DomainConstraint.CanBeViolated); }
/// <summary> /// Gets the name of the decision variable which is used to test whether the constraint is satisfied. /// </summary> /// <param name="constraint">The soft constraints for which is the decision variable</param> /// <returns></returns> public static string GetSatDVarName(this ConfigurationConstraint constraint) { // Hack: Currently the name of the start and end node is used for uniques identifier, which is not applicable for non-binary constraints if (constraint.EqualActiveConstraint == null) { return(String.Format("{0}-{1}-{2}-satisfied", constraint.DomainConstraint.Name, constraint.AllowedRelations[0].GetStartNode(constraint).GetUId(), constraint.AllowedRelations[0].GetEndNode(constraint).GetUId())); } else { // If the constraint is not active in the network the decision variable of its equal constraint is returned return(constraint.EqualActiveConstraint.GetSatDVarName()); } }
/// <summary> /// Switches a constraint with another constraint /// </summary> /// <param name="constraintToSwitch">The constraint to be removed from the tree</param> /// <param name="newConstraint">The new constraint to be added to the tree</param> internal void SwitchConstraint(ConfigurationConstraint constraintToSwitch, ConfigurationConstraint newConstraint) { newConstraint.OwningTree = this; this.ConfigurationConstraints.Remove(constraintToSwitch); this.ConfigurationConstraints.Add(newConstraint); }