Exemplo n.º 1
0
        public override List <TmsConstraint> GetTmsConstraints(ConfigurationConstraint constraint, Edge edge)
        {
            List <TmsConstraint> result    = new List <TmsConstraint>();
            RelationFamily       relFamily = constraint.AllowedRelations[0].RelationFamily;

            if (!(edge is MetricEdge))
            {
                edge.Network.SturcturalReasonerLog.AddItem(LogType.Warning, string.Format("Edge {0} is not a metric 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 qualitative while the needed relation for edge {1} is metric. The requested TMS constraints will not be added.", constraint.DomainConstraint.Name, edge.GetUId()));
            }
            else
            {
                string        dVarA         = edge.EndNode.GetDVarName();
                string        dVarMetric    = (constraint.RelationParts[1] as MetricRelationPart).GetDVarName();
                TmsConstraint tmsConstraint = new TmsConstraint();

                tmsConstraint.ConstraintType = TmsManager.CTNameGreaterThan;
                tmsConstraint.VariableTuple  = new List <string>()
                {
                    dVarA, dVarMetric, constraint.GetSatDVarName()
                };

                result.Add(tmsConstraint);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // A - BeginOfTime is in [n+1, MAX]
            MetricRelationPart relPartN = constraint.RelationParts[1] as MetricRelationPart;
            Interval           interval = new Interval(relPartN.GetIntValue() + 1, StructuralRelationsManager.MetricDomain.MaxValue); List <Interval> intervals = new List <Interval>();

            intervals.Add(interval);

            return(intervals);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // B-A is in [0, MAX]
            Interval        interval  = new Interval(0, StructuralRelationsManager.MetricDomain.MaxValue);
            List <Interval> intervals = new List <Interval>();

            intervals.Add(interval);

            return(intervals);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // B-A is in [0, 0]
            Interval        interval  = new Interval(0, 0);
            List <Interval> intervals = new List <Interval>();

            intervals.Add(interval);

            return(intervals);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // B-A is in [-n, -n]
            MetricRelationPart relPartN  = constraint.RelationParts[2] as MetricRelationPart;
            Interval           interval  = new Interval(-relPartN.GetIntValue(), -relPartN.GetIntValue());
            List <Interval>    intervals = new List <Interval>();

            intervals.Add(interval);

            return(intervals);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // A - BeginOfTime is in [n, n]
            MetricRelationPart relPartN  = constraint.RelationParts[1] as MetricRelationPart;
            Interval           interval  = new Interval(relPartN.GetIntValue(), relPartN.GetIntValue());
            List <Interval>    intervals = new List <Interval>();

            intervals.Add(interval);

            return(intervals);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Finds the implied (by a constraint) difference between the value of the two nodes as a union of intervals
        /// </summary>
        /// <param name="constraint">The constraint implying the difference</param>
        /// <returns></returns>
        public List <Interval> GetDifferenceIntervals(ConfigurationConstraint constraint)
        {
            // B - A is in [-MAX, -1] or [1, MAX]
            Interval        interval1 = new Interval(-StructuralRelationsManager.MetricDomain.MaxValue, -1);
            Interval        interval2 = new Interval(1, StructuralRelationsManager.MetricDomain.MaxValue);
            List <Interval> intervals = new List <Interval>();

            intervals.Add(interval1);
            intervals.Add(interval2);

            return(intervals);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Assigns a list of intervals to a configuration constraint. Use this instead of directly adding new items to the property.
        /// </summary>
        /// <param name="constraint">The constraint</param>
        /// <param name="intervals">The list of intervals allowed by the constraint</param>
        public void AddConstraintIntervals(ConfigurationConstraint constraint, List <Interval> intervals, Log log)
        {
            if (!Constraints.Contains(constraint))
            {
                this.Constraints.Add(constraint);
            }

            if (!ConstraintIntervals.ContainsKey(constraint))
            {
                ConstraintIntervals.Add(constraint, intervals);
            }
            else
            {
                log.AddItem(LogType.Warning, String.Format("A constraint {0}-{1} is assigned intervals more than once", this.GetUId(), constraint.DomainConstraint.Name));
            }
        }
Exemplo n.º 9
0
        public ConfigurationConstraint GetInverseConstraint(ConfigurationConstraint constraint)
        {
            ConfigurationConstraint inverseConstraint = new ConfigurationConstraint(constraint.DomainConstraint);
            List <IRelationPart>    relationParts     = new List <IRelationPart>();

            inverseConstraint.AllowedRelations = new List <BinaryRelation>()
            {
                StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.GreaterOrEquals)
            };

            relationParts.Add(constraint.RelationParts[1]);
            relationParts.Add(constraint.RelationParts[0]);

            inverseConstraint.SetRelationParts(relationParts);

            return(inverseConstraint);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generates the configuration constraints matching the domain constraint for a given list of components
        /// </summary>
        /// <param name="componentsList">The list of components</param>
        /// <returns>A list of configuration constraints representing the domain constraint</returns>
        internal virtual List <ConfigurationConstraint> GenerateConfigurationConstraints(List <GKOComponent> componentsList, Log log)
        {
            List <ConfigurationConstraint> constraints = new List <ConfigurationConstraint>();

            if (DomainRelationParts != null && DomainRelationParts.Count > 0 && componentsList != null && componentsList.Count > 0)
            {
                List <List <IRelationPart> > possibleParts = new List <List <IRelationPart> >();
                IEnumerable <IEnumerable <IRelationPart> > partsCarthesianProduct = new[] { Enumerable.Empty <IRelationPart>() };

                for (int i = 0; i < DomainRelationParts.Count; i++)
                {
                    possibleParts.Add(DomainRelationParts[i].GeneratePossibleRelationParts(componentsList, log));
                }

                // Calculating the carthesian product of the different relation parts
                partsCarthesianProduct = possibleParts.Aggregate(
                    partsCarthesianProduct,
                    (accumulator, sequence) =>
                    from accseq in accumulator
                    from item in sequence
                    // ToDo: Check if the filter works properly
                    // This prohibits relations including the same elements (components/attributes)
                    where CheckNewRelationPart(accseq.ToList(), item, log)
                    select accseq.Concat(new[] { item }));

                foreach (var relationPartsAssignment in partsCarthesianProduct)
                {
                    ConfigurationConstraint constraint = new ConfigurationConstraint(this);

                    try
                    {
                        constraint.AllowedRelations = this.allowedRelations;
                        constraint.SetRelationParts(relationPartsAssignment.ToList());
                        constraints.Add(constraint);
                    }
                    catch (Exception ex)
                    {
                        log.AddItem(LogType.Warning, "A configuration constraint could not be created: " + ex.ToString());
                    }
                }
            }

            return(constraints);
        }
Exemplo n.º 11
0
        public override string ToString(ConfigurationConstraint constraint)
        {
            List <Interval> intervals = this.GetDifferenceIntervals(constraint);

            return(string.Format("B > {0}  i.e.  B in {1}", (constraint.RelationParts[1] as MetricRelationPart).GetIntValue(), intervals.Select(x => x.ToString()).Aggregate((a, b) => a + " or " + b)));
        }
        /// <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);
        }
Exemplo n.º 13
0
        public override string ToString(ConfigurationConstraint constraint)
        {
            List <Interval> intervals = this.GetDifferenceIntervals(constraint);

            return(string.Format("A <= B  i.e.  B - A in {0}", intervals.Select(x => x.ToString()).Aggregate((a, b) => a + " or " + b)));
        }
 public override string ToString(ConfigurationConstraint constraint)
 {
     return(string.Format("A {0} B", this.Name));
 }
Exemplo n.º 15
0
 public override Node GetStartNode(ConfigurationConstraint constraint)
 {
     return(null);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Finds the end node of of a constraint
 /// <para>The end node is Y in the relation: XrY</para>
 /// </summary>
 /// <param name="constraint">The constraint specifying the elements of the relation</param>
 /// <returns>The node representing the end element of the relation</returns>
 public abstract Node GetEndNode(ConfigurationConstraint constraint);
Exemplo n.º 17
0
 /// <summary>
 /// Generates the TMS constraints for a particular configuration constraint in a constraint network edge
 /// <para>Does not handle soft constraints!</para>
 /// </summary>
 /// <param name="constraint">The constraint</param>
 /// <param name="edge">The constraint network edge that holds the configuration constraint</param>
 public abstract List <TmsConstraint> GetTmsConstraints(ConfigurationConstraint constraint, Edge edge);
Exemplo n.º 18
0
 /// <summary>
 /// Provides a human readable explanation. A nad B are used as placeholders for the first and second Node relaiton part
 /// </summary>
 /// <param name="constraint">The constraint for which to provide the explanation</param>
 /// <returns></returns>
 public abstract string ToString(ConfigurationConstraint constraint);
Exemplo n.º 19
0
 public override Node GetEndNode(ConfigurationConstraint constraint)
 {
     return(constraint.RelationParts[0].ToNode());
 }
Exemplo n.º 20
0
 public override Node GetStartNode(ConfigurationConstraint constraint)
 {
     // null is used for the beginning of time
     return(null);
 }
Exemplo n.º 21
0
 public ConfigurationConstraint GetInverseConstraint(ConfigurationConstraint constraint)
 {
     throw new NotSupportedException("No inverse relation is available for relation " + this.Name);
 }
        /// <summary>
        /// Adds a configuration constraint
        /// </summary>
        /// <param name="constraint">The constraint to add</param>
        /// <param name="constrNetworks">The list of possible constraint networks where the constraint can e added</param>
        /// <param name="log"></param>
        private static void ApplyMetricConstraint(ConfigurationConstraint constraint, List <ConstraintNetwork> constrNetworks, Log log)
        {
            IMetricRelation relation = constraint.AllowedRelations[0] as IMetricRelation;

            if (relation == null)
            {
                log.AddItem(LogType.Warning, String.Format("A constraint ({0}) is skipped during the generation of a metric constraint network, because it is {1} relation and not recognized as metric.", constraint.DomainConstraint.Name, constraint.AllowedRelations[1].RelationFamily.Name));
            }
            else
            {
                ConstraintNetwork constraintNetwork = constrNetworks.Single(x => constraint.GetIncludedNodes().All(y => x.Nodes.Contains(y)));
                Node startNode                    = (relation as BinaryRelation).GetStartNode(constraint);
                Node endNode                      = (relation as BinaryRelation).GetEndNode(constraint);
                Tuple <Node, Node> edgeKey        = new Tuple <Node, Node>(startNode, endNode);
                Tuple <Node, Node> reverseEdgeKey = new Tuple <Node, Node>(endNode, startNode);
                List <Interval>    intervals      = relation.GetDifferenceIntervals(constraint);

                // Check if the edge already exists
                if (constraintNetwork.Edges.ContainsKey(edgeKey))
                {
                    // Adding the current constraint to the edge
                    MetricEdge edge = constraintNetwork.Edges[edgeKey] as MetricEdge;
                    ConfigurationConstraint equalConstraint = edge.Constraints.SingleOrDefault(x => x.Equals(constraint));

                    // Add the constraint if an equal one doesn't already exist
                    if (equalConstraint == null)
                    {
                        edge.AddConstraintIntervals(constraint, intervals, log);
                    }
                    else
                    {
                        // Adding the constraints as implied by a previous one
                        edge.ImpliedConstraints.Add(constraint);
                        constraint.EqualActiveConstraint = equalConstraint;
                    }
                }
                // Check if the reverse of the edge exists
                else if (constraintNetwork.Edges.ContainsKey(reverseEdgeKey))
                {
                    // Adding the inverse constraint to the mirror edge
                    MetricEdge              edge = constraintNetwork.Edges[reverseEdgeKey] as MetricEdge;
                    IMetricRelation         asMetricConstraint        = (IMetricRelation)constraint.AllowedRelations[0];
                    ConfigurationConstraint inverseConstraint         = asMetricConstraint.GetInverseConstraint(constraint);
                    IMetricRelation         inverseAsMetricConstraint = (IMetricRelation)inverseConstraint.AllowedRelations[0];
                    ConfigurationConstraint equalConstraint           = edge.Constraints.SingleOrDefault(x => x.Equals(inverseConstraint));

                    // Since the inverse constraint is used, it should be included instead of the current one in the constraint tree
                    constraint.OwningTree.SwitchConstraint(constraint, inverseConstraint);

                    // Add the constraint if an equal one doesn't already exist
                    if (equalConstraint == null)
                    {
                        edge.AddConstraintIntervals(inverseConstraint, inverseAsMetricConstraint.GetDifferenceIntervals(inverseConstraint), log);
                    }
                    else
                    {
                        // Adding the constraints as implied by a previous one
                        edge.ImpliedConstraints.Add(inverseConstraint);
                        inverseConstraint.EqualActiveConstraint = equalConstraint;
                    }
                }
                // Adding the new edge with the found intervals
                else
                {
                    MetricEdge edge = new MetricEdge(constraintNetwork, edgeKey.Item1, edgeKey.Item2);

                    edge.AddConstraintIntervals(constraint, intervals, log);
                    constraintNetwork.Edges.Add(edgeKey, edge);
                }
            }
        }