Пример #1
0
        /// <summary>
        /// Finds the L mapped element.
        /// </summary>
        /// <param name="GraphElementName">Name of the graph element.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Graph element named \ + GraphElementName + \ was not found in the L-mapping of rule  + GraphElementName</exception>
        public graphElement findLMappedElement(string GraphElementName)
        {
            graphElement elt = rule.L[GraphElementName];

            if (elt != null)
            {
                return(findLMappedElement(elt));
            }
            throw new Exception("Graph element named \"" + GraphElementName + "\" was not found in the L-mapping of rule " + GraphElementName);
        }
Пример #2
0
 /// <summary>
 /// Finds the L mapped element.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <returns></returns>
 /// <exception cref="System.Exception">Graph element not found in rule's left-hand-side (GrammarRule.findMappedElement)</exception>
 public graphElement findLMappedElement(graphElement x)
 {
     if (x is hyperarc)
     {
         return(findLMappedHyperarc((hyperarc)x));
     }
     if (x is node)
     {
         return(findLMappedNode((node)x));
     }
     if (x is arc)
     {
         return(findLMappedArc((arc)x));
     }
     throw new Exception("Graph element not found in rule's left-hand-side (GrammarRule.findMappedElement)");
 }
 /// <summary>
 ///   Copies this graphElement data into the copyOfElt.
 /// </summary>
 /// <param name = "copyOfElt">The copy of elt.</param>
 protected virtual void copy(graphElement copyOfElt)
 {
     copyOfElt.name = name;
     foreach (var label in localLabels)
     {
         copyOfElt.localLabels.Add(label);
     }
     foreach (var d in localVariables)
     {
         copyOfElt.localVariables.Add(d);
     }
     if (DisplayShape != null)
     {
         copyOfElt.DisplayShape = DisplayShape.Copy(copyOfElt);
     }
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RelaxItem"/> class.
 /// </summary>
 /// <param name="RelaxationType">Type of the relaxation.</param>
 /// <param name="NumberAllowed">The number allowed.</param>
 /// <param name="GraphElement">The graph element.</param>
 /// <param name="Datum">The datum.</param>
 public RelaxItem(Relaxations RelaxationType, int NumberAllowed, graphElement GraphElement = null, string Datum = null)
 {
     this.GraphElement   = GraphElement;
     this.RelaxationType = RelaxationType;
     bothRevokeAndImpose = RelaxationType.ToString().EndsWith("_Altered");
     if (bothRevokeAndImpose)
     {
         prefixForAltered = RelaxationType.ToString().Replace("_Altered", "");
     }
     this.Datum         = Datum;
     this.NumberAllowed = NumberAllowed;
     if (GraphElement != null)
     {
         AppliesTo = (RelaxAppliesTo)Enum.Parse(typeof(RelaxAppliesTo), GraphElement.GetType().BaseType.Name, true);
     }
     else if (RelaxationType == Relaxations.Additional_Functions_Revoked ||
              RelaxationType == Relaxations.Contains_All_Global_Labels_Revoked ||
              RelaxationType == Relaxations.Ordered_Global_Labels_Revoked ||
              RelaxationType == Relaxations.Global_Label_Revoked ||
              RelaxationType == Relaxations.Negate_Global_Label_Revoked ||
              RelaxationType == Relaxations.Induced_Revoked ||
              RelaxationType == Relaxations.Shape_Restriction_Revoked)
     {
         AppliesTo = RelaxAppliesTo.graph;
     }
     else if (RelaxationType == Relaxations.Direction_Is_Equal_Revoked ||
              RelaxationType == Relaxations.Null_Means_Null_Revoked)
     {
         AppliesTo = RelaxAppliesTo.arc;
     }
     else if (RelaxationType == Relaxations.Strict_Degree_Match_Revoked ||
              RelaxationType == Relaxations.HyperArc_Preclusion_Revoked)
     {
         AppliesTo = RelaxAppliesTo.node;
     }
     else if (RelaxationType == Relaxations.Strict_Node_Count_Revoked)
     {
         AppliesTo = RelaxAppliesTo.hyperarc;
     }
     else
     {
         AppliesTo = RelaxAppliesTo.element;
     }
 }
Пример #5
0
 internal bool Matches(Relaxations rType, graphElement g = null, string datum = "")
 {
     if ((!string.IsNullOrWhiteSpace(Datum)) && (Datum != datum))
     {
         return(false);
     }
     if (NumberAllowed <= 0)
     {
         return(false);
     }
     if (RelaxationType == Relaxations.Any)
     {
         return(true);
     }
     if (bothRevokeAndImpose)
     {
         if (!rType.ToString().StartsWith(prefixForAltered))
         {
             return(false);
         }
     }
     else if (RelaxationType != rType)
     {
         return(false);
     }
     if (g == null)
     {
         return(true);
     }
     if (GraphElement != null)
     {
         return(GraphElement == g);
     }
     /* in the remaining cases, g is not null, but GraphElement is, so we need to look at "Applies To" */
     if (AppliesTo == RelaxAppliesTo.element)
     {
         return(true);
     }
     return((g is node && AppliesTo == RelaxAppliesTo.node) ||
            (g is arc && AppliesTo == RelaxAppliesTo.arc) ||
            (g is hyperarc && AppliesTo == RelaxAppliesTo.hyperarc));
 }