/// <summary> /// Returns a copy of this instance. /// </summary> /// <returns>the copy of the arc.</returns> public override arc copy() { var copyOfArc = new ruleArc(); copy(copyOfArc); return(copyOfArc); }
private void checkForNegativeArc(option location, node fromLNode, node fromHostNode, ruleArc newLArc) { var currentLArcIndex = L.arcs.IndexOf(newLArc); /* so, currentLArcIndex now, points to a LArc that has yet to be recognized. What we do from * this point depends on whether that LArc points to an L node we have yet to recognize, an L * node we have recognized, or null. */ var nextLNode = (ruleNode)newLArc.otherNode(fromLNode); /* first we must match the arc to a possible arc leaving the fromHostNode .*/ node nextHostNode = (nextLNode == null) ? null : location.findLMappedNode(nextLNode); var neighborHostArcs = fromHostNode.arcs.FindAll(a => (a is arc && !location.arcs.Contains(a)) && arcMatches(newLArc, (arc)a, fromHostNode, nextHostNode, (newLArc.From == fromLNode))).Cast <arc>(); if ((nextHostNode != null) || newLArc.nullMeansNull) { foreach (var HostArc in neighborHostArcs) { var newLocation = location.copy(); newLocation.arcs[currentLArcIndex] = HostArc; findNegativeStartElement(newLocation); if ((bool)AllNegativeElementsFound) { return; /* another sub-branch found a match to the negative elements. * There's no point in finding more than one, so this statement * aborts the search down this branch. */ } } } else { foreach (var HostArc in neighborHostArcs) { nextHostNode = HostArc.otherNode(fromHostNode); if (!location.nodes.Contains(nextHostNode)) { var newLocation = location.copy(); newLocation.arcs[currentLArcIndex] = HostArc; if (nextLNode == null) { findNegativeStartElement(newLocation); } else { checkForNegativeNode(newLocation, nextLNode, nextHostNode); } } if ((bool)AllNegativeElementsFound) { return; /* another sub-branch found a match to the negative elements. * There's no point in finding more than one, so this statement * aborts the search down this branch. */ } } } }
public void addArcsFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Boolean ruleGraph) { Shape fromShape, toShape; arc temparc; foreach (Connection a in graphControl1.Connections) { if (!arcs.Exists(delegate(arc b) { return(b.displayShape == a); })) { if (ruleGraph) { temparc = new ruleArc(nameFromText(a.Text)); } else { temparc = new arc(nameFromText(a.Text)); } this.arcs.Add(temparc); } else { temparc = arcs.Find(delegate(arc b) { return(b.displayShape == a); }); } fromShape = a.From.BelongsTo; toShape = a.To.BelongsTo; temparc.From = nodes.Find(delegate(node c) { return(sameName(c.name, fromShape.Text)); }); temparc.To = nodes.Find(delegate(node c) { return(sameName(c.name, toShape.Text)); }); for (int i = 0; i != fromShape.Connectors.Count; i++) { if (fromShape.Connectors[i] == a.From) { temparc.fromConnector = i; } } for (int i = 0; i != toShape.Connectors.Count; i++) { if (toShape.Connectors[i] == a.To) { temparc.toConnector = i; } } if (a.Text != "[Not_set]") { temparc.name = nameFromText(a.Text); temparc.localLabels = labelsFromText(a.Text); } temparc.displayShape = a; temparc.setStyleKeyFromDisplayShape(); } }
private string KarcsChangeDirection() { string badArcNames = ""; foreach (ruleArc a in L.arcs) { ruleArc b = (ruleArc)R.arcs.Find(delegate(arc c) { return(c.name == a.name); }); if ((b != null) && ((a.To.name == b.From.name) || (a.From.name == b.To.name))) { badArcNames += a.name + ", "; } } return(badArcNames); }
private void checkArcAvoidNegatives(option location, node fromLNode, node fromHostNode, ruleArc newLArc) { var currentLArcIndex = L.arcs.IndexOf(newLArc); /* so, currentLArcIndex now, points to a LArc that has yet to be recognized. What we do from * this point depends on whether that LArc points to an L node we have yet to recognize, an L * node we have recognized, or null. */ var nextLNode = (ruleNode)newLArc.otherNode(fromLNode); /* first we must match the arc to a possible arc leaving the fromHostNode .*/ var nextHostNode = (nextLNode == null || nextLNode.NotExist) ? null : location.findLMappedNode(nextLNode); var neighborHostArcs = fromHostNode.arcs.FindAll(a => (a is arc && !location.arcs.Contains(a)) && (arcMatches(newLArc, (arc)a, fromHostNode, nextHostNode, (newLArc.From == fromLNode)) || arcMatchRelaxed(newLArc, (arc)a, location, fromHostNode, nextHostNode, (newLArc.From == fromLNode)))).Cast <arc>(); //relaxelt if ((nextHostNode != null) || newLArc.nullMeansNull) { foreach (var HostArc in neighborHostArcs) { var newLocation = location.copy(); newLocation.arcs[currentLArcIndex] = HostArc; FindPositiveStartElementAvoidNegatives(newLocation); } } else { foreach (var HostArc in neighborHostArcs) { nextHostNode = HostArc.otherNode(fromHostNode); if (!location.nodes.Contains(nextHostNode)) { var newLocation = location.copy(); newLocation.arcs[currentLArcIndex] = HostArc; if (nextLNode == null || nextLNode.NotExist) { FindPositiveStartElementAvoidNegatives(newLocation); } else { checkNodeAvoidNegatives(newLocation, nextLNode, nextHostNode); } } } } }
/// <summary> /// Overrides the object method to check all details of the graphs to see /// if they are identical. It is potentially time-consuming as it makes /// rules and assigns the graphs as the L of the rule, and then performs /// the "recognize" function on the other graph. /// </summary> /// <param name="obj">The other graph to compare to this one.</param> /// <param name="contentsOfGraphAreEqual">if set to <c>true</c> then check that contents of graph are equal even though they occupy different memory.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> public bool Equals(object obj, bool contentsOfGraphAreEqual) { if (Equals(obj)) { return(true); } if (!contentsOfGraphAreEqual) { return(false); } if (!(obj is designGraph)) { return(false); } var g = (designGraph)obj; if (!grammarRule.LabelsMatch(globalLabels, g.globalLabels, null, true)) { return(false); } if (nodes.Count != g.nodes.Count) { return(false); } if (arcs.Count != g.arcs.Count) { return(false); } if (hyperarcs.Count != g.hyperarcs.Count) { return(false); } if (!DegreeSequence.SequenceEqual(g.DegreeSequence)) { return(false); } var thisSecondaryDegree = new List <List <int> >(); var gSecondaryDegree = new List <List <int> >(); for (int i = 0; i < nodes.Count; i++) { var thisDegreelist = new List <int>(); var gDegreelist = new List <int>(); var thisNode = nodes[i]; var gNode = g.nodes[i]; foreach (var a in thisNode.arcs) { if (a is arc) { thisDegreelist.Add(((arc)a).otherNode(thisNode).degree); } } thisDegreelist.Sort(); thisSecondaryDegree.Add(thisDegreelist); foreach (var a in gNode.arcs) { if (a is arc) { gDegreelist.Add(((arc)a).otherNode(gNode).degree); } } gDegreelist.Sort(); gSecondaryDegree.Add(gDegreelist); } foreach (var degreeList in thisSecondaryDegree) { var i = gSecondaryDegree.FindIndex(v => v.SequenceEqual(degreeList)); if (i == -1) { return(false); } else { gSecondaryDegree.RemoveAt(i); } } if (gSecondaryDegree.Any()) { return(false); } var maxDegree = DegreeSequence[0]; var dummyRule = new grammarRule { spanning = true, containsAllGlobalLabels = true, induced = true, L = new designGraph() }; #region put g's nodes, arcs and hyperarcs into the LHS of the rule foreach (var n in g.nodes) { var rn = new ruleNode(n) { containsAllLocalLabels = true, strictDegreeMatch = true }; if (n.degree == maxDegree) { dummyRule.L.nodes.Insert(0, rn); } else { dummyRule.L.nodes.Add(rn); } } foreach (var a in g.arcs) { var ra = new ruleArc(a) { containsAllLocalLabels = true, directionIsEqual = true }; dummyRule.L.arcs.Add(ra); } foreach (var ha in g.hyperarcs) { var rha = new ruleHyperarc(ha) { containsAllLocalLabels = true, strictNodeCountMatch = true }; dummyRule.L.hyperarcs.Add(rha); } dummyRule.L.RepairGraphConnections(); #endregion if (dummyRule.recognize(this).Count < 1) { return(false); } #region put this's nodes, arcs and hyperarcs into the LHS of the rule dummyRule.L = new designGraph(); foreach (var n in this.nodes) { var rn = new ruleNode(n) { containsAllLocalLabels = true, strictDegreeMatch = true }; if (n.degree == maxDegree) { dummyRule.L.nodes.Insert(0, rn); } else { dummyRule.L.nodes.Add(rn); } } foreach (var a in this.arcs) { var ra = new ruleArc(a) { containsAllLocalLabels = true, directionIsEqual = true }; dummyRule.L.arcs.Add(ra); } foreach (var ha in this.hyperarcs) { var rha = new ruleHyperarc(ha) { containsAllLocalLabels = true, strictNodeCountMatch = true }; dummyRule.L.hyperarcs.Add(rha); } dummyRule.L.RepairGraphConnections(); #endregion if (dummyRule.recognize(g).Count < 1) { return(false); } return(true); }
public void addArcsFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Boolean ruleGraph) { Shape fromShape, toShape; arc temparc; foreach (Connection a in graphControl1.Connections) { if (!arcs.Exists(delegate(arc b) { return (b.displayShape == a); })) { if (ruleGraph) temparc = new ruleArc(nameFromText(a.Text)); else temparc = new arc(nameFromText(a.Text)); this.arcs.Add(temparc); } else temparc = arcs.Find(delegate(arc b) { return (b.displayShape == a); }); fromShape = a.From.BelongsTo; toShape = a.To.BelongsTo; temparc.From = nodes.Find(delegate(node c) { return (sameName(c.name, fromShape.Text)); }); temparc.To = nodes.Find(delegate(node c) { return (sameName(c.name, toShape.Text)); }); for (int i = 0; i != fromShape.Connectors.Count; i++) { if (fromShape.Connectors[i] == a.From) temparc.fromConnector = i; } for (int i = 0; i != toShape.Connectors.Count; i++) { if (toShape.Connectors[i] == a.To) temparc.toConnector = i; } if (a.Text != "[Not_set]") { temparc.name = nameFromText(a.Text); temparc.localLabels = labelsFromText(a.Text); } temparc.displayShape = a; temparc.setStyleKeyFromDisplayShape(); } }