/// <summary> /// The returned IQueryResult contains vertices which are null if no Int64 is created, /// otherwise they contain a vertexview with a property dictionary, where in first position is the created Int64 /// </summary> public override IQueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, Int64 myTransactionToken) { var sw = Stopwatch.StartNew(); var myToken = myGraphDB.BeginTransaction(mySecurityToken, IsLongRunning, Isolation); VertexView view = null; var readoutVals = new Dictionary <String, Object>(); readoutVals.Add("TransactionID", myToken); readoutVals.Add("Created", TimeStamp); readoutVals.Add("Distributed", IsDistributed); readoutVals.Add("IsolationLevel", Isolation); readoutVals.Add("LongRunning", IsLongRunning); readoutVals.Add("Name", Name); view = new VertexView(readoutVals, null); sw.Stop(); return(QueryResult.Success(myQuery, SonesGQLConstants.GQL, new List <IVertexView> { view }, Convert.ToUInt64(sw.ElapsedMilliseconds))); }
public async Task <IEnumerable <VertexView> > DFS(int v_num, Canvas graphCanvas) { Stack <VertexView> stack = new Stack <VertexView>(); List <VertexView> toReturn = new List <VertexView>(); VertexView visited = V.Where(x => x.Number == v_num).First(); foreach (var elem in graphCanvas.Children) { if (elem is Ellipse ellipse) { if ((int)ellipse.Tag == visited.Number) { ellipse.Stroke = new SolidColorBrush(Color.FromRgb(140, 140, 0)); } } } stack.Push(visited); toReturn.Add(visited); SortedSet <VertexView> VisitedVertex = new SortedSet <VertexView>(); VisitedVertex.Add(visited); while (stack.Count != 0) { VertexView s = stack.Pop(); if (!VisitedVertex.Contains(s)) { toReturn.Add(s); await Task.Delay(2000); foreach (var elem in graphCanvas.Children) { if (elem is Ellipse ellipse) { if ((int)ellipse.Tag == s.Number) { ellipse.Stroke = new SolidColorBrush(Color.FromRgb(140, 140, 0)); } } else if (elem is Line line) { int v1 = int.Parse(line.Tag.ToString().Split()[0]); int v2 = int.Parse(line.Tag.ToString().Split()[1]); if (toReturn[toReturn.Count - 2].Number == v1 && toReturn.Last().Number == v2) { line.Stroke = new SolidColorBrush(Color.FromRgb(140, 0, 140)); } } } } VisitedVertex.Add(s); foreach (var vert in FindАdjacentVertexs(s.Number).OrderByDescending(x => x.Number)) { if (!VisitedVertex.Contains(vert)) { stack.Push(vert); } } } return(toReturn); }
public override void Init() { this.model = base.model as TriangleModel; model.verticesModelVec = new List <VertexModel>(); for (int i = 0; i != model.view.transform.childCount; ++i) { VertexModel vertexModel = new VertexModel(); vertexModel.componentsAssetID = model.componentsAssetID; vertexModel.codeSnippetsAssetID = model.codeSnippetsAssetID; vertexModel.name = "Vertex"; vertexModel.parent = model; VertexView vertexView = model.view.transform.GetChild(i).gameObject.GetComponent_AutoAdd <VertexView>(); VertexController vertexController = new VertexController(); GameResourceManager.Instance.CombineMVC(vertexModel, vertexView, vertexController); vertexModel.OnPositionUpdated += InitTriangle; vertexModel.OnColorUpdated += (Color => InitTriangle(Vector3.zero)); model.verticesModelVec.Add(vertexModel); } InitTriangle(Vector3.zero); }
public IEnumerable <VertexView> BFSLearningMode(int v_num) { Queue <VertexView> queue = new Queue <VertexView>(); List <VertexView> toReturn = new List <VertexView>(); VertexView visited = V.Where(x => x.Number == v_num).First(); queue.Enqueue(visited); SortedSet <VertexView> VisitedVertex = new SortedSet <VertexView>(); VisitedVertex.Add(visited); while (queue.Count != 0) { VertexView cur = queue.Dequeue(); toReturn.Add(cur); foreach (var vert in FindАdjacentVertexs(cur.Number).OrderBy(x => x.Number)) { if (!VisitedVertex.Contains(vert)) { queue.Enqueue(vert); VisitedVertex.Add(vert); } } } return(toReturn); }
public void DeleteVertex(VertexView vertex) { var edgesToDelete = new List <EdgeView>(); foreach (var edge in E) { if (edge.V1.Number == vertex.Number || edge.V2.Number == vertex.Number) { edgesToDelete.Add(edge); } } foreach (var edge in edgesToDelete) { E.Remove(edge); } foreach (var edge in E) { if (edge.V1.Number > vertex.Number) { edge.V1.Number -= 1; } if (edge.V2.Number > vertex.Number) { edge.V2.Number -= 1; } } V.Remove(vertex); }
public IEnumerable <VertexView> DFSBoruvka(int v) { Stack <VertexView> stack = new Stack <VertexView>(); List <VertexView> toReturn = new List <VertexView>(); VertexView visited = V.Where(x => x.Number == v).First(); stack.Push(visited); toReturn.Add(visited); SortedSet <VertexView> VisitedVertex = new SortedSet <VertexView>(); VisitedVertex.Add(visited); while (stack.Count != 0) { VertexView s = stack.Pop(); if (!VisitedVertex.Contains(s)) { toReturn.Add(s); } VisitedVertex.Add(s); foreach (var vert in FindАdjacentVertexs(s.Number).OrderByDescending(x => x.Number)) { if (!VisitedVertex.Contains(vert)) { stack.Push(vert); vert.IsVisited = true; } } } return(toReturn); }
public void InstantiateModel(OBJFile model) { nodes = new List <TestNode>(); foreach (Vector3 v in model.vertexPositions) { GameObject vertex = Instantiate(vertexPrefab, v, Quaternion.identity); VertexView ver = vertex.GetComponent <VertexView>(); TestNode testNode = new TestNode(ver); nodes.Add(testNode); } foreach (Face tri in model.faces) { GameObject connection1 = Instantiate(sidePrefab, Vector3.zero, Quaternion.identity); GameObject connection2 = Instantiate(sidePrefab, Vector3.zero, Quaternion.identity); GameObject connection3 = Instantiate(sidePrefab, Vector3.zero, Quaternion.identity); ConnectionView conn1 = connection1.GetComponent <ConnectionView>(); ConnectionView conn2 = connection2.GetComponent <ConnectionView>(); ConnectionView conn3 = connection3.GetComponent <ConnectionView>(); conn1.SetConection(tri.vertices[0].position, tri.vertices[1].position); conn2.SetConection(tri.vertices[0].position, tri.vertices[2].position); conn3.SetConection(tri.vertices[1].position, tri.vertices[2].position); } graph = new TestGraph(nodes, ConnectionView.conections); graph.GenerateGraphConections(); }
public TestNode(VertexView _vertexView) { view = _vertexView; view.testNode = this; Position = view.transform.position; id = IDManager.CreateID("TestNode", 4); view.gameObject.name = id; }
//public VertexDjekstra(int number, string Name): base(number,Name) //{ // CurrentMark = int.MaxValue; //} //public VertexDjekstra(int number, string Name, bool visited) : base(number, Name, visited) //{ // CurrentMark = int.MaxValue; //} public VertexDjekstra(VertexView v) { Name = v.Name; IsVisited = v.IsVisited; Number = v.Number; CurrentMark = int.MaxValue / 2; X = v.X; Y = v.Y; }
private IEnumerable <EdgeView> FindAdjacentEdges(VertexView vertex) { foreach (var e in E) { if (e.V1.Number == vertex.Number) { yield return(e); } } }
public EdgeDjekstra(VertexView v1, VertexView v2, int distance) { V1 = new VertexDjekstra() { Number = v1.Number, Name = v1.Name }; V2 = new VertexDjekstra() { Number = v2.Number, Name = v2.Name }; Distance = distance; }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (MouseOver) { print("Start: " + name); if (destinationVertex == this) { destinationVertex.meshRenderer.material = defaultMaterial; destinationVertex = null; } if (startVertex != null) { startVertex.meshRenderer.material = defaultMaterial; } startVertex = this; meshRenderer.material = startMaterial; } } if (Input.GetMouseButtonDown(1)) { if (MouseOver) { print("Destination: " + name); if (startVertex == this) { startVertex.meshRenderer.material = defaultMaterial; startVertex = null; } if (destinationVertex != null) { destinationVertex.meshRenderer.material = defaultMaterial; } destinationVertex = this; meshRenderer.material = destinationMaterial; } } }
public override void Init() { // DO NOT trigger base init, or it will create component for texture quad this.model = base.model as TextureQuadModel; verticesPos = new Vector3[4]; verticesTexcoord = new Vector2[4]; indexes = new int[6] { 0, 3, 2, 0, 2, 1 }; model.verticesModelVec = new List <VertexModel>(); for (int i = 0; i != model.view.transform.childCount; ++i) { // TODO: refactor int index = i; VertexModel vertexModel = new VertexModel(); vertexModel.componentsAssetID = model.componentsAssetID; // set the vertex components id vertexModel.codeSnippetsAssetID = model.codeSnippetsAssetID; vertexModel.name = "Vertex"; vertexModel.parent = model; VertexView vertexView = model.view.transform.GetChild(i).gameObject.GetComponent_AutoAdd <VertexView>(); VertexController vertexController = new VertexController(); GameResourceManager.Instance.CombineMVC(vertexModel, vertexView, vertexController); vertexModel.OnPositionUpdated += ((pos) => UpdateVertexPos(index, pos)); vertexModel.OnTexcoordUpdated += ((texcoord) => UpdateVertexTexcoord(index, texcoord)); model.verticesModelVec.Add(vertexModel); } for (int i = 0; i != model.view.transform.childCount; ++i) { verticesPos[i] = model.verticesModelVec[i].position; verticesTexcoord[i] = model.verticesModelVec[i].texcoord; } UpdateVertexData(); }
public async static Task <SortedDictionary <VertexView, int> > AlgDjekstra(int startVert, GraphVisual.Graph g, Canvas graphCanvas, bool isLearingMode) { VertexView startVertex = g.V.Where(item => item.Number == startVert).First(); ; _distances = new SortedDictionary <VertexView, int>(); Edges = new List <EdgeDjekstra>(); Vertices = new List <VertexDjekstra>(); grCanvas = graphCanvas; foreach (var edge in g.E) { Edges.Add(new EdgeDjekstra(edge.V1, edge.V2, edge.Distance)); } foreach (var vertex in g.V) { Vertices.Add(new VertexDjekstra(vertex)); } VertexDjekstra firstVertex = Vertices.Where(item => item.Number == startVertex.Number).First(); firstVertex.CurrentMark = 0; await FindMinWays(firstVertex, isLearingMode); return(_distances); }
public async Task <IEnumerable <VertexView> > BFS(int v_num, Canvas graphCanvas) { Queue <VertexView> queue = new Queue <VertexView>(); List <VertexView> toReturn = new List <VertexView>(); VertexView visited = V.Where(x => x.Number == v_num).First(); foreach (var elem in graphCanvas.Children) { if (elem is Ellipse ellipse) { if ((int)ellipse.Tag == visited.Number) { ellipse.Stroke = new SolidColorBrush(Color.FromRgb(140, 140, 0)); } } } queue.Enqueue(visited); toReturn.Add(visited); SortedSet <VertexView> VisitedVertex = new SortedSet <VertexView>(); VisitedVertex.Add(visited); while (queue.Count != 0) { VertexView cur = queue.Dequeue(); toReturn.Add(cur); await Task.Delay(1000); foreach (var elem in graphCanvas.Children) { if (elem is Ellipse ellipse) { if ((int)ellipse.Tag == cur.Number) { ellipse.Stroke = new SolidColorBrush(Color.FromRgb(140, 140, 0)); } } } foreach (var vert in FindАdjacentVertexs(cur.Number).OrderBy(x => x.Number)) { if (!VisitedVertex.Contains(vert)) { foreach (var elem in graphCanvas.Children) { if (elem is Ellipse ellipse) { if ((int)ellipse.Tag == cur.Number) { ellipse.Stroke = new SolidColorBrush(Color.FromRgb(140, 140, 0)); } } else if (elem is Line line) { int v1 = int.Parse(line.Tag.ToString().Split()[0]); int v2 = int.Parse(line.Tag.ToString().Split()[1]); if (cur.Number == v1 && vert.Number == v2) { line.Stroke = new SolidColorBrush(Color.FromRgb(140, 0, 140)); } } } await Task.Delay(1000); queue.Enqueue(vert); VisitedVertex.Add(vert); } } } return(toReturn); }
public override FuncParameter ExecFunc(IAttributeDefinition myAttributeDefinition, Object myCallingObject, IVertex myDBObject, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, params FuncParameter[] myParams) { #region initialize data // The edge we starting of (e.g. Friends) var typeAttribute = myAttributeDefinition; var startNode = myDBObject; var targetNode = (myParams[0].Value as IVertex); byte maxDepth = Convert.ToByte((Int64)myParams[1].Value); byte maxPathLength = Convert.ToByte((Int64)myParams[2].Value); bool onlyShortestPath = (Boolean)myParams[3].Value; bool allPaths = (Boolean)myParams[4].Value; if (!onlyShortestPath && !allPaths) { allPaths = true; } #endregion #region check correctness of parameters //check if values are correct if (maxDepth < 1) { throw new InvalidFunctionParameterException("maxDepth", ">= 1", maxDepth.ToString()); } if (maxPathLength < 2) { throw new InvalidFunctionParameterException("maxPathLength", ">= 2", maxPathLength.ToString()); } #endregion #region call graph function HashSet<List<long>> paths; //BFS paths = new BFS().Find(typeAttribute, startNode, targetNode, onlyShortestPath, allPaths, maxDepth, maxPathLength); //bidirectional BFS paths = new BidirectionalBFS().Find(typeAttribute, startNode, targetNode, onlyShortestPath, allPaths, maxDepth, maxPathLength); if (paths != null) { #region create outputted vertexviews var props = new Dictionary<String, object>(); var edges = new Dictionary<String, IEdgeView>(); foreach (var vertex in paths) { #region get properties #endregion } var vertexView = new VertexView(props, edges); #endregion //ALT //return new FuncParameter(new EdgeTypePath(paths, typeAttribute, typeAttribute.GetDBType(dbContext.DBTypeManager)), typeAttribute); return new FuncParameter(paths); } else { //ALT //return new FuncParameter(new EdgeTypePath(new HashSet<List<long>>(), typeAttribute, typeAttribute.GetDBType(dbContext.DBTypeManager)), typeAttribute); return new FuncParameter(new HashSet<List<long>>()); } #endregion }
public void AddVertex(VertexView vertex) { V.Add(vertex); cntVertix += 1; }
/// <summary> /// Go through each DBO and aggregate them /// </summary> /// <param name="myAggregates"></param> /// <param name="mySelections"></param> /// <param name="myDBOs"></param> /// <param name="myReferencedDBType"></param> /// <returns></returns> private IEnumerable<IVertexView> ExamineDBO_Aggregates(Int64 myTransactionToken, SecurityToken mySecurityToken, IEnumerable<IVertex> myDBOs, List<SelectionElementAggregate> myAggregates, List<SelectionElement> mySelections, Boolean myUsingGraph, Int64 myDepth) { #region Aggregate if (mySelections.CountIsGreater(0)) { #region Grouping - each selection is grouped (checked prior) var aggregatedGroupings = new Dictionary<GroupingKey, SelectionElementAggregate>(); #region Create groupings using the ILookup var groupedDBOs = myDBOs.ToLookup((dbo) => { #region Create GroupingKey based on the group values and attributes Dictionary<GroupingValuesKey, IComparable> groupingVals = new Dictionary<GroupingValuesKey, IComparable>(); foreach (var selection in mySelections) { var attrValue = (selection.Element as IPropertyDefinition).GetValue(dbo); groupingVals.Add(new GroupingValuesKey(selection.Element, selection.Alias), attrValue); } GroupingKey groupingKey = new GroupingKey(groupingVals); #endregion return groupingKey; }, (dbo) => { return dbo; }); #endregion foreach (var group in groupedDBOs) { #region Create group readouts var aggregatedAttributes = new Dictionary<String, Object>(); foreach (var aggr in myAggregates) { var aggrResult = aggr.Aggregate.Aggregate( (group).Select( aVertex => (aggr.Element as IPropertyDefinition).GetValue(aVertex)), (IPropertyDefinition)aggr.Element); if (aggrResult.Value != null) { //aggregatedAttributes.Add(aggr.Alias, aggrResult.Value.Value.GetReadoutValue()); aggregatedAttributes.Add(aggr.Alias, ResolveAggregateResult(aggrResult, myDepth)); } } foreach (var groupingKeyVal in group.Key.Values) { aggregatedAttributes.Add(groupingKeyVal.Key.AttributeAlias, groupingKeyVal.Value); } var dbObjectReadout = new VertexView(aggregatedAttributes, null); #endregion #region Evaluate having if exist and yield return if (_HavingExpression != null) { var res = _HavingExpression.IsSatisfyHaving(dbObjectReadout); if (res) yield return dbObjectReadout; } else { yield return dbObjectReadout; } #endregion } yield break; #endregion } else { #region No grouping, just aggregates var aggregatedAttributes = new Dictionary<String, Object>(); VertexView _Vertex; #region OR Attribute aggregates foreach (var aggr in myAggregates) { FuncParameter aggrResult = null; if (aggr.Aggregate.PluginShortName == "count" && aggr.RelatedIDChainDefinition.SelectType == TypesOfSelect.Asterisk) { aggrResult = new FuncParameter(_graphdb.GetVertexCount<UInt64>(mySecurityToken, myTransactionToken, new RequestGetVertexCount(aggr.EdgeList.LastEdge.VertexTypeID), (stats, count) => count)); } else { aggrResult = aggr.Aggregate.Aggregate( myDBOs.Where(aVertex => (aggr.Element as IPropertyDefinition).HasValue(aVertex)).Select( dbo => (aggr.Element as IPropertyDefinition).GetValue(dbo)), (IPropertyDefinition)aggr.Element); } //aggregatedAttributes.Add(aggr.Alias, aggrResult.Value.GetReadoutValue()); if (aggrResult.Value != null) { aggregatedAttributes.Add(aggr.Alias, ResolveAggregateResult(aggrResult, myDepth)); } } _Vertex = new VertexView(aggregatedAttributes, null); #endregion #region Check having expression and yield return value if (_HavingExpression != null) { var res = _HavingExpression.IsSatisfyHaving(_Vertex); if (res) yield return _Vertex; } else { yield return _Vertex; } #endregion yield break; #endregion } #endregion }
/// <summary> /// The returned QueryResult contains vertices which are null if no Int64 is created, /// otherwise they contain a vertexview with a property dictionary, where in first position is the created Int64 /// </summary> public override QueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, Int64 myTransactionToken) { var sw = Stopwatch.StartNew(); var myToken = myGraphDB.BeginTransaction(mySecurityToken, IsLongRunning, Isolation); VertexView view = null; var readoutVals = new Dictionary<String, Object>(); readoutVals.Add("TransactionID", myToken); readoutVals.Add("Created", TimeStamp); readoutVals.Add("Distributed", IsDistributed); readoutVals.Add("IsolationLevel", Isolation); readoutVals.Add("LongRunning", IsLongRunning); readoutVals.Add("Name", Name); view = new VertexView(readoutVals, null); sw.Stop(); return new QueryResult(myQuery, "GQL", Convert.ToUInt64(sw.ElapsedMilliseconds), ResultType.Successful, new List<IVertexView> { view }); }
/// <summary> /// Group all DBOs and return the readouts /// </summary> /// <param name="myDBObjectStreams"></param> /// <param name="mySelections"></param> /// <param name="myReferencedDBType"></param> /// <returns></returns> private IEnumerable<IVertexView> ExamineDBO_Groupings(IEnumerable<IVertex> myDBObjectStreams, List<SelectionElement> mySelections) { #region Create groupings using the ILookup var _GroupedVertices = myDBObjectStreams.ToLookup((dbo) => { #region Create GroupingKey based on the group values and attributes var groupingVals = new Dictionary<GroupingValuesKey, IComparable>(); foreach (var selection in mySelections) { var attrValue = (selection.Element as IPropertyDefinition).GetValue(dbo); groupingVals.Add(new GroupingValuesKey(selection.Element, selection.Alias), attrValue); } GroupingKey groupingKey = new GroupingKey(groupingVals); #endregion return groupingKey; }, (dbo) => { return dbo; }); #endregion foreach (var group in _GroupedVertices) { #region No valid grouping keys found if (group.Key.Values.IsNullOrEmpty()) { continue; } #endregion var groupedAttributes = new Dictionary<String, Object>(); foreach (var groupingKeyVal in group.Key.Values) { groupedAttributes.Add(groupingKeyVal.Key.AttributeAlias, groupingKeyVal.Value); } var _VertexGroup = new VertexView(groupedAttributes, null); #region Check having if (_HavingExpression != null) { var res = _HavingExpression.IsSatisfyHaving(_VertexGroup); if (res) yield return _VertexGroup; } else { yield return _VertexGroup; } #endregion } }