private void Testing(ComplementEnum complementEnum) { try { testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[complementEnum]); reader = new ReaderWriter.ReaderGraph(testPath, false); graph = reader.ReadFile(); stringBuilder.AppendLine(complementEnum.ToString()); stringBuilder.AppendLine("Graph created."); stringBuilder.AppendLine(graph.ToString()); IGraphInterface graphComplement = GraphOperation.ComplementGraph(graph); stringBuilder.AppendLine("Complement graph."); stringBuilder.AppendLine(graphComplement.ToString()); } catch (KeyNotFoundException) { throw new MyException.TestsException.TestsMissingTestException(complementEnum.ToString()); } catch (MyException.ReaderWriterException.ReaderWriterException e) { stringBuilder.AppendLine(e.Message); } }
public static int TestGraph(DirectedGraph graph, Node start, Node target) { Debug.LogFormat("Graph = {0}", graph); Dictionary <Node, Edge> path = GraphOperation.getShortestPathDistances(graph, start, target); if (graph == null || !graph.Contains(start) || !graph.Contains(target)) { Debug.LogFormat("Error param"); return(-1); } if (path == null) { Debug.LogFormat("No solution"); return(-1); } Node currentNode = target; string displayPath = currentNode.ToString(); while (currentNode != start) { Edge edge = path[currentNode]; currentNode = edge.src; displayPath = currentNode + "->" + displayPath; } Debug.LogFormat(displayPath + " : " + path[target].weight); return(path[target].weight); }
private void Testing(SubGraphEnum subGraphEnum) { try { testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[subGraphEnum].Item1); countVertices = testsDictionary[subGraphEnum].Item2; reader = new ReaderWriter.ReaderGraph(testPath, false); graph = reader.ReadFile(); stringBuilder.AppendLine(subGraphEnum.ToString()); stringBuilder.AppendLine("Graph created."); stringBuilder.AppendLine(graph.ToString()); IGraphInterface subGraph = GraphOperation.SubGraph(graph, graph.AllVertices().Take(countVertices).ToList()); stringBuilder.AppendLine("Subgraph created."); stringBuilder.AppendLine(subGraph.ToString()); } catch (KeyNotFoundException) { throw new MyException.TestsException.TestsMissingTestException(subGraphEnum.ToString()); } catch (MyException.ReaderWriterException.ReaderWriterException e) { stringBuilder.AppendLine(e.Message); } }
/// <summary> /// Ensures that the root operation type (query, mutation etc.) exists on this schema and the associated virtual /// type representing it also exists in the schema's type collection. /// </summary> /// <param name="operationType">Type of the operation.</param> private void EnsureGraphOperationType(GraphCollection operationType) { if (!this.Schema.OperationTypes.ContainsKey(operationType)) { var name = _formatter.FormatGraphTypeName(operationType.ToString()); var operation = new GraphOperation(operationType, name); this.Schema.KnownTypes.EnsureGraphType(operation); this.Schema.OperationTypes.Add(operation.OperationType, operation); } }
public void Open(GraphOperation operation) { if (operation == null) { return; } RebuildEntries(); CurrentOperation = operation; gameObject.SetActive(true); }
private void checkIsomorphismButton_Click(object sender, RoutedEventArgs e) { if (graphController_1.Graph != null && graphController_2.Graph != null) { bool result = GraphOperation.IsBijective(graphController_1.Graph, graphController_2.Graph, 0, new bool[graphController_2.Graph.VerticesCount], new List <int>()); string message = ""; if (result) { message = "Grafy są izomorficzne!"; } else { message = "Niestety grafy nie są izomorficzne"; } MessageBox.Show(message, "Wynik", MessageBoxButton.OK, MessageBoxImage.Asterisk); } }
private void OnGraphUpdate(GraphOperation operation, object obj) { switch (operation) { case GraphOperation.AddNode: break; case GraphOperation.AddEdge: var edge = (IEdge)obj; var nodeComparer = Comparer <INode> .Create((x, y) => x.Number.CompareTo(y.Number)); var edgeComparer = Comparer <IEdge> .Create((x, y) => { var result = nodeComparer.Compare(x.First, y.First); if (result == 0) { return(nodeComparer.Compare(x.Second, y.Second)); } return(result); }); var i = 0; for (; i < cbEdgeSizeChange.Items.Count; i++) { var fromCb = (IEdge)cbEdgeSizeChange.Items[i]; if (edgeComparer.Compare(edge, fromCb) < 0) { break; } } cbEdgeSizeChange.Items.Insert(i, obj); break; case GraphOperation.DeleteNode: break; case GraphOperation.DeleteEdge: cbEdgeSizeChange.Items.Remove(obj); break; } }
public void OnClose() { gameObject.SetActive(false); CurrentOperation = null; GraphInput.text = ""; }
public void GraphFromMap() { List <Node> nodes = new List <Node>(); List <Edge> edges = new List <Edge>(); for (int y = 0; y < labSize; ++y) { for (int x = 0; x < labSize; ++x) { int currentPos = GetTileIndexFromCoordinates(new Vector2Int(x, y)); nodes.Add(new Node(currentPos.ToString())); Tile currentTile = labyrinthTiles[currentPos]; if (x > 0) { int leftPos = currentPos - 1; Tile leftTile = labyrinthTiles[leftPos]; if (currentTile.left && leftTile.right) { //Directed graph, bilateral with 2 differents difficulty depending on the target tile (number of skull) int difficulty = labyrinthSkulls[leftPos].difficulty; edges.Add(new Edge(nodes[currentPos], nodes[leftPos], difficulty)); difficulty = labyrinthSkulls[currentPos].difficulty; edges.Add(new Edge(nodes[leftPos], nodes[currentPos], difficulty)); } } if (y > 0) { int downPos = currentPos - labSize; Tile downTile = labyrinthTiles[downPos]; if (currentTile.down && downTile.up) { int difficulty = labyrinthSkulls[downPos].difficulty; edges.Add(new Edge(nodes[currentPos], nodes[downPos], difficulty)); difficulty = labyrinthSkulls[currentPos].difficulty; edges.Add(new Edge(nodes[downPos], nodes[currentPos], difficulty)); } } } } Node start = nodes[enemy.pos]; Node target = nodes[player.pos]; //Setting graph and calculing shortest path graph = new DirectedGraph(nodes, edges, true); Stack <Node> path = new Stack <Node>(); GraphOperation.getShortestPath(graph, start, target, out path); //Calculing path for charcter and tracing it List <Vector3> vectorPath = new List <Vector3>(); int pathCountMax = path.Count; while (path.Count != 0) { Node node = path.Pop(); int nodeInt = -1; if (System.Int32.TryParse(node.label, out nodeInt)) { vectorPath.Add(GetTilePosFromIndex(nodeInt)); if (path.Count == pathCountMax - 2) { //Next move if more than 2 nodes enemyNextPos = nodeInt; enemyNextDifficulty = labyrinthSkulls[nodeInt].difficulty; } } } trace.SetPath(vectorPath); }
protected virtual void OnChanged(GraphOperation operation, object obj) { Changed?.Invoke(operation, obj); }
internal ArangoGraphOperation(GraphOperation graphOperation) { _graphOperation = graphOperation; }
/// <summary> /// Creates a node that subtracts each input from 1 (1-x) /// </summary> /// <param name="name">Optional name to give the node</param> /// <returns></returns> public INode CreateOneMinusInput(string name = null) { return(GraphOperation.OneMinusInput(name)); }