private bool IsAdjacent(BaseGraph<int> graph, int first, int second) { var firstVertex = graph.Verticies.First(x => x.Value == first); var secondVertex = graph.Verticies.First(x => x.Value == second); return firstVertex.AdjacentVerteces.Any(x => x == secondVertex); }
protected override void InitializeWindow(BaseGraph graph) { titleContent = new GUIContent("Context Menu Graph"); var graphView = new CustomContextMenuGraphView(this); rootView.Add(graphView); graphView.Add(new MiniMapView(graphView)); }
/// <inheritdoc /> public bool ContainsVertex(TVertex vertex) { if (vertex == null) { throw new ArgumentNullException(nameof(vertex)); } return(VertexPredicate(vertex) && BaseGraph.ContainsVertex(vertex)); }
/// <summary> /// Finds communities in a graph using the Girvan–Newman method. /// </summary> /// <param name="graph"></param> /// <returns>Yields tuples of sets of nodes in G. Each set of nodes is a community, each tuple is a sequence of communities at a particular level of the algorithm.</returns> /// <note>The Girvan–Newman algorithm detects communities by progressively /// removing edges from the original graph.The algorithm removes the /// "most valuable" edge, traditionally the edge with the highest /// betweenness centrality, at each step.As the graph breaks down into /// pieces, the tightly knit community structure is exposed and the /// result can be depicted as a dendrogram.</note> public IEnumerable <Tuple <HashSet <int>, HashSet <int> > > GirwanNewman(BaseGraph graph) { throw new NotImplementedException("Function not implemented"); if (graph.NumberOfEdges == 0) { //yield return new Tuple<HashSet<int>>(new Component().ConnectedComponents(graph))); yield break; } }
public MixtureGraphProcessor(BaseGraph graph) : base(graph) { processorInstances.TryGetValue(graph as MixtureGraph, out var hashset); if (hashset == null) { hashset = processorInstances[graph as MixtureGraph] = new HashSet <MixtureGraphProcessor>(); } hashset.Add(this); }
protected override void InitializeWindow(BaseGraph graph) { titleContent = new GUIContent("All Graph"); var graphView = new AllGraphView(this); rootView.Add(graphView); graphView.Add(new CustomToolbarView(graphView)); }
protected override void AddButtons() { AddButton(new GUIContent("", m_CreateNewToggleIcon, "新建Graph资产"), () => { GenericMenu genericMenu = new GenericMenu(); foreach (var graphType in TypeCache.GetTypesDerivedFrom <BaseGraph>()) { genericMenu.AddItem(new GUIContent($"{graphType.Name}"), false, data => { BaseGraph baseGraph = GraphCreateAndSaveHelper.CreateGraph(data as System.Type); GraphAssetCallbacks.InitializeGraph(baseGraph); }, graphType); } genericMenu.ShowAsContext(); }, true); //AddSeparator(5); AddToggle(new GUIContent("", m_ExposedParamsToggleIcon, "开/关参数面板"), graphView.GetPinnedElementStatus <ExposedParameterView>() != DropdownMenuAction.Status.Hidden, (v) => graphView.ToggleView <ExposedParameterView>()); //AddSeparator(5); AddToggle(new GUIContent("", m_MiniMapToggleIcon, "开/关小地图"), m_MiniMap.visible, (v) => m_MiniMap.visible = v); //AddSeparator(5); AddToggle(new GUIContent(m_ConditionalToggleIcon, "开/关运行的面板"), graphView.GetPinnedElementStatus <ConditionalProcessorView>() != DropdownMenuAction.Status.Hidden, (v) => graphView.ToggleView <ConditionalProcessorView>()); AddButton(new GUIContent("", m_GotoFileButtonIcon, "定位至资产文件"), () => { EditorGUIUtility.PingObject(graphView.graph); Selection.activeObject = graphView.graph; }); AddSeparator(5); AddCustom(() => { GUI.color = new Color(128 / 255f, 128 / 255f, 128 / 255f); GUILayout.Label(m_BaseGraph.GetType().Name, EditorGUIStyleHelper.GetGUIStyleByName(nameof(EditorStyles.toolbarButton))); GUI.color = Color.white; }); AddButton(new GUIContent("Reload", "主动重载界面"), () => { (this.m_BaseGraphView as UniversalGraphView)?.universalGraphWindow.RefreshWindow(); }, false); }
protected override void InitializeWindow(BaseGraph graph) { titleContent = new GUIContent("Properties Graph"); if (graphView == null) { graphView = new ExposedPropertiesGraphView(this); } rootView.Add(graphView); }
/// <summary> /// Compute the average clustering coefficient for the graph G. The clustering coefficient for the graph is the average. /// </summary> /// <param name="graph">BaseGraph graph.</param> /// <param name="nodes">List of nodes.</param> /// <param name="countZeros">If False include only the nodes with nonzero clustering in the average.</param> /// <returns>Double: Avergae clustering.</returns> public double AverageClustering(BaseGraph graph, List <int> nodes = null, bool countZeros = true) { Dictionary <int, double> c = ClusteringCoefficient(graph, nodes); List <double> cValues = c.Values.ToList <double>(); if (!countZeros) { cValues = cValues.Where(i => i != 0).ToList(); } return((double)cValues.Sum() / (double)cValues.Count); }
protected override void InitializeWindow(BaseGraph graph) { titleContent = new GUIContent("Default Graph"); if (graphView == null) { graphView = new BaseGraphView(this); } rootView.Add(graphView); }
/// <summary> /// returns netwrok distances for undirected graph /// <param name="graph"></param> /// <returns>Returns a list of distances.</returns> private static List <List <short?> > NetworkDistances(BaseGraph graph) { List <List <short?> > distances = new List <List <short?> >(); foreach (int node in graph.Nodes) { distances.Add(UndirectedDistances(graph, node)); } return(distances); }
public override List <Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) { var compatiblePorts = new List <Port>(); PortView startPortView = startPort as PortView; compatiblePorts.AddRange(ports.ToList().Where(p => { var portView = p as PortView; if (p.direction == startPort.direction) { return(false); } //Check if there is custom adapters for this assignation if (CustomPortIO.IsAssignable(startPort.portType, p.portType)) { return(true); } // Allow connection between RenderTexture and all texture types: Type startType = startPortView.portData.displayType ?? startPortView.portType; Type endType = portView.portData.displayType ?? portView.portType; if (startType == typeof(RenderTexture)) { if (endType.IsSubclassOf(typeof(Texture))) { return(true); } } if (endType == typeof(RenderTexture)) { if (startType.IsSubclassOf(typeof(Texture))) { return(true); } } //Check for type assignability if (!BaseGraph.TypesAreConnectable(startPort.portType, p.portType)) { return(false); } //Check if the edge already exists if (portView.GetEdges().Any(e => e.input == startPort || e.output == startPort)) { return(false); } return(true); })); return(compatiblePorts); }
protected override void Initialize(BaseGraph graph) { titleContent = new GUIContent("Custom Toolbar Graph"); var graphView = new ProceduralTextureGraphView(); rootView.Add(graphView); graphView.Add(new ProceduralTextureToolbarView(graphView)); graphView.Add(new MiniMapView(graphView)); }
/// <summary> /// Test directed graph for weak connectivity. /// A directed graph is weakly connected if and only if the graph is connected when the direction of the edge between nodes is ignored. /// Note that if a graph is strongly connected, it is by definition weakly connected as well. /// </summary> /// <param name="graph">BaseGraph graph.</param> /// <returns>True if the graph is weakly connected, False otherwise.</returns> public Boolean IsWeaklyConnected(BaseGraph graph) { if (graph.Nodes.Count == 0) { throw new NotImplementedException("Connectivity is undefined for the null graph."); } List <HashSet <int> > components = WeaklyConnectedComponents(graph).ToList <HashSet <int> >(); return(components[0].Count == graph.Nodes.Count); }
public JsonResult Delete(int id = 0) { BaseGraph model = db.BaseGraphs.Find(id); if (model != null) { db.BaseGraphs.Remove(model); db.SaveChanges(); } return(Json("ok", JsonRequestBehavior.AllowGet)); }
//[IsCompatibleWithGraph] public static bool Create(BaseGraph assetGraph) { var uniGraph = assetGraph as UniAssetGraph; if (!uniGraph) { return(false); } uniGraph.CreateNode(typeof(PointNode), Vector2.zero); return(true); }
public static Node SerializeToTree(BaseGraph graph) { List <Tree_RootNode> rootNodes = NodeHelper.GetNodes <Tree_RootNode>(graph); if (rootNodes.Count <= 0) { Debug.LogError($"试图序列化出错,没有根节点"); } Node rootNode = rootNodes[0].GetRuntimeNode(); return(rootNode); }
/// <summary> /// The DFS1 /// </summary> /// <param name="visited">The visited<see cref="bool[]"/></param> /// <param name="orderStack">The orderStack<see cref="Stack{int}"/></param> /// <param name="v">The v<see cref="int"/></param> /// <param name="baseGraph">The baseGraph<see cref="BaseGraph"/></param> private void DFS1(bool[] visited, Stack <int> orderStack, int v, BaseGraph baseGraph) { visited[v] = true; foreach (Edge edge in baseGraph.GetEdges(v)) { if (!visited[edge.To]) { DFS1(visited, orderStack, edge.To, baseGraph); } } orderStack.Push(v); }
/// <summary> /// Returns True if the graph is connected, false otherwise. /// </summary> /// <param name="graph"></param> /// <returns>True if the graph is connected, false otherwise.</returns> /// <raises>GraphLibraryNotImplemented: – If graph is directed.</raises> /// <note>For undirected graphs only</note> public Boolean IsConnected(BaseGraph graph) { if (graph.Edges.Count == 0) { throw new NotImplementedException("Connectivity is undefined for null graph."); } List <int> connected = new List <int>(); List <Tuple <int, int, int?> > bfs = new Traversal().BreadthFirstSearchAll(graph); return(bfs.Count == graph.NumberOfNodes); }
protected override void Initialize(BaseGraph graph) { titleContent = new GUIContent("Context Menu Graph"); var graphView = new CustomContextMenuGraphView(); rootView.Add(graphView); graphView.Add(new MiniMapView(graphView)); // graphView.AddElement(new NodeSelectorMenu()); }
public override void ExportGraph(List <InternalBaseGraphAsset> assets) { Dictionary <DialogType, List <DialogGraphAsset> > dialogGroupDict = new Dictionary <DialogType, List <DialogGraphAsset> >(); for (int i = 0; i < assets.Count; i++) { if (assets[i] is DialogGraphAsset) { DialogGraphAsset asset = assets[i] as DialogGraphAsset; if (!dialogGroupDict.ContainsKey(asset.dialogType)) { dialogGroupDict.Add(asset.dialogType, new List <DialogGraphAsset>()); } dialogGroupDict[asset.dialogType].Add(asset); } } foreach (var item in dialogGroupDict) { TBDialogCnf cnfTab = new TBDialogCnf(); List <DialogModel> dialogs = new List <DialogModel>(); DialogType dialogType = item.Key; List <DialogGraphAsset> dialogAssets = item.Value; foreach (var dialogAsset in dialogAssets) { BaseGraph graphData = dialogAsset.DeserializeGraph(); dialogs.AddRange(SerializeToDialogModel(graphData, dialogAsset)); } for (int i = 0; i < dialogs.Count; i++) { DialogModel tModel = dialogs[i]; if (cnfTab.ContainsKey(tModel.id)) { Debug.LogError($"Dialog配置生成失败,重复的对话Id>>>>{tModel.id}"); return; } else { cnfTab.Add(tModel.id, tModel); } } string filePath = DialogDef.GetDialogCnfPath(dialogType); IOHelper.WriteText(JsonMapper.ToJson(dialogs), filePath); Debug.Log($"对话生成成功》》》{filePath}"); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public ActionResult Form(int id = 0) { if (id == 0) { return(PartialView(new Admin.Models.BaseGraph())); } else { BaseGraph model = db.BaseGraphs.Find(id); return(PartialView(model)); } }
protected override void InitializeWindow(BaseGraph graph) { titleContent = new GUIContent("Custom Toolbar Graph"); if (graphView == null) { graphView = new CustomToolbarGraphView(this); graphView.Add(new CustomToolbarView(graphView)); } rootView.Add(graphView); }
/// <summary> /// The DFS2 /// </summary> /// <param name="visited">The visited<see cref="bool[]"/></param> /// <param name="component">The component<see cref="Component"/></param> /// <param name="v">The v<see cref="int"/></param> /// <param name="transposeGraph">The transposeGraph<see cref="BaseGraph"/></param> private void DFS2(bool[] visited, Component component, int v, BaseGraph transposeGraph) { visited[v] = true; component.Nodes.Add(v); foreach (Edge e in transposeGraph.GetEdges(v)) { if (!visited[e.To]) { DFS2(visited, component, e.To, transposeGraph); } } }
/** * Constructor 2 * * @param graph * @param sourceVertex * @param targetVertex */ public YenTopKShortestPathsAlg(BaseGraph graph, BaseVertex sourceVertex, BaseVertex targetVertex) { if (graph == null) { throw new System.ArgumentException("A NULL graph object occurs!"); } this.graph = new VariableGraph((Graph)graph); this.sourceVertex = sourceVertex; this.targetVertex = targetVertex; Init(); }
/// <inheritdoc /> public bool TryGetOutEdges(TVertex vertex, out IEnumerable <TEdge> edges) { if (BaseGraph.TryGetOutEdges(vertex, out _)) { TEdge[] outEdges = OutEdges(vertex).ToArray(); edges = outEdges; return(outEdges.Length > 0); } edges = null; return(false); }
protected override void InitializeWindow(BaseGraph graph) { var mixture = (graph as MixtureGraph); bool realtime = mixture.isRealtime; titleContent = new GUIContent($"Mixture {(realtime ? "(RT) " : "")}- {mixture.name}", MixtureUtils.windowIcon); view = new MixtureGraphView(this); rootView.Add(view); view.Add(new MixtureToolbar(view)); }
/// <inheritdoc /> public TEdge OutEdge(TVertex vertex, int index) { if (vertex == null) { throw new ArgumentNullException(nameof(vertex)); } if (VertexPredicate(vertex)) { return(BaseGraph.OutEdges(vertex).Where(FilterEdge).ElementAt(index)); } throw new VertexNotFoundException(); }
/// <inheritdoc /> public IEnumerable <TEdge> OutEdges(TVertex vertex) { if (vertex == null) { throw new ArgumentNullException(nameof(vertex)); } if (VertexPredicate(vertex)) { return(BaseGraph.OutEdges(vertex).Where(FilterEdge)); } throw new VertexNotFoundException(); }
protected override void InitializeWindow(BaseGraph graph) { graphView = new UniversalGraphView(this); m_MiniMap = new MiniMap() { anchored = true }; graphView.Add(m_MiniMap); m_ToolbarView = new SkillToolbarView(this, graphView, m_MiniMap, graph); graphView.Add(m_ToolbarView); }
/// <inheritdoc /> public IEnumerable <TEdge> AdjacentEdges(TVertex vertex) { if (vertex == null) { throw new ArgumentNullException(nameof(vertex)); } if (VertexPredicate(vertex)) { return(BaseGraph.AdjacentEdges(vertex).Where(FilterEdge)); } return(Enumerable.Empty <TEdge>()); }
}//end method #endregion public static void WriteToXMLFile(string url, BaseGraph graph) { StreamWriter filewriter = new StreamWriter(url); XmlTextWriter writer = new XmlTextWriter(filewriter); if (graph is NonDirectedGraph) { writer.WriteElementString("NonDirectedGraph", ""); } else if(graph is DirectedGraph) { writer.WriteElementString("DirectedGraph", ""); } writer.WriteElementString("Nodes", ""); foreach (Node node in graph.NodesList.Values) { writer.WriteElementString("Node", node.NodeNumber.ToString()); writer.WriteEndElement(); //</Node> } writer.WriteEndElement(); //</Nodes> writer.WriteName("Lines"); foreach (Line line in graph.LinesList.Values) { writer.WriteElementString("Name", line.LineName); writer.WriteEndElement(); writer.WriteElementString("FirstNode", line.FirstNode.NodeNumber.ToString()); writer.WriteEndElement(); writer.WriteElementString("SecondNode", line.SecondNode.NodeNumber.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); // end </Lines> writer.WriteEndElement(); // end </NonDirectedGraph> or <DirectedGraph> }