Esempio n. 1
0
 public Triangle(Vertex a, Vertex b, Vertex c)
 {
     Verteces.Add(a);
     Verteces.Add(b);
     Verteces.Add(c);
     populated = true;
     //figure out which vertex is top, bottom and opposite (as in opposite the hypotunuse)
     sortVerteces();
 }
Esempio n. 2
0
 public GraphBuilder <TV, TW> AddVertex(Vertex <TV> vertex)
 {
     if (Verteces.ContainsKey(vertex.Value))
     {
         throw new InvalidOperationException($"A vertex with value {vertex.Value} has already been added to this graph.");
     }
     Verteces[vertex.Value] = vertex;
     Edges[vertex.Value]    = new HashSet <Edge <TV, TW> >();
     return(this);
 }
Esempio n. 3
0
 public GraphBuilder <TV, TW> AddEdge(Edge <TV, TW> edge)
 {
     if (Verteces.ContainsKey(edge.OriginVertex.Value) && Verteces.ContainsKey(edge.TargetVertex.Value))
     {
         Edges[edge.OriginVertex.Value].Add(edge);
         if (!Directed)
         {
             Edges[edge.TargetVertex.Value].Add(edge);
         }
     }
     else
     {
         throw new InvalidOperationException($"One or more of the passed verteces are not verteces of this graph.");
     }
     return(this);
 }
Esempio n. 4
0
 private void findVerteces()
 {
     // to get here, we've created a triangle using either a cell address or a row and column
     TopVertex    = new Vertex(((Column / 2) - 1), Row - 1);
     BottomVertex = new Vertex((Column / 2), Row);
     if (TriangleType == TriangleType.Top)
     {
         OppositeVertex = new Vertex((Column / 2), Row - 1);
     }
     else if (TriangleType == TriangleType.Bottom)
     {
         OppositeVertex = new Vertex(((Column / 2) - 1), Row);
     }
     Verteces.Add(TopVertex);
     Verteces.Add(OppositeVertex);
     Verteces.Add(BottomVertex);
 }
Esempio n. 5
0
 public GraphBuilder <TV, TW> AddEdge(TV startingVertexValue, TV targetVertexValue, TW weight = default)
 {
     if (Verteces.ContainsKey(startingVertexValue) && Verteces.ContainsKey(targetVertexValue))
     {
         Edge <TV, TW> newEdge = new Edge <TV, TW>(Verteces[startingVertexValue], Verteces[targetVertexValue], weight);
         Edges[startingVertexValue].Add(newEdge);
         if (!Directed)
         {
             Edges[targetVertexValue].Add(newEdge);
         }
     }
     else
     {
         throw new InvalidOperationException($"One or more of the passed verteces are not verteces of this graph.");
     }
     return(this);
 }
Esempio n. 6
0
 public bool ContainsVertex(IVertex <TV> vertex)
 {
     return(Verteces.Contains(vertex));
 }
Esempio n. 7
0
 public IEnumerable <IVertex <TV> > GetAllMatchingVerteces(Func <IVertex <TV>, bool> filter)
 {
     return(Verteces.Where(filter));
 }
Esempio n. 8
0
 public IVertex <TV> GetFirstMatchingVertex(Func <IVertex <TV>, bool> filter)
 {
     return(Verteces.FirstOrDefault(filter));
 }
Esempio n. 9
0
 public IVertex <TV> GetFirstVertex()
 {
     return(Verteces.FirstOrDefault());
 }