コード例 #1
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;
     }
 }
コード例 #2
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));
 }