/// <summary> /// Returns a random simple digraph containing <tt>V</tt> vertices and <tt>E</tt> edges. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of vertices</param> /// <returns>a random simple digraph on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple digraph exists</exception> public static Digraph Simple(int v, int e) { if (e > (long)v * (v - 1)) { throw new ArgumentException("Too many edges"); } if (e < 0) { throw new ArgumentException("Too few edges"); } var g = new Digraph(v); var set = new SET <EdgeD>(); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if ((ve != we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(ve, we); } } return(g); }
/// <summary> /// Returns a random simple graph containing <tt>V</tt> vertices and <tt>E</tt> edges. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <returns> random simple graph on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple graph exists</exception> public static Graph Simple(int v, int e) { if (e > (long)v * (v - 1) / 2) { throw new ArgumentException("Too many edges"); } if (e < 0) { throw new ArgumentException("Too few edges"); } var g = new Graph(v); var set = new SET <EdgeU>(); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeU(ve, we); if ((ve == we) || set.Contains(edge)) { continue; } set.Add(edge); g.AddEdge(ve, we); } return(g); }
/// <summary> /// Returns a random simple DAG containing <tt>V</tt> vertices and <tt>E</tt> edges. /// Note: it is not uniformly selected at random among all such DAGs. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of vertices</param> /// <returns>a random simple DAG on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple DAG exists</exception> public static Digraph Dag(int v, int e) { if (e > (long)v * (v - 1) / 2) { throw new ArgumentException("Too many edges"); } if (e < 0) { throw new ArgumentException("Too few edges"); } var g = new Digraph(v); var set = new SET <EdgeD>(); var vertices = new int[v]; for (var i = 0; i < v; i++) { vertices[i] = i; } StdRandom.Shuffle(vertices); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if ((ve < we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(vertices[ve], vertices[we]); } } return(g); }
/// <summary> /// Returns a random rooted-out DAG on <tt>V</tt> vertices and <tt>E</tt> edges. /// A rooted out-tree is a DAG in which every vertex is reachable from a /// single vertex. /// The DAG returned is not chosen uniformly at random among all such DAGs. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <returns>a random rooted-out DAG on <tt>V</tt> vertices and <tt>E</tt> edges</returns> public static Digraph RootedOutDag(int v, int e) { if (e > (long)v * (v - 1) / 2) { throw new ArgumentException("Too many edges"); } if (e < v - 1) { throw new ArgumentException("Too few edges"); } var g = new Digraph(v); var set = new SET <EdgeD>(); // fix a topological order var vertices = new int[v]; for (var i = 0; i < v; i++) { vertices[i] = i; } StdRandom.Shuffle(vertices); // one edge pointing from each vertex, other than the root = vertices[V-1] for (var ve = 0; ve < v - 1; ve++) { var we = StdRandom.Uniform(ve + 1, v); var edge = new EdgeD(we, ve); set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(we, ve); if ((ve < we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } } return(g); }
/// <summary> /// Returns a random simple bipartite graph on <tt>V1</tt> and <tt>V2</tt> vertices /// with <tt>E</tt> edges. /// </summary> /// <param name="v1">V1 the number of vertices in one partition</param> /// <param name="v2">V2 the number of vertices in the other partition</param> /// <param name="e">E the number of edges</param> /// <returns>a random simple bipartite graph on <tt>V1</tt> and <tt>V2</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple bipartite graph exists</exception> public static Graph Bipartite(int v1, int v2, int e) { if (e > (long)v1 * v2) throw new ArgumentException("Too many edges"); if (e < 0) throw new ArgumentException("Too few edges"); var g = new Graph(v1 + v2); var vertices = new int[v1 + v2]; for (var i = 0; i < v1 + v2; i++) vertices[i] = i; StdRandom.Shuffle(vertices); var set = new SET<EdgeU>(); while (g.E < e) { var i = StdRandom.Uniform(v1); var j = v1 + StdRandom.Uniform(v2); var edge = new EdgeU(vertices[i], vertices[j]); if (set.Contains(edge)) continue; set.Add(edge); g.AddEdge(vertices[i], vertices[j]); } return g; }
/// <summary> /// Returns a random simple bipartite graph on <tt>V1</tt> and <tt>V2</tt> vertices /// with <tt>E</tt> edges. /// </summary> /// <param name="v1">V1 the number of vertices in one partition</param> /// <param name="v2">V2 the number of vertices in the other partition</param> /// <param name="e">E the number of edges</param> /// <returns>a random simple bipartite graph on <tt>V1</tt> and <tt>V2</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple bipartite graph exists</exception> public static Graph Bipartite(int v1, int v2, int e) { if (e > (long)v1 * v2) { throw new ArgumentException("Too many edges"); } if (e < 0) { throw new ArgumentException("Too few edges"); } var g = new Graph(v1 + v2); var vertices = new int[v1 + v2]; for (var i = 0; i < v1 + v2; i++) { vertices[i] = i; } StdRandom.Shuffle(vertices); var set = new SET <EdgeU>(); while (g.E < e) { var i = StdRandom.Uniform(v1); var j = v1 + StdRandom.Uniform(v2); var edge = new EdgeU(vertices[i], vertices[j]); if (set.Contains(edge)) { continue; } set.Add(edge); g.AddEdge(vertices[i], vertices[j]); } return(g); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinySET.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinySET.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Searching\\{fieName}"); var keys = @in.ReadAllLines(); //var list = words.Select(word => new StringComparable(word)).ToList(); //var listComparable = list.Cast<IComparable>().ToList(); //var arrayComparable = list.Cast<IComparable>().ToArray(); //var listStrings = words.ToList(); var set = new SET<string>(); foreach (var key in keys) { set.Add(key); } // print results foreach (var item in set) { Console.WriteLine(item); } Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Contains("www.cs.princeton.edu")); Console.WriteLine(!set.Contains("www.harvardsucks.com")); Console.WriteLine(set.Contains("www.simpsons.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("ceiling(www.simpsonr.com) = " + set.Ceiling("www.simpsonr.com")); Console.WriteLine("ceiling(www.simpsons.com) = " + set.Ceiling("www.simpsons.com")); Console.WriteLine("ceiling(www.simpsont.com) = " + set.Ceiling("www.simpsont.com")); Console.WriteLine("floor(www.simpsonr.com) = " + set.Floor("www.simpsonr.com")); Console.WriteLine("floor(www.simpsons.com) = " + set.Floor("www.simpsons.com")); Console.WriteLine("floor(www.simpsont.com) = " + set.Floor("www.simpsont.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Max()); Console.WriteLine(set.Min()); Console.WriteLine(); Console.ReadLine(); }
public void Run() { Console.WriteLine("Choose file:"); // Prompt Console.WriteLine("1 - tinySET.txt"); // Prompt Console.WriteLine("or quit"); // Prompt var fileNumber = Console.ReadLine(); var fieName = string.Empty; switch (fileNumber) { case "1": fieName = "tinySET.txt"; break; case "quit": return; default: return; } var @in = new In($"Files\\Searching\\{fieName}"); var keys = @in.ReadAllLines(); //var list = words.Select(word => new StringComparable(word)).ToList(); //var listComparable = list.Cast<IComparable>().ToList(); //var arrayComparable = list.Cast<IComparable>().ToArray(); //var listStrings = words.ToList(); var set = new SET <string>(); foreach (var key in keys) { set.Add(key); } // print results foreach (var item in set) { Console.WriteLine(item); } Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Contains("www.cs.princeton.edu")); Console.WriteLine(!set.Contains("www.harvardsucks.com")); Console.WriteLine(set.Contains("www.simpsons.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine("ceiling(www.simpsonr.com) = " + set.Ceiling("www.simpsonr.com")); Console.WriteLine("ceiling(www.simpsons.com) = " + set.Ceiling("www.simpsons.com")); Console.WriteLine("ceiling(www.simpsont.com) = " + set.Ceiling("www.simpsont.com")); Console.WriteLine("floor(www.simpsonr.com) = " + set.Floor("www.simpsonr.com")); Console.WriteLine("floor(www.simpsons.com) = " + set.Floor("www.simpsons.com")); Console.WriteLine("floor(www.simpsont.com) = " + set.Floor("www.simpsont.com")); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(set.Max()); Console.WriteLine(set.Min()); Console.WriteLine(); Console.ReadLine(); }
/// <summary> /// Returns a random simple DAG containing <tt>V</tt> vertices and <tt>E</tt> edges. /// Note: it is not uniformly selected at random among all such DAGs. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of vertices</param> /// <returns>a random simple DAG on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple DAG exists</exception> public static Digraph Dag(int v, int e) { if (e > (long)v * (v - 1) / 2) throw new ArgumentException("Too many edges"); if (e < 0) throw new ArgumentException("Too few edges"); var g = new Digraph(v); var set = new SET<EdgeD>(); var vertices = new int[v]; for (var i = 0; i < v; i++) vertices[i] = i; StdRandom.Shuffle(vertices); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if ((ve < we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(vertices[ve], vertices[we]); } } return g; }
/// <summary> /// Returns a random simple digraph on <tt>V</tt> vertices, <tt>E</tt> /// edges and (at least) <tt>c</tt> strong components. The vertices are randomly /// assigned integer labels between <tt>0</tt> and <tt>c-1</tt> (corresponding to /// strong components). Then, a strong component is creates among the vertices /// with the same label. Next, random edges (either between two vertices with /// the same labels or from a vetex with a smaller label to a vertex with a /// larger label). The number of components will be equal to the number of /// distinct labels that are assigned to vertices. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <param name="c">c the (maximum) number of strong components</param> /// <returns>a random simple digraph on <tt>V</tt> vertices and <tt>E</tt> edges, with (at most) <tt>c</tt> strong components</returns> /// <exception cref="ArgumentException">if <tt>c</tt> is larger than <tt>V</tt></exception> public static Digraph Strong(int v, int e, int c) { if (c >= v || c <= 0) throw new ArgumentException("Number of components must be between 1 and V"); if (e <= 2 * (v - c)) throw new ArgumentException("Number of edges must be at least 2(V-c)"); if (e > (long)v * (v - 1) / 2) throw new ArgumentException("Too many edges"); // the digraph var g = new Digraph(v); // edges added to G (to avoid duplicate edges) var set = new SET<EdgeD>(); var label = new int[v]; for (var i = 0; i < v; i++) label[i] = StdRandom.Uniform(c); // make all vertices with label c a strong component by // combining a rooted in-tree and a rooted out-tree for (var i = 0; i < c; i++) { // how many vertices in component c var count = 0; for (var ii = 0; ii < g.V; ii++) { if (label[ii] == i) count++; } // if (count == 0) System.err.println("less than desired number of strong components"); var vertices = new int[count]; var j = 0; for (var jj = 0; jj < v; jj++) { if (label[jj] == i) vertices[j++] = jj; } StdRandom.Shuffle(vertices); // rooted-in tree with root = vertices[count-1] for (var ve = 0; ve < count - 1; ve++) { var we = StdRandom.Uniform(ve + 1, count); var edge = new EdgeD(we, ve); set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } // rooted-out tree with root = vertices[count-1] for (var ve = 0; ve < count - 1; ve++) { var we = StdRandom.Uniform(ve + 1, count); var edge = new EdgeD(ve, we); set.Add(edge); g.AddEdge(vertices[ve], vertices[we]); } } while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if (!set.Contains(edge) && ve != we && label[ve] <= label[we]) { set.Add(edge); g.AddEdge(ve, we); } } return g; }
/// <summary> /// Returns a random simple digraph containing <tt>V</tt> vertices and <tt>E</tt> edges. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of vertices</param> /// <returns>a random simple digraph on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple digraph exists</exception> public static Digraph Simple(int v, int e) { if (e > (long)v * (v - 1)) throw new ArgumentException("Too many edges"); if (e < 0) throw new ArgumentException("Too few edges"); var g = new Digraph(v); var set = new SET<EdgeD>(); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if ((ve != we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(ve, we); } } return g; }
/// <summary> /// Returns a random rooted-out DAG on <tt>V</tt> vertices and <tt>E</tt> edges. /// A rooted out-tree is a DAG in which every vertex is reachable from a /// single vertex. /// The DAG returned is not chosen uniformly at random among all such DAGs. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <returns>a random rooted-out DAG on <tt>V</tt> vertices and <tt>E</tt> edges</returns> public static Digraph RootedOutDag(int v, int e) { if (e > (long)v * (v - 1) / 2) throw new ArgumentException("Too many edges"); if (e < v - 1) throw new ArgumentException("Too few edges"); var g = new Digraph(v); var set = new SET<EdgeD>(); // fix a topological order var vertices = new int[v]; for (var i = 0; i < v; i++) vertices[i] = i; StdRandom.Shuffle(vertices); // one edge pointing from each vertex, other than the root = vertices[V-1] for (var ve = 0; ve < v - 1; ve++) { var we = StdRandom.Uniform(ve + 1, v); var edge = new EdgeD(we, ve); set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(we, ve); if ((ve < we) && !set.Contains(edge)) { set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } } return g; }
/// <summary> /// Returns a random simple graph containing <tt>V</tt> vertices and <tt>E</tt> edges. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <returns> random simple graph on <tt>V</tt> vertices, containing a total of <tt>E</tt> edges</returns> /// <exception cref="ArgumentException">if no such simple graph exists</exception> public static Graph Simple(int v, int e) { if (e > (long)v * (v - 1) / 2) throw new ArgumentException("Too many edges"); if (e < 0) throw new ArgumentException("Too few edges"); var g = new Graph(v); var set = new SET<EdgeU>(); while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeU(ve, we); if ((ve == we) || set.Contains(edge)) continue; set.Add(edge); g.AddEdge(ve, we); } return g; }
/// <summary> /// Graph <paramref name="o"/> onto <paramref name="s"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // XP is special, it does not extend anything so we have to graph from scratch var instance = o as ENXP; // Null flavor? if (instance.NullFlavor != null) { s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor)); } else { // Validate DatatypeR2FormatterParseResult tResult = new DatatypeR2FormatterParseResult(result.ValidateConformance); new ANYFormatter().Validate(instance, s.ToString(), tResult); result.AddResultDetail(tResult.Details); // Qualifiers (copy for modification) SET <CS <EntityNamePartQualifier> > qualifiers = new SET <CS <EntityNamePartQualifier> >(); if (instance.Qualifier != null) { foreach (var qlf in instance.Qualifier) { qualifiers.Add(qlf.Clone() as CS <EntityNamePartQualifier>); } } // Unsupported properties if (instance.ControlActExt != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ENXP", s.ToString())); } if (instance.ControlActRoot != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ENXP", s.ToString())); } if (instance.ValidTimeHigh != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ENXP", s.ToString())); } if (instance.ValidTimeLow != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ENXP", s.ToString())); } if (instance.Flavor != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ENXP", s.ToString())); } if (instance.UpdateMode != null) { result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ENXP", s.ToString())); } // Output the supported properties if (instance.Value != null) { s.WriteAttributeString("value", instance.Value); } if (instance.Code != null) { s.WriteAttributeString("code", instance.Code); } if (instance.CodeSystem != null) { s.WriteAttributeString("codeSystem", instance.CodeSystem); } if (instance.CodeSystemVersion != null) { s.WriteAttributeString("codeSystemVersion", instance.CodeSystemVersion); } if (instance.Type != null) { // Qualifiers that count as TITLE EntityNamePartQualifier[] titleQualifiers = new EntityNamePartQualifier[] { EntityNamePartQualifier.Professional, EntityNamePartQualifier.Nobility, EntityNamePartQualifier.Academic, EntityNamePartQualifier.LegalStatus }; // If type is not SFX or PFX then output the type, // if it is either SFX or PFX then don't output the type // but do modify the qualifier switch (instance.Type.Value) { case EntityNamePartType.Prefix: if (instance.Qualifier == null) { instance.Qualifier = new SET <CS <EntityNamePartQualifier> >(); } if (!qualifiers.Contains(EntityNamePartQualifier.Prefix)) { qualifiers.Add(EntityNamePartQualifier.Prefix); } // Change the instance type if (Array.Exists(titleQualifiers, q => qualifiers.Contains(q))) { s.WriteAttributeString("type", "TITLE"); } break; case EntityNamePartType.Suffix: if (instance.Qualifier == null) { instance.Qualifier = new SET <CS <EntityNamePartQualifier> >(); } if (!qualifiers.Contains(EntityNamePartQualifier.Suffix)) { qualifiers.Add(EntityNamePartQualifier.Suffix); } // Change the instance type if (Array.Exists(titleQualifiers, q => qualifiers.Contains(q))) { s.WriteAttributeString("type", "TITLE"); } break; default: s.WriteAttributeString("type", Util.ToWireFormat(instance.Type)); break; } } if (!qualifiers.IsEmpty) { s.WriteAttributeString("qualifier", Util.ToWireFormat(qualifiers)); } } }
/// <summary> /// Returns a random simple digraph on <tt>V</tt> vertices, <tt>E</tt> /// edges and (at least) <tt>c</tt> strong components. The vertices are randomly /// assigned integer labels between <tt>0</tt> and <tt>c-1</tt> (corresponding to /// strong components). Then, a strong component is creates among the vertices /// with the same label. Next, random edges (either between two vertices with /// the same labels or from a vetex with a smaller label to a vertex with a /// larger label). The number of components will be equal to the number of /// distinct labels that are assigned to vertices. /// </summary> /// <param name="v">V the number of vertices</param> /// <param name="e">E the number of edges</param> /// <param name="c">c the (maximum) number of strong components</param> /// <returns>a random simple digraph on <tt>V</tt> vertices and <tt>E</tt> edges, with (at most) <tt>c</tt> strong components</returns> /// <exception cref="ArgumentException">if <tt>c</tt> is larger than <tt>V</tt></exception> public static Digraph Strong(int v, int e, int c) { if (c >= v || c <= 0) { throw new ArgumentException("Number of components must be between 1 and V"); } if (e <= 2 * (v - c)) { throw new ArgumentException("Number of edges must be at least 2(V-c)"); } if (e > (long)v * (v - 1) / 2) { throw new ArgumentException("Too many edges"); } // the digraph var g = new Digraph(v); // edges added to G (to avoid duplicate edges) var set = new SET <EdgeD>(); var label = new int[v]; for (var i = 0; i < v; i++) { label[i] = StdRandom.Uniform(c); } // make all vertices with label c a strong component by // combining a rooted in-tree and a rooted out-tree for (var i = 0; i < c; i++) { // how many vertices in component c var count = 0; for (var ii = 0; ii < g.V; ii++) { if (label[ii] == i) { count++; } } // if (count == 0) System.err.println("less than desired number of strong components"); var vertices = new int[count]; var j = 0; for (var jj = 0; jj < v; jj++) { if (label[jj] == i) { vertices[j++] = jj; } } StdRandom.Shuffle(vertices); // rooted-in tree with root = vertices[count-1] for (var ve = 0; ve < count - 1; ve++) { var we = StdRandom.Uniform(ve + 1, count); var edge = new EdgeD(we, ve); set.Add(edge); g.AddEdge(vertices[we], vertices[ve]); } // rooted-out tree with root = vertices[count-1] for (var ve = 0; ve < count - 1; ve++) { var we = StdRandom.Uniform(ve + 1, count); var edge = new EdgeD(ve, we); set.Add(edge); g.AddEdge(vertices[ve], vertices[we]); } } while (g.E < e) { var ve = StdRandom.Uniform(v); var we = StdRandom.Uniform(v); var edge = new EdgeD(ve, we); if (!set.Contains(edge) && ve != we && label[ve] <= label[we]) { set.Add(edge); g.AddEdge(ve, we); } } return(g); }
/// <summary> /// Graph <paramref name="o"/> onto <paramref name="s"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // XP is special, it does not extend anything so we have to graph from scratch var instance = o as ENXP; // Null flavor? if (instance.NullFlavor != null) s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor)); else { // Validate DatatypeR2FormatterParseResult tResult = new DatatypeR2FormatterParseResult(result.ValidateConformance); new ANYFormatter().Validate(instance, s.ToString(), tResult); result.AddResultDetail(tResult.Details); // Qualifiers (copy for modification) SET<CS<EntityNamePartQualifier>> qualifiers = new SET<CS<EntityNamePartQualifier>>(); if(instance.Qualifier != null) foreach (var qlf in instance.Qualifier) qualifiers.Add(qlf.Clone() as CS<EntityNamePartQualifier>); // Unsupported properties if (instance.ControlActExt != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ENXP", s.ToString())); if (instance.ControlActRoot != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ENXP", s.ToString())); if (instance.ValidTimeHigh != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ENXP", s.ToString())); if (instance.ValidTimeLow != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ENXP", s.ToString())); if (instance.Flavor != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ENXP", s.ToString())); if (instance.UpdateMode != null) result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ENXP", s.ToString())); // Output the supported properties if (instance.Value != null) s.WriteAttributeString("value", instance.Value); if (instance.Code != null) s.WriteAttributeString("code", instance.Code); if (instance.CodeSystem != null) s.WriteAttributeString("codeSystem", instance.CodeSystem); if (instance.CodeSystemVersion != null) s.WriteAttributeString("codeSystemVersion", instance.CodeSystemVersion); if (instance.Type != null) { // Qualifiers that count as TITLE EntityNamePartQualifier[] titleQualifiers = new EntityNamePartQualifier[] { EntityNamePartQualifier.Professional, EntityNamePartQualifier.Nobility, EntityNamePartQualifier.Academic , EntityNamePartQualifier.LegalStatus }; // If type is not SFX or PFX then output the type, // if it is either SFX or PFX then don't output the type // but do modify the qualifier switch(instance.Type.Value) { case EntityNamePartType.Prefix: if (instance.Qualifier == null) instance.Qualifier = new SET<CS<EntityNamePartQualifier>>(); if(!qualifiers.Contains(EntityNamePartQualifier.Prefix)) qualifiers.Add(EntityNamePartQualifier.Prefix); // Change the instance type if(Array.Exists(titleQualifiers, q => qualifiers.Contains(q))) s.WriteAttributeString("type", "TITLE"); break; case EntityNamePartType.Suffix: if (instance.Qualifier == null) instance.Qualifier = new SET<CS<EntityNamePartQualifier>>(); if (!qualifiers.Contains(EntityNamePartQualifier.Suffix)) qualifiers.Add(EntityNamePartQualifier.Suffix); // Change the instance type if (Array.Exists(titleQualifiers, q => qualifiers.Contains(q))) s.WriteAttributeString("type", "TITLE"); break; default: s.WriteAttributeString("type", Util.ToWireFormat(instance.Type)); break; } } if (!qualifiers.IsEmpty) s.WriteAttributeString("qualifier", Util.ToWireFormat(qualifiers)); } }