public void Insert(T data) { if (data.CompareTo(Data) >= 1) { if (RNode == null) { RNode = new Node <T>(data); } else { RNode.Insert(data); } } else { if (LNode == null) { LNode = new Node <T>(data); } else { LNode.Insert(data); } } }
public void ShouldIncreaseNodeArea() { var config = new RTreeConfig() { Max = 5, Min = 2 }; var node = new RNode <Int32>(config, new GuttmanSplit <Int32>()); var elemets = new List <Shape2DItem <Int32> >() { Shape2DFactory.GetShape(0, 0, 10, 10), Shape2DFactory.GetShape(15, 10, 10, 10), //Shape2DFactory.GetShape(30,0,10,10), //Shape2DFactory.GetShape(45,0,10,10), //Shape2DFactory.GetShape(60,0,10,10), //Shape2DFactory.GetShape(75,0,10,10), }; foreach (var item in elemets) { node.Add(item); } Assert.AreEqual(25, ((BoundingBox2D <Int32>)node.BoundingBox).Right); Assert.AreEqual(20, ((BoundingBox2D <Int32>)node.BoundingBox).Bottom); }
public LConnection(long id, RNode src, RNode dst) : base(id) { this.Source = src; this.Destination = dst; this.Distance = Source.Point.DistanceFrom(Destination.Point); }
RNode Find(RNode cloneHead, int k) { var it = cloneHead; while (it != null) { if (it.Value == k) { return(it); } it = it.Random; } it = cloneHead; while (it != null) { if (it.Value == k) { return(it); } it = it.Next; } return(null); }
public HiddenMarkovState(Point P, RNode roadSegment, double offset, bool isVirtual = false) { Candidate = new Tuple <RNode, double>(roadSegment, offset); AdjacencyList = new List <HiddenMarkovState>(); IsVirtualState = isVirtual; this.P = P; }
private void OnNodeAdded(Object sender, NodeRegisteredEventArgs e) { var rnode = new RNode(e.RegisteredNode); m_rnodes.Add(rnode.Identity, rnode); RNodeAdded?.Invoke(this, new RNodeAddedEventArgs(rnode)); }
public RConnection(long id, RNode src, RNode dst, bool isOneWay, bool isOnlyFoot) : base(id) { this.Source = src; this.Destination = dst; this.Distance = Source.Point.DistanceFrom(Destination.Point); this.OneWay = isOneWay; this.OnlyFoot = isOnlyFoot; }
public LConnection AddConnection(RNode src, RNode dst) { LConnection C = new LConnection(__MaxArcID, src, dst); src.Connections.Add(C); Connections.Add(__MaxArcID, C); ++(__MaxArcID); return(C); }
public RConnection AddConnection(RNode src, RNode dst, bool isOneWay, bool isOnlyFoot) { RConnection C = new RConnection(__MaxArcID, src, dst, isOneWay, isOnlyFoot); src.Connections.Add(C); Connections.Add(__MaxArcID, C); RConnections.Add(__MaxArcID, C); ++(__MaxArcID); return(C); }
public void RunLeftToRight() { if (LNode != null) { LNode.RunLeftToRight(); } Console.WriteLine(Data + " "); if (RNode != null) { RNode.RunLeftToRight(); } }
public void RunLeftToRight(List <string> theList) { if (LNode != null) { LNode.RunLeftToRight(theList); } theList.Add(Data.ToString()); Console.WriteLine(Data + " "); if (RNode != null) { RNode.RunLeftToRight(theList); } }
public RNode Clone(RNode head) { if (head == null) { return(null); } var cloneHead = new RNode(); var cloneCurrent = cloneHead; var it = head; while (it != null) { // Handle next element var existing = Find(cloneHead.Next, it.Value); if (existing == null) { cloneCurrent.Next = new RNode(it.Value); } else { cloneCurrent.Next = existing; } // Handle random element if (it.Random == null) { it = it.Next; cloneCurrent = cloneCurrent.Next; continue; } var existingRandom = Find(cloneHead.Next, it.Random.Value); if (existingRandom == null) { cloneCurrent.Next.Random = new RNode(it.Random.Value); } else { cloneCurrent.Next.Random = existingRandom; } // Move along the lists cloneCurrent = cloneCurrent.Next; it = it.Next; } return(cloneHead.Next); }
public RNode AddNode(long id, Point Coordinates) { RNode N = new RNode(id, Coordinates); GNodes.Add(id, N); RNodes.Add(id, N); //SpatialQuadTree.Insert(new QuadTreeNodeItem<RNode>(N, (float)N.Point.Longitude, (float)N.Point.Latitude)); Containers.RTree.Rectangle rect = new Containers.RTree.Rectangle((float)Coordinates.Longitude, (float)Coordinates.Latitude, (float)Coordinates.Longitude + 0.001f, (float)Coordinates.Latitude + 0.001f, 0, 0); SpatialQuadTree.Add(rect, N); return(N); }
public void Test1() { var n1 = new RNode(1); var n2 = new RNode(2); var n3 = new RNode(3); var n4 = new RNode(4); var n5 = new RNode(5); n1.Next = n2; n1.Random = n3; n2.Next = n3; n2.Random = n1; n3.Next = n4; n3.Random = n5; n4.Next = n5; n4.Random = n5; n5.Next = null; n5.Random = n2; var sut = new CloneListWithRandomPointer(); var result = sut.Clone(n1); var expIt = n1; var actualIt = result; while (expIt != null) { Assert.That(expIt.Value, Is.EqualTo(actualIt.Value)); if (expIt.Random != null) { Assert.That(expIt.Random.Value, Is.EqualTo(actualIt.Random.Value)); } else { Assert.That(actualIt.Random, Is.Null); } expIt = expIt.Next; actualIt = actualIt.Next; } }
public void PrintBTreeRecurrsive() { Console.Write(Data + " "); if (LNode != null) { LNode.PrintBTreeRecurrsive(); } if (RNode != null) { RNode.PrintBTreeRecurrsive(); } if (Next != null) { Next.PrintBTreeRecurrsive(); } }
private void CheckConnectivity() { List <RNode> Nodes = MatchingSolution.Where(x => x != null).ToList(); List <Tuple <RNode, RNode> > Cuts = new List <Tuple <RNode, RNode> >(); RNode u = null, v = null; RConnection C = null; for (int i = 0; i < Nodes.Count - 1; ++i) { u = Nodes[i]; v = Nodes[i + 1]; C = RoadNetwork.AreConnected(u, v); if (C == null) { Cuts.Add(new Tuple <RNode, RNode>(u, v)); } } // foreach (Tuple <RNode, RNode> T in Cuts) { u = T.Item1; v = T.Item2; Node Source = RoadNetwork.ResolvePoint(u.Point, 0.1f).First(); Node Target = RoadNetwork.ResolvePoint(v.Point, 0.1f).First(); Router router = new Router(Source, Target, string.Empty, 0, TravelMode.Car, ObjFunction.Distance); router.Start(); List <RNode> route = new List <RNode>(); foreach (Connection conn in router.Solution) { route.Add((RNode)conn.GetDestination()); } route.RemoveAll(x => x == u || x == v); RNode prev = u, next = null; for (int i = 0; i < route.Count; ++i) { next = route[i]; MatchingSolution.AddAfter(MatchingSolution.Find(prev), next); prev = next; } } }
public void ConnectCarpools() { RNode n = null; List <RNode> nList = null; foreach (CNode c in CNodes.Values) { nList = ResolvePoint(c.Point, 0.01f); if (nList.Count > 0) { n = nList.First(); AddConnection(c, n); AddConnection(n, c); } else { log.Warn("Carpools void node list (nList.Count: " + nList.Count + " c.Id:" + c.Id + " c.Point.Latitude:" + c.Point.Latitude + " c.Point.Longitude:" + c.Point.Longitude + ")"); } } }
public void ConnectTransportation() { RNode n = null; List <RNode> nList = null; foreach (TNode t in TNodes.Values) { nList = ResolvePoint(t.Point, 0.01f); if (nList.Count > 0) { n = nList.First(); AddConnection(t, n); AddConnection(n, t); } else { log.Warn("Transportation void node list (nList.Count: " + nList.Count + " t.Id:" + t.Id + " t.Point.Latitude:" + t.Point.Latitude + " t.Point.Longitude:" + t.Point.Longitude + ")"); } } }
private void CalculateScores() { // contains the node score if (_isScoreCalculated) { return; } _nodeScore = RNode.GetScore(); var r = (FragmentFeatureNode)RNode; if (LNode is PrecursorFeatureNode) { _ratioScore = _scoringParams.GetRatioScore(r.FragmentIonClassBase, _ratio, r.GroupParameter); var rr = 0.0; if (LNode.Feature != null) { rr = LNode.Feature.IntensityMax; } if (RNode.Feature != null) { rr /= RNode.Feature.IntensityMax; } else { rr = 0.0; } //if (rr > 100 || rr < .01) _ratioScore -= 4; //TODO //Console.WriteLine("Prec : " + r.FragmentIonClassBase.Name +"\t" + _ratio + "\t" + RatioScore + "\t" + r.Feature); //Console.WriteLine("pre " + _ratioScore); } else { var l = (FragmentFeatureNode)LNode; _ratioScore = _scoringParams.GetRatioScore(l.FragmentIonClassBase, r.FragmentIonClassBase, _ratio, r.GroupParameter); } _isScoreCalculated = true; }
public SplitNodeResult <T> Split(RNode <T> overflowNode) { var worstCouple = GetWorstCouple(overflowNode.Items); var result1 = new RNode <T>(overflowNode.Config, overflowNode.SplitStrategy); var result2 = new RNode <T>(overflowNode.Config, overflowNode.SplitStrategy); result1.Add(overflowNode.Items.ElementAt(worstCouple.IndexA)); result2.Add(overflowNode.Items.ElementAt(worstCouple.IndexB)); if (worstCouple.IndexA < worstCouple.IndexB) { overflowNode.Items.RemoveAt(worstCouple.IndexB); overflowNode.Items.RemoveAt(worstCouple.IndexA); } else { overflowNode.Items.RemoveAt(worstCouple.IndexA); overflowNode.Items.RemoveAt(worstCouple.IndexB); } var nodes = new List <RNode <T> >() { result1, result2 }; foreach (var item in overflowNode.Items) { var node = SearchHelper <T> .GetLessEnlargementNode(nodes, item.BoundingBox); node.Add(item); } return(new SplitNodeResult <T>() { A = result1, B = result2 }); }
public RNodeAddedEventArgs(RNode node) => AddedNode = node;
RNode str_extend(RNode list, int term) { int brace = -1; RNode node; int nest; int c = nextc(); switch (c) { case '$': break; case '@': break; case '{': break; default: tokadd('#'); pushback(c); return list; } string ss = tok(); if (list == null) { list = new RNDStr(thread, ruby, ss); } else if (toklen() > 0) { RNode.list_append(thread, list, new RNStr(thread, ruby, ss)); } newtok(); switch (c) { case '$': tokadd('$'); c = nextc(); if (c == -1) return new RNEOF(); switch (c) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': while (Char.IsDigit((char)c)) { tokadd(c); c = nextc(); } pushback(c); goto fetch_id; case '&': case '+': case '_': case '~': case '*': case '$': case '?': case '!': case '@': case ',': case '.': case '=': case ':': case '<': case '>': case '\\': refetch: tokadd(c); goto fetch_id; default: if (c == term) { RNode.list_append(thread, list, new RNStr(thread, ruby, "#$")); pushback(c); newtok(); return list; } switch (c) { case '\"': case '/': case '\'': case '`': goto refetch; } if (!is_identchar(c)) { parser.yyerror("bad global variable in string"); newtok(); return list; } break; } while (is_identchar(c)) { tokadd(c); /* if (ismbchar(c)) { int i, len = mbclen(c)-1; for (i = 0; i < len; i++) { c = nextc(); tokadd(c); } } */ c = nextc(); } pushback(c); break; case '@': tokadd(c); c = nextc(); if (c == '@') { tokadd(c); c = nextc(); } while (is_identchar(c)) { tokadd(c); /* if (ismbchar(c)) { int i, len = mbclen(c)-1; for (i = 0; i < len; i++) { c = nextc(); tokadd(c); } } */ c = nextc(); } pushback(c); break; case '{': if (c == '{') brace = '}'; nest = 0; do { loop_again: c = nextc(); switch (c) { case -1: if (nest > 0) { parser.yyerror("bad substitution in string"); newtok(); return list; } return new RNEOF(); case '}': if (c == brace) { if (nest == 0) break; nest--; } tokadd(c); goto loop_again; case '\\': c = nextc(); if (c == -1) return new RNEOF(); if (c == term) { tokadd(c); } else { tokadd('\\'); tokadd(c); } break; case '{': if (brace != -1) nest++; goto case '`'; case '\"': case '/': case '`': if (c == term) { pushback(c); RNode.list_append(thread, list, new RNStr(thread, ruby, "#")); ruby.warn("bad substitution in string"); RNode.list_append(thread, list, new RNStr(thread, ruby, tok())); newtok(); return list; } goto default; default: tokadd(c); break; } } while (c != brace); break; } fetch_id: node = new RNEVStr(thread, ruby, tok()); RNode.list_append(thread, list, node); newtok(); return list; }
/// <summary> Build edges of the RGraphs /// This method create the edge of the RGraph and /// calculates the incompatibility and neighbourhood /// relationships between RGraph nodes. /// /// </summary> /// <param name="gr"> the rGraph /// </param> /// <param name="ac1"> Description of the first molecule /// </param> /// <param name="ac2"> Description of the second molecule /// </param> private static void arcConstructor(RGraph gr, IAtomContainer ac1, IAtomContainer ac2) { // each node is incompatible with himself for (int i = 0; i < gr.Graph.Count; i++) { RNode x = (RNode)gr.Graph[i]; SupportClass.BitArraySupport.Set(x.Forbidden, i); } IBond a1; IBond a2; IBond b1; IBond b2; IBond[] bondsA1 = ac1.Bonds; IBond[] bondsA2 = ac2.Bonds; gr.FirstGraphSize = ac1.getBondCount(); gr.SecondGraphSize = ac2.getBondCount(); for (int i = 0; i < gr.Graph.Count; i++) { RNode x = (RNode)gr.Graph[i]; // two nodes are neighbours if their adjacency // relationship in are equivalent in G1 and G2 // else they are incompatible. for (int j = i + 1; j < gr.Graph.Count; j++) { if (timeout > -1 && ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start) > timeout) { throw new CDKException("Timeout exceeded in getOverlaps"); } RNode y = (RNode)gr.Graph[j]; a1 = bondsA1[((RNode)gr.Graph[i]).RMap.Id1]; a2 = bondsA2[((RNode)gr.Graph[i]).RMap.Id2]; b1 = bondsA1[((RNode)gr.Graph[j]).RMap.Id1]; b2 = bondsA2[((RNode)gr.Graph[j]).RMap.Id2]; if (a2 is IQueryBond) { if (a1.Equals(b1) || a2.Equals(b2) || !queryAdjacency(a1, b1, a2, b2)) { SupportClass.BitArraySupport.Set(x.Forbidden, j); SupportClass.BitArraySupport.Set(y.Forbidden, i); } else if (hasCommonAtom(a1, b1)) { SupportClass.BitArraySupport.Set(x.Extension, j); SupportClass.BitArraySupport.Set(y.Extension, i); } } else { if (a1.Equals(b1) || a2.Equals(b2) || (!getCommonSymbol(a1, b1).Equals(getCommonSymbol(a2, b2)))) { SupportClass.BitArraySupport.Set(x.Forbidden, j); SupportClass.BitArraySupport.Set(y.Forbidden, i); } else if (hasCommonAtom(a1, b1)) { SupportClass.BitArraySupport.Set(x.Extension, j); SupportClass.BitArraySupport.Set(y.Extension, i); } } } } }
public List <RNode> Match() { int i = 0; try { for (i = 0; i < Points.Count - 1; ++i) { SocialCar.RoutePlanner.Routing.Nodes.Point StartPoint = new SocialCar.RoutePlanner.Routing.Nodes.Point(Points[i].Latitude, Points[i].Longitude); SocialCar.RoutePlanner.Routing.Nodes.Point FinishPoint = new SocialCar.RoutePlanner.Routing.Nodes.Point(Points[i + 1].Latitude, Points[i + 1].Longitude); DateTime StartingTime = DateTime.Now; int StartingTimeSinceMidnight = Globals.ConvertTimeToSeconds(StartingTime.ToString("HH:mm:ss")); float delta = 0.1f; RNode StartNode = null; RNode TargetNode = null; List <RNode> StartNodeList = new List <RNode> { }; List <RNode> TargetNodeList = new List <RNode> { }; StartNodeList = RoadNetwork.ResolvePoint(StartPoint, delta); TargetNodeList = RoadNetwork.ResolvePoint(FinishPoint, delta); if (StartNodeList.Count() > 0) { StartNode = StartNodeList.First(); } if (TargetNodeList.Count() > 0) { TargetNode = TargetNodeList.First(); } if ((StartNode != null) && (TargetNode != null)) { Router X = new Router(StartNode, TargetNode, string.Empty, StartingTimeSinceMidnight, TravelMode.Car, ObjFunction.Distance); X.Start(); if (X.Solution.Count() > 0) { foreach (Connection C in X.Solution) { MatchingSolution.AddLast((RNode)C.GetSource()); } MatchingSolution.AddLast((RNode)X.Solution.Last().GetDestination()); } } else { throw new Exception("Carpooling StartNode or EndNode are null"); } } //Init(); //RunDijkstra(); //CheckConnectivity(); } catch (Exception ex) { log.Error("ERROR: " + ex.Message); if (ex.InnerException != null) { log.Error("ERROR: " + ex.InnerException.Message); } log.Error("ERROR: " + ex.StackTrace); } return(MatchingSolution.ToList().Where(x => x != null).Distinct().ToList()); }
private void ProcessWay(XElement Way) { LinkedList <RNode> LstWayNodes = new LinkedList <RNode>(); // Get all nodes forming the way IEnumerable <XElement> wayNodes = Way.Elements("nd"); // Get way tags IEnumerable <XElement> wayTags = Way.Elements("tag"); // For each node in the way foreach (XElement wayNode in wayNodes) { long nodeID = long.Parse(wayNode.Attribute("ref").Value); RNode Node = null; // If the node doesn't exist create it else retrieve it. if (!RNodes.ContainsKey(nodeID)) { // Get node. Point P = OSMNodeElements[nodeID]; double lat = P.Latitude; double lng = P.Longitude; // Create an RNode. Node = Network.AddNode(nodeID, new Point(lat, lng)); RNodes.Add(nodeID, Node); LstWayNodes.AddLast(Node); } else { LstWayNodes.AddLast(RNodes[nodeID]); } } // Dictionary <string, string> Tags = new Dictionary <string, string>(); // Get way tags foreach (XElement Tag in wayTags) { string key = Tag.Attribute("k").Value.ToString(); string value = Tag.Attribute("v").Value.ToString(); Tags.Add(key, value); } // string oneway = null; if (Tags.ContainsKey("oneway")) { oneway = Tags["oneway"]; } // Create edges. RNode u, v; for (int i = 1; i < LstWayNodes.Count(); ++i) { u = LstWayNodes.ElementAt(i - 1); v = LstWayNodes.ElementAt(i); if (oneway == null || oneway == "no") { Network.AddConnection(u, v, true, false).CopyTags(Tags); Network.AddConnection(v, u, true, false).CopyTags(Tags); } else if (oneway == "yes") { Network.AddConnection(u, v, true, false).CopyTags(Tags); Network.AddConnection(v, u, true, true).CopyTags(Tags); } else if (oneway == "-1") { Network.AddConnection(v, u, true, false).CopyTags(Tags); Network.AddConnection(u, v, true, true).CopyTags(Tags); } } LstWayNodes.Clear(); }
//share 50 50 elements public SplitNodeResult <T> Split(RNode <T> overflowNode) { throw new NotImplementedException(); }
public RConnection AreConnected(RNode src, RNode dst) { //This returns null values (NULL => CRASH) if the carpooling waypoints are enabled return(RConnections.Values.Where(x => x.GetSource().Id == src.Id && x.GetDestination().Id == dst.Id).FirstOrDefault());; }