Beispiel #1
0
        public DomainConstraint TransformConstraint()
        {
            DomainConstraint    metricDomainConstraint = null;
            QualitativeRelation requiredRelation       = this.allowedRelations[0] as QualitativeRelation;

            // The metric relations that might be needed
            BinaryRelation lessThanRelation    = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.LessThan);
            BinaryRelation greaterThanRelation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.GreaterThan);
            BinaryRelation equalsRelation      = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.Equals);

            switch (requiredRelation.Name)
            {
            case PointsAlgebraRelationNames.After:
                // A After B	 |  A.Attr > B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, greaterThanRelation, this.CanBeViolated);
                break;

            case PointsAlgebraRelationNames.Before:
                // A Before B	 |  A.Attr < B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, lessThanRelation, this.CanBeViolated);
                break;

            case PointsAlgebraRelationNames.Equals:
                // A Equals B	 |  A.Attr = B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, equalsRelation, this.CanBeViolated);
                break;
            }

            // Setting the relation parts
            if (metricDomainConstraint != null)
            {
                AttributeDomainRelationPart attrComp1Part = this.GenerateRelationPart(this.DomainRelationParts[0], this.Comp1Attribute);
                AttributeDomainRelationPart attrComp2Part = this.GenerateRelationPart(this.DomainRelationParts[1], this.Comp2Attribute);

                metricDomainConstraint.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1Part, attrComp2Part
                };
            }

            return(metricDomainConstraint);
        }
        /// <summary>
        /// Finds the AttributeDomainRelationPart for a specific attribute and IRelationPart
        /// </summary>
        /// <param name="relPart">The relation part for which to generate the attribute rel part</param>
        /// <param name="attribute">The attribute to apply</param>
        /// <returns></returns>
        private AttributeDomainRelationPart GenerateRelationPart(IDomainRelationPart relPart, GKOAttribute attribute)
        {
            AttributeDomainRelationPart attributePart;

            if (relPart is ComponentDomainRelationPart)
            {
                attributePart = new AttributeDomainRelationPart((relPart as ComponentDomainRelationPart).Filter, attribute);
            }
            else if (relPart is AttributeDomainRelationPart)
            {
                attributePart           = (relPart as AttributeDomainRelationPart);
                attributePart.Attribute = attribute;
            }
            else
            {
                throw new InvalidOperationException(string.Format("The Interval Algebra to metric domain constraint '{0}' has invalid relation parts", this.Name));
            }

            return(attributePart);
        }
        public DomainConstraint TransformConstraint()
        {
            List <DomainConstraint> metricDomainConstraints = new List <DomainConstraint>();
            DomainConstraint        constr1          = null;
            DomainConstraint        constr2          = null;
            QualitativeRelation     requiredRelation = this.allowedRelations[0] as QualitativeRelation;

            // The metric relations that might be needed
            BinaryRelation lessThanRelation    = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.LessThan);
            BinaryRelation greaterThanRelation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.GreaterThan);
            BinaryRelation equalsRelation      = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.Equals);

            // The attribute domain relation parts that might be needed
            AttributeDomainRelationPart attrComp1IntervalStart = this.GenerateRelationPart(this.DomainRelationParts[0], this.Comp1IntervalStart);
            AttributeDomainRelationPart attrComp1IntervalEnd   = this.GenerateRelationPart(this.DomainRelationParts[0], this.Comp1IntervalEnd);
            AttributeDomainRelationPart attrComp2IntervalStart = this.GenerateRelationPart(this.DomainRelationParts[1], this.Comp2IntervalStart);
            AttributeDomainRelationPart attrComp2IntervalEnd   = this.GenerateRelationPart(this.DomainRelationParts[1], this.Comp2IntervalEnd);

            #region IA to Metric
            switch (requiredRelation.Name)
            {
            case IntervalAlgebraRelationNames.After:
                // A After B	 |  A.Start > B.End
                constr1 = new DomainConstraint(this.Name, greaterThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                break;

            case IntervalAlgebraRelationNames.Before:
                // A Before B
                //      A.End < B.Start
                constr1 = new DomainConstraint(this.Name, lessThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalStart
                };

                metricDomainConstraints.Add(constr1);
                break;

            case IntervalAlgebraRelationNames.During:
                // A During B
                //      A.Start > B.Start
                //      A.End < B.End
                constr1 = new DomainConstraint(this.Name + "_part1", greaterThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };
                constr2 = new DomainConstraint(this.Name + "_part2", lessThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Equals:
                // A Equals B
                //      A.Start = B.Start
                //      A.End = B.End
                constr1 = new DomainConstraint(this.Name + "_part1", equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };
                constr2 = new DomainConstraint(this.Name + "_part2", equalsRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.FinishedBy:
                // A Finished-by B
                //      A.End = B.End
                //      A.Start < B.Start
                constr1 = new DomainConstraint(this.Name + "_part1", equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };
                constr2 = new DomainConstraint(this.Name + "_part2", lessThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Finishes:
                // A Finishes B
                //      A.End = B.End
                //      A.Start > B.Start
                constr1 = new DomainConstraint(this.Name + "_part1", equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };
                constr2 = new DomainConstraint(this.Name + "_part2", greaterThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Includes:
                // A Includes B
                //      A.Start < B.Start
                //      A.End > B.End
                constr1 = new DomainConstraint(this.Name + "_part1", lessThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };
                constr2 = new DomainConstraint(this.Name + "_part2", greaterThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Meets:
                // A Meets B
                //      A.End = B.Start
                constr1 = new DomainConstraint(this.Name, equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalStart
                };

                metricDomainConstraints.Add(constr1);
                break;

            case IntervalAlgebraRelationNames.MetBy:
                // A Met-by B
                //      A.Start = B.End
                constr1 = new DomainConstraint(this.Name, equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                break;

            case IntervalAlgebraRelationNames.OverlappedBy:
                // A Overlapped-by B
                //      A.End > B.End
                //      A.Start < B.End
                constr1 = new DomainConstraint(this.Name + "_part1", greaterThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };
                constr2 = new DomainConstraint(this.Name + "_part2", lessThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Overlaps:
                // A Overlaps B
                //      A.End < B.End
                //      A.End > B.Start
                constr1 = new DomainConstraint(this.Name + "_part1", lessThanRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };
                constr2 = new DomainConstraint(this.Name + "_part2", greaterThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalStart
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.StartedBy:
                // A Started-by B
                //      A.Start = B.Start
                //      A.End > B.End
                constr1 = new DomainConstraint(this.Name + "_part1", equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };
                constr2 = new DomainConstraint(this.Name + "_part2", greaterThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;

            case IntervalAlgebraRelationNames.Starts:
                //A Starts B
                //    A.Start = B.Start
                //    A.End < B.End
                constr1 = new DomainConstraint(this.Name + "_part1", equalsRelation, this.CanBeViolated);
                constr1.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalStart, attrComp2IntervalStart
                };
                constr2 = new DomainConstraint(this.Name + "_part2", lessThanRelation, this.CanBeViolated);
                constr2.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1IntervalEnd, attrComp2IntervalEnd
                };

                metricDomainConstraints.Add(constr1);
                metricDomainConstraints.Add(constr2);
                break;
            }
            #endregion

            if (metricDomainConstraints.Count == 0)
            {
                // The mapping was not found so return null
                return(null);
            }
            else if (metricDomainConstraints.Count == 1)
            {
                // If only one domain constraint can represent the IA then just return it
                return(metricDomainConstraints[0]);
            }
            else
            {
                // If the IA constraint has to be expressed with two metric constraints then use domain constraints combination
                return(new DomainConstraintCombination(this.Name, metricDomainConstraints, DomainConstraintCombinationType.And, this.CanBeViolated));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Checks whether an item should be added to the carthesian product when generating a configuration constraints
        /// <para>If the component of the new item matches the component of old ones the configuration constraint is ivalid</para>
        /// <para>EXCEPT: When the ComponentFilter generating the newItem actually specifies that it should be the same component as a previous one.
        /// In this case only equal components are returned as true</para>
        /// </summary>
        /// <param name="currTuple">The current relation tuple</param>
        /// <param name="newItem">The new item to add to the tuple</param>
        /// <returns></returns>
        private bool CheckNewRelationPart(List <IRelationPart> currTuple, IRelationPart newItem, Log log)
        {
            ComponentDomainRelationPart itemDomRelCompPart = this.DomainRelationParts[currTuple.Count] as ComponentDomainRelationPart;
            AttributeDomainRelationPart itemDomRelAttrPart = this.DomainRelationParts[currTuple.Count] as AttributeDomainRelationPart;

            // If it is not component or attribute relation part there are no constraints
            if (itemDomRelCompPart == null && itemDomRelAttrPart == null)
            {
                return(true);
            }
            else
            {
                int?samePartNr = null;

                // Finds whether the component part is equal to another component
                if (itemDomRelCompPart != null)
                {
                    samePartNr = itemDomRelCompPart.Filter.SameAsDomainRelationPartNr;
                }
                else if (itemDomRelAttrPart != null)
                {
                    samePartNr = itemDomRelAttrPart.Filter.SameAsDomainRelationPartNr;
                }

                // If the component part should equal to other component - it (the component) is found and checked if it matches the current one
                if (samePartNr.HasValue)
                {
                    if (currTuple.Count < samePartNr.Value || samePartNr.Value < 1)
                    {
                        log.AddItem(LogType.Warning, string.Format("The 'component same as filter' has wrong value({0} when the maximum is {1}) for domain constraint {2}. A configuration constraint cannot be generated.", samePartNr.Value, currTuple.Count, this.Name));
                        return(false);
                    }
                    else
                    {
                        ComponentRelationPart equalCompPart = currTuple[samePartNr.Value - 1] as ComponentRelationPart;
                        AttributeRelationPart equalAttrPart = currTuple[samePartNr.Value - 1] as AttributeRelationPart;

                        if (equalCompPart == null && equalAttrPart == null)
                        {
                            log.AddItem(LogType.Warning, string.Format("The 'component same as filter' points to relation part with no component included (i.e. metric part) for domain constraint {0}. A configuration constraint cannot be generated.", this.Name));
                            return(false);
                        }
                        else
                        {
                            ComponentRelationPart newItemCompPart = newItem as ComponentRelationPart;
                            AttributeRelationPart newItemAttrPart = newItem as AttributeRelationPart;

                            if (newItemCompPart == null && newItemAttrPart == null)
                            {
                                log.AddItem(LogType.Warning, string.Format("The 'component same as filter' points to relation part with no component included for domain constraint {0}. A configuration constraint cannot be generated.", this.Name));
                                return(false);
                            }
                            else
                            {
                                GKOComponent componentToComapre = null;

                                // The component from the new relation part is extracted
                                if (newItemCompPart != null)
                                {
                                    componentToComapre = newItemCompPart.Component;
                                }
                                else if (newItemAttrPart != null)
                                {
                                    componentToComapre = newItemAttrPart.Component;
                                }

                                // And finally the new component is compared with the one from the relation part it should match
                                if (equalCompPart != null)
                                {
                                    return(equalCompPart.Component.Id == componentToComapre.Id);
                                }
                                else if (equalAttrPart != null)
                                {
                                    return(equalAttrPart.Component.Id == componentToComapre.Id);
                                }

                                // this should not be reached
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    // If the value is not set to match other component then specificly exclude matching the same components
                    return(!currTuple.Any(x =>
                                          ((x is ComponentRelationPart) && (x as ComponentRelationPart).Equals(newItem)) ||
                                          ((x is AttributeRelationPart) && (x as AttributeRelationPart).Equals(newItem))
                                          ));
                }
            }
        }