/// <summary> /// Generates a TMS constraint restricting the value of a decision variable to a predefined one /// </summary> /// <param name="domain">The domain of the decision variable</param> /// <param name="dVarName">The decision variable</param> /// <param name="value">The value that the decision value is restricted to have</param> /// <returns>The TMS constraint</returns> internal static TmsConstraint GenerateSingleValueConstraint(GKODomainAbstract domain, string dVarName, string value) { TmsConstraint tmsConstraint = new TmsConstraint(); tmsConstraint.ConstraintType = domain.GetIndividualValueCTName(value); tmsConstraint.VariableTuple = new List <string>() { dVarName }; return(tmsConstraint); }
///// <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))); }