private IReadOnlyList <EdgeModel> GetHalfEdges() { var verts = _kernel.Vertices.ToArray(); var edges = _kernel.Edges.ToArray(); var models = new EdgeModel[HalfEdgeCount]; for (int i = 0; i < HalfEdgeCount; i++) { models[i] = new EdgeModel { Index = i, Origin = new VertexModel { Index = Array.IndexOf(verts, edges[i].Origin), Position = edges[i].Origin.Position }, Target = new VertexModel { Index = Array.IndexOf(verts, edges[i].Target), Position = edges[i].Target.Position } }; } return(models); }
/// <summary> /// Writes the edge. /// </summary> /// <param name='edge'> Edge. </param> /// <param name='writer'> Writer. </param> private static void WriteEdge(EdgeModel edge, SerializationWriter writer) { writer.WriteOptimized(SerializedEdge); WriteAGraphElement(edge, writer); writer.Write(edge.SourceVertex.Id); writer.Write(edge.TargetVertex.Id); }
public GraphModel BuildGraph() { GraphModel graphModel = new GraphModel(); List <string> nodeFileLines = File.ReadAllLines(_nodeFileName).ToList(); foreach (var nodeFileLine in nodeFileLines) { var splitFileLine = nodeFileLine.Split(new[] { "," }, StringSplitOptions.None); string nodeName = splitFileLine[0].Trim(); int x = int.Parse(splitFileLine[1]); int y = int.Parse(splitFileLine[2]); NodeModel nodeModel = new NodeModel(x, y, nodeName); graphModel.Nodes.Add(nodeModel); } List <string> edgeFileLines = File.ReadAllLines(_edgeFileName).ToList(); foreach (var edgeFileLine in edgeFileLines) { var splitFileLine = edgeFileLine.Split(new[] { "," }, StringSplitOptions.None); string startNodeName = splitFileLine[0].Trim(); string endNodeName = splitFileLine[1].Trim(); int weight = int.Parse(splitFileLine[2]); NodeModel startNodeModel = graphModel.Nodes.Single(x => x.Name == startNodeName); NodeModel endNodeModel = graphModel.Nodes.Single(x => x.Name == endNodeName); EdgeModel edgeModel = new EdgeModel(startNodeModel, endNodeModel, weight); graphModel.Edges.Add(edgeModel); } return(graphModel); }
/// <summary> /// Creates a new path element /// </summary> /// <param name="edge"> The edge. </param> /// <param name="edgePropertyId"> The edge property identifier. </param> /// <param name="direction"> The direction. </param> /// <param name="weight"> The weight. </param> public PathElement(EdgeModel edge, UInt16 edgePropertyId, Direction direction, Double weight = 0.0) { Edge = edge; EdgePropertyId = edgePropertyId; Direction = direction; Weight = weight; _sourceVertex = null; _targetVertex = null; }
public void EdgeHasNotGhostClass() { GraphView graphView = new GraphView(null, null, ""); var model = new EdgeModel(); var edge = new Edge(); edge.SetupBuildAndUpdate(model, null, graphView); Assert.IsFalse(edge.ClassListContains(Edge.ghostModifierUssClassName)); }
public void PathElementConstructorUnitTest() { Assert.Inconclusive("TODO"); EdgeModel edge = null; // TODO: Initialize to an appropriate value ushort edgePropertyId = 0; // TODO: Initialize to an appropriate value var direction = new Direction(); // TODO: Initialize to an appropriate value double weight = 0F; // TODO: Initialize to an appropriate value var target = new PathElement(edge, edgePropertyId, direction, weight); }
public void InitSubjectModel(SubjectModel node, EdgeModel edge) { node.Id = Graph.Address[edge.SubjectId].Id; node.IdType = Graph.SubjectTypesIndexReverse[edge.SubjectType]; node.Scope = Graph.ScopeIndexReverse[edge.Scope]; node.Activate = edge.Activate; node.Expire = edge.Expire; node.Cost = edge.Cost; node.Timestamp = edge.Timestamp; node.Claim = edge.Claim.ConvertToJObject(); }
public void EdgeHasExpectedParts() { GraphView graphView = new GraphView(null, null, ""); var model = new EdgeModel(); var edge = new Edge(); edge.SetupBuildAndUpdate(model, null, graphView); Assert.IsNotNull(edge.SafeQ <EdgeControl>(Edge.edgeControlPartName)); Assert.IsFalse(edge.ClassListContains(Edge.editModeModifierUssClassName)); }
public void EdgeModelConstructorUnitTest() { Assert.Inconclusive("TODO"); int id = 0; // TODO: Initialize to an appropriate value uint creationDate = 0; // TODO: Initialize to an appropriate value VertexModel targetVertex = null; // TODO: Initialize to an appropriate value VertexModel sourceVertex = null; // TODO: Initialize to an appropriate value PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value var target = new EdgeModel(id, creationDate, targetVertex, sourceVertex, properties); }
public async Task Update(EdgeModel edge) { var mappedEntity = ObjectMapper.Mapper.Map <Edge>(edge); if (mappedEntity == null) { throw new ApplicationException($"Entity could not be mapped."); } await _edgeRepository.Update(mappedEntity); _logger.LogInformation($"Entity successfully updated - {serviceName}"); }
public Boolean TryGetEdge(out EdgeModel result, Int32 id) { if (ReadResource()) { var success = _graphElements.TryGetElementOrDefault(out result, id); FinishReadResource(); return(success); } throw new CollisionException(); }
public Boolean TryGetEdge(out EdgeModel result, Int32 id) { if (ReadResource()) { result = _graphElements[id] as EdgeModel; FinishReadResource(); return(result != null); } throw new CollisionException(this); }
public void SourceVertexUnitTest() { Assert.Inconclusive("TODO"); EdgeModel edge = null; // TODO: Initialize to an appropriate value ushort edgePropertyId = 0; // TODO: Initialize to an appropriate value var direction = new Direction(); // TODO: Initialize to an appropriate value double weight = 0F; // TODO: Initialize to an appropriate value var target = new PathElement(edge, edgePropertyId, direction, weight); // TODO: Initialize to an appropriate value VertexModel actual; actual = target.SourceVertex; }
/// <summary> /// Loads the edge. /// </summary> /// <param name='reader'> Reader. </param> /// <param name='graphElements'> Graph elements. </param> /// <param name='sneakPeaks'> Sneak peaks. </param> private static void LoadEdge(SerializationReader reader, AGraphElement[] graphElements, ref List <EdgeSneakPeak> sneakPeaks) { var id = reader.ReadInt32(); var creationDate = reader.ReadUInt32(); var modificationDate = reader.ReadUInt32(); #region properties PropertyContainer[] properties = null; var propertyCount = reader.ReadInt32(); if (propertyCount > 0) { properties = new PropertyContainer[propertyCount]; for (var i = 0; i < propertyCount; i++) { var propertyIdentifier = reader.ReadUInt16(); var propertyValue = reader.ReadObject(); properties[i] = new PropertyContainer { PropertyId = propertyIdentifier, Value = propertyValue }; } } #endregion var sourceVertexId = reader.ReadInt32(); var targetVertexId = reader.ReadInt32(); VertexModel sourceVertex = graphElements[sourceVertexId] as VertexModel; VertexModel targetVertex = graphElements[targetVertexId] as VertexModel; if (sourceVertex != null && targetVertex != null) { graphElements[id] = new EdgeModel(id, creationDate, modificationDate, targetVertex, sourceVertex, properties); } else { sneakPeaks.Add(new EdgeSneakPeak { CreationDate = creationDate, Id = id, ModificationDate = modificationDate, Properties = properties, SourceVertexId = sourceVertexId, TargetVertexId = targetVertexId }); } }
public static double Overlap(this EdgeModel firstEdge, EdgeModel secondEdge) { if (firstEdge is null) { throw new ArgumentNullException(nameof(firstEdge)); } if (secondEdge is null) { throw new ArgumentNullException(nameof(secondEdge)); } return(Math.Max(0, firstEdge.Difference(secondEdge))); }
public void ChangingEditModeAddClassName() { GraphView graphView = new GraphView(null, null, ""); var model = new EdgeModel(); var edge = new Edge(); edge.SetupBuildAndUpdate(model, null, graphView); Assert.IsFalse(edge.ClassListContains(Edge.editModeModifierUssClassName)); model.EditMode = true; edge.UpdateFromModel(); Assert.IsTrue(edge.ClassListContains(Edge.editModeModifierUssClassName)); }
public static bool Collision(this EdgeModel firstEdge, EdgeModel secondEdge) { if (firstEdge is null) { throw new ArgumentNullException(nameof(firstEdge)); } if (secondEdge is null) { throw new ArgumentNullException(nameof(secondEdge)); } return(firstEdge.Difference(secondEdge) >= 0); }
public void CalculateWeightUnitTest() { Assert.Inconclusive("TODO"); EdgeModel edge = null; // TODO: Initialize to an appropriate value ushort edgePropertyId = 0; // TODO: Initialize to an appropriate value var direction = new Direction(); // TODO: Initialize to an appropriate value double weight = 0F; // TODO: Initialize to an appropriate value var target = new PathElement(edge, edgePropertyId, direction, weight); // TODO: Initialize to an appropriate value PathDelegates.VertexCost vertexCost = null; // TODO: Initialize to an appropriate value PathDelegates.EdgeCost edgeCost = null; // TODO: Initialize to an appropriate value target.CalculateWeight(vertexCost, edgeCost); }
private async Task ValidateIfExist(EdgeModel edge) { if (edge == null) { throw new ArgumentNullException(nameof(edge)); } var existingEntity = await _edgeRepository.GetById(edge.Id); if (existingEntity != null) { throw new ApplicationException($"{edge} with this id already exists"); } }
/// <summary> /// Loads the graph model /// </summary> /// <param name="grahpInfo">Info about the graphn as text</param> /// <returns>Graph Model</returns> public GraphModel PopulateGraphModel(string grahpInfo) { GraphModel routeGraph = new GraphModel(); grahpInfo = grahpInfo.Replace(" ", "").Trim(); string[] nodeElements = grahpInfo.Split(','); foreach (var nodeElement in nodeElements) { if (nodeElement.Length == 3) { char nodeName = nodeElement[0]; EdgeModel edge = new EdgeModel { Label = nodeElement[1], Weight = int.Parse(nodeElement[2].ToString()) }; NodeModel node = routeGraph.Nodes.Find(n => n.Label.Equals(nodeName)); // Add a new node or new edge in a existing node if (node != null) { if (node.Edges.Find(e => e.Label.Equals(node.Label)) == null) { node.Edges.Add(edge); } else { throw new Exception(string.Format("Node: {0}, Weight: {1}", node.Label, edge.Weight)); } } else { node = new NodeModel { Label = nodeName }; node.Edges.Add(edge); routeGraph.Nodes.Add(node); } } else { throw new Exception(string.Format("The node information '{0}' is incorrect.", nodeElement)); } } return(routeGraph); }
public void TryGetEdgeIntegrationTest() { Assert.Inconclusive("TODO."); IRead target = CreateIRead(); // TODO: Initialize to an appropriate value EdgeModel result = null; // TODO: Initialize to an appropriate value EdgeModel resultExpected = null; // TODO: Initialize to an appropriate value int id = 0; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.TryGetEdge(out result, id); Assert.AreEqual(resultExpected, result); Assert.AreEqual(expected, actual); }
public EdgeModel CreateEdgeModel(SubjectModel subject, int timestamp) { var edge = new EdgeModel(); edge.SubjectId = EnsureNode(subject.Id); edge.SubjectType = EnsureSubjectType(subject.IdType); edge.Scope = EnsureScopeIndex(subject.Scope); edge.Activate = subject.Activate; edge.Expire = subject.Expire; edge.Cost = (short)subject.Cost; edge.Timestamp = timestamp; edge.Claim = ClaimStandardModel.Parse(subject.Claim); return(edge); }
public void CreateEdgeIntegrationTest() { Assert.Inconclusive("TODO."); IWrite target = CreateIWrite(); // TODO: Initialize to an appropriate value int sourceVertexId = 0; // TODO: Initialize to an appropriate value ushort edgePropertyId = 0; // TODO: Initialize to an appropriate value int targetVertexId = 0; // TODO: Initialize to an appropriate value uint creationDate = 0; // TODO: Initialize to an appropriate value PropertyContainer[] properties = null; // TODO: Initialize to an appropriate value EdgeModel expected = null; // TODO: Initialize to an appropriate value EdgeModel actual; actual = target.CreateEdge(sourceVertexId, edgePropertyId, targetVertexId, creationDate, properties); Assert.AreEqual(expected, actual); }
private Line AddEdge(EdgeModel graphEdge, Brush edgeBrush) { var line = new Line { X1 = graphEdge.Start.X + 7.5, X2 = graphEdge.End.X + 7.5, Y1 = graphEdge.Start.Y + 7.5, Y2 = graphEdge.End.Y + 7.5, Stroke = edgeBrush, StrokeThickness = graphEdge.Weight, ToolTip = graphEdge.Name }; MainCanvas.Children.Add(line); return(line); }
internal void Read(Class434 or, DxfVisualStyle.Class486 pr) { if (or.Version < DxfVersion.Dxf24) { this.edgeModel_0 = (EdgeModel)pr.vmethod_3(); this.edgeStyleFlags_0 = (EdgeStyleFlags)pr.vmethod_3(); this.color_0 = pr.vmethod_5(); this.color_1 = pr.vmethod_5(); this.lineType_0 = (LineType)pr.vmethod_3(); this.double_0 = pr.vmethod_4(); this.edgeModifierFlags_0 = (EdgeModifierFlags)pr.vmethod_3(); this.color_2 = pr.vmethod_5(); this.double_1 = pr.vmethod_4(); this.int_0 = (int)pr.vmethod_2(); this.int_1 = (int)pr.vmethod_2(); this.jitterAmount_0 = (JitterAmount)pr.vmethod_3(); this.color_3 = pr.vmethod_5(); this.int_2 = (int)pr.vmethod_2(); this.int_3 = (int)pr.vmethod_1(); this.int_4 = (int)pr.vmethod_2(); this.bool_0 = pr.vmethod_0(); this.edgeStyleApplication_0 = (EdgeStyleApplication)pr.vmethod_2(); this.lineType_1 = (LineType)pr.vmethod_2(); } else { this.edgeModel_0 = (EdgeModel)pr.vmethod_3(); this.edgeStyleFlags_0 = (EdgeStyleFlags)pr.vmethod_3(); this.color_0 = pr.vmethod_5(); this.color_1 = pr.vmethod_5(); this.lineType_0 = (LineType)pr.vmethod_3(); this.lineType_1 = (LineType)pr.vmethod_3(); this.double_0 = pr.vmethod_4(); this.edgeModifierFlags_0 = (EdgeModifierFlags)pr.vmethod_3(); this.color_2 = pr.vmethod_5(); this.double_1 = pr.vmethod_4(); this.int_0 = (int)(short)pr.vmethod_3(); this.int_1 = (int)(short)pr.vmethod_3(); this.jitterAmount_0 = (JitterAmount)pr.vmethod_3(); this.color_3 = pr.vmethod_5(); this.int_2 = (int)(short)pr.vmethod_3(); this.int_3 = (int)(short)pr.vmethod_3(); this.int_4 = (int)(short)pr.vmethod_3(); this.bool_0 = pr.vmethod_0(); } }
public EdgeModel CreateEdge(Int32 sourceVertexId, UInt16 edgePropertyId, Int32 targetVertexId, UInt32 creationDate, PropertyContainer[] properties = null) { if (WriteResource()) { try { EdgeModel outgoingEdge = null; var sourceVertex = _graphElements[sourceVertexId] as VertexModel; var targetVertex = _graphElements[targetVertexId] as VertexModel; //get the related vertices if (sourceVertex != null && targetVertex != null) { outgoingEdge = new EdgeModel(_currentId, creationDate, targetVertex, sourceVertex, properties); //add the edge to the graph elements _graphElements.Add(outgoingEdge); //increment the ids Interlocked.Increment(ref _currentId); //add the edge to the source vertex sourceVertex.AddOutEdge(edgePropertyId, outgoingEdge); //link the vertices targetVertex.AddIncomingEdge(edgePropertyId, outgoingEdge); //increase the edgeCount EdgeCount++; } return(outgoingEdge); } finally { FinishWriteResource(); } } throw new CollisionException(this); }
public async Task <EdgeModel> Create(EdgeModel edge) { await ValidateIfExist(edge); var mappedEntity = ObjectMapper.Mapper.Map <Edge>(edge); if (mappedEntity == null) { throw new ApplicationException($"Entity could not be mapped."); } var newEntity = await _edgeRepository.Create(mappedEntity); _logger.LogInformation($"Entity successfully added - { serviceName }"); var newMappedEntity = ObjectMapper.Mapper.Map <EdgeModel>(newEntity); return(newMappedEntity); }
private FrameworkElement CreateEdge(EdgeModel edgeModel) { var source = GetVertexControlFromVertexModel(edgeModel.Source); var target = GetVertexControlFromVertexModel(edgeModel.Target); var edgeControl = new EdgeControl { Source = source, Target = target, SourceRole = edgeModel.SourceRole, TargetRole = edgeModel.TargetRole, Foreground = Brushes.DarkRed, ToolTip = $"{target.Caption} ist {edgeModel.SourceRole} für {source.Caption} \n{source.Caption} ist {edgeModel.TargetRole} für {target.Caption}" }; SetZIndex(edgeControl, 10); return(edgeControl); }
public EdgeModel CreateEdge(Int32 sourceVertexId, UInt16 edgePropertyId, Int32 targetVertexId, UInt32 creationDate, PropertyContainer[] properties = null) { if (WriteResource()) { EdgeModel outgoingEdge = null; VertexModel sourceVertex; VertexModel targetVertex; //get the related vertices if (_graphElements.TryGetElementOrDefault(out sourceVertex, sourceVertexId) && _graphElements.TryGetElementOrDefault(out targetVertex, targetVertexId)) { outgoingEdge = new EdgeModel(_currentId, creationDate, targetVertex, sourceVertex, properties); //add the edge to the graph elements _graphElements.SetValue(_currentId, outgoingEdge); //increment the ids Interlocked.Increment(ref _currentId); //add the edge to the source vertex sourceVertex.AddOutEdge(edgePropertyId, outgoingEdge); //link the vertices targetVertex.AddIncomingEdge(edgePropertyId, outgoingEdge); //increase the edgeCount EdgeCount++; } FinishWriteResource(); return(outgoingEdge); } throw new CollisionException(); }
public void CopyFrom(EdgeStyle from, CloneContext cloneContext) { this.edgeModel_0 = from.edgeModel_0; this.edgeStyleFlags_0 = from.edgeStyleFlags_0; this.color_0 = from.color_0; this.color_1 = from.color_1; this.lineType_0 = from.lineType_0; this.lineType_1 = from.lineType_1; this.double_0 = from.double_0; this.edgeModifierFlags_0 = from.edgeModifierFlags_0; this.color_2 = from.color_2; this.double_1 = from.double_1; this.int_0 = from.int_0; this.int_1 = from.int_1; this.jitterAmount_0 = from.jitterAmount_0; this.color_3 = from.color_3; this.int_2 = from.int_2; this.int_3 = from.int_3; this.int_4 = from.int_4; this.bool_0 = from.bool_0; this.edgeStyleApplication_0 = from.edgeStyleApplication_0; this.wiggleAmount_0 = from.wiggleAmount_0; }