/// <summary> /// Gets the boolean domain consisting of: /// <para> 0/F - meaning False </para> /// <para> 1/T - meaning True </para> /// </summary> /// <returns></returns> public static GKODomain GenerateBoolDomain() { GKODomain domain = new GKODomain() { Id = DomainNameBool, Name = DomainNameBool, Values = new List <string>() { TrueValue, FalseValue } }; return(domain); }
///// <summary> ///// Generates the domain used as index for the powerset of the enabled calculi ///// </summary> ///// <returns></returns> //private GKOIntDomain GenerateCalculiPwSetIxDomain() //{ // GKOIntDomain domain = new GKOIntDomain() // { // Id = DomainNameCalculiPwSetIx, // Name = DomainNameCalculiPwSetIx, // StepWidth = 1, // MinValue = 0, // MaxValue = (int)Math.Pow(2, StructuralRelationsManager.RelationFamilies.Max(x => x.Relations.Count)) // }; // return domain; //} #region Constraint Types /// <summary> /// Creates constraint types in the CS3, each new CT contains only one value from a domain. /// NOTE: These constraint types are used to allow only one value to be selected for a variable. /// </summary> /// <param name="domain">The domain to create constraint types for</param> /// <param name="addSoft">Specifies whether to add a softness variable at the end</param> private void CreateIndividualCTForDomain(GKODomainAbstract domain, bool addSoft) { List <GKOConstraintType> constraintTypes = new List <GKOConstraintType>(); List <string> domainValues = new List <string>(); if (domain is GKOIntDomain) { GKOIntDomain domainTemp = domain as GKOIntDomain; for (int i = domainTemp.MinValue; i < domainTemp.MaxValue + 1; i += domainTemp.StepWidth) { domainValues.Add(i.ToString()); } } else if (domain is GKODomain) { GKODomain domainTemp = domain as GKODomain; foreach (var value in domainTemp.Values) { domainValues.Add(value); } } foreach (var value in domainValues) { GKOConstraintType ct = new GKOConstraintType() { Id = domain.GetIndividualValueCTName(value), Name = domain.GetIndividualValueCTName(value), Signature = new List <GKODomainAbstract>() { domain }, Tuples = new List <List <string> >() { new List <string>() { value } } }; if (addSoft) { ct.Signature.Add(this.BoolDomain); ct.Tuples[0].Add(TrueValue); foreach (var excludedValue in domainValues) { ct.Tuples.Add(new List <string>() { excludedValue, FalseValue }); } } constraintTypes.Add(ct); } constraintTypes.ForEach(x => this.ConstraintTypes.Add(x.Name, x.CreateIConstraintType(cdaStarTms, this.Domains))); }
/// <summary> /// ! Use this only once (not for every relation) per edge constraint ! /// </summary> /// <param name="constraint"></param> /// <param name="edge"></param> /// <returns></returns> public override List <TmsConstraint> GetTmsConstraints(ConfigurationConstraint constraint, Edge edge) { ////OLD: Rem: Qualitative relations use composition constraints and constraint limiting the allowed relations between components, hence there are no constraints implied by a single relation //throw new NotSupportedException("A single qualitative relation do not imply a constraint!"); List <TmsConstraint> result = new List <TmsConstraint>(); RelationFamily relFamily = constraint.AllowedRelations[0].RelationFamily; if (!(edge is QualitativeEdge)) { edge.Network.SturcturalReasonerLog.AddItem(LogType.Warning, string.Format("Edge {0} is not a qualitative edge. The requested TMS constraints will not be added.", edge.GetUId())); } else if (!edge.Constraints.Contains(constraint)) { edge.Network.SturcturalReasonerLog.AddItem(LogType.Warning, string.Format("The constraint {0} is not found in the edge {1}. The requested TMS constraints will not be added.", constraint.DomainConstraint.Name, edge.GetUId())); } else if (relFamily == StructuralRelationsManager.GetRelationFamily(RelationFamilyNames.MetricRelationsName)) { edge.Network.SturcturalReasonerLog.AddItem(LogType.Warning, string.Format("The constraint {0} is metric while the needed relation for edge {1} is qualitative. The requested TMS constraints will not be added.", constraint.DomainConstraint.Name, edge.GetUId())); } else { QualitativeEdge qualEdge = (QualitativeEdge)edge; GKODomain calculusDomain = StructuralRelationsManager.GetDomain(constraint.AllowedRelations[0].RelationFamily.GetTmsRelationsDomainName()); TmsConstraint exactlyOneHoldsConstraint = new TmsConstraint(); List <string> relDvars = new List <string>(); // holds all relation variables GKODomain boolDomain = TmsManager.GenerateBoolDomain(); string dVarSat = constraint.GetSatDVarName(); // This will create a constraint saying that the edge dvar is matching the chosen relation and the relation's dvar is TRUE, or if they are not matching and the relation's dvar is FALSE foreach (var relation in constraint.AllowedRelations) { TmsConstraint tmsConstraint = new TmsConstraint(); string edgeDVar = qualEdge.GetDVarName(); string edgeRelDVar = qualEdge.GetDVarName((QualitativeRelation)relation); string constraintTypeName = calculusDomain.GetIndividualValueCTName(relation.Name); relDvars.Add(edgeRelDVar); tmsConstraint.ConstraintType = constraintTypeName; tmsConstraint.VariableTuple = new List <string>() { edgeDVar, edgeRelDVar }; result.Add(tmsConstraint); } // This will create the constraint saying that one of the relation dvars has to be set // This works because the calculi are JEPD exactlyOneHoldsConstraint.ConstraintType = relDvars.Count.GetExactlyOneCTName(); exactlyOneHoldsConstraint.VariableTuple = new List <string>(relDvars); exactlyOneHoldsConstraint.VariableTuple.Add(dVarSat); // This prohibits the constraint to be violated if (!constraint.CanBeViolated) { result.Add(TmsConstraint.GenerateSingleValueConstraint(boolDomain, dVarSat, TmsManager.TrueValue)); } result.Add(exactlyOneHoldsConstraint); } return(result); }