private void PropagateAggregateUpdate(IExecutionContext context, Tuple tuple, Fact aggregateFact) { if (aggregateFact != null) { MemoryNode.PropagateUpdate(context, tuple, aggregateFact); } }
public void MatchLeftJoinNode <T, TDiscard>(MemoryNode <Token <T, TDiscard> > start, Action <LeftJoinNode <T, TDiscard> > callback) where T : class { var locator = new LeftJoinNodeLocator <T, TDiscard>(this, start); locator.Find(callback); }
public MemoryGraphNode AddNamedNodeToGraph(MemoryNode memNode, bool copyOverload = false) { MemoryGraphNode mgn = new MemoryGraphNode(memNode); MemoryNodes.Add(mgn); //Debug.Log(mgn.UID); MemoryHash.Add(mgn.UID, mgn); if (memNode.MemoryType == MemoryType.Cue)// || (copyOverload && memNode.MemoryType != MemoryType.Location)) //Cues cannot have parent nodes. return mgn; //We can access related memories from high-level cues (e.g. Hammers, Villagers, Family etc.) //Here we either add a reference from the related cue to the object. //Or if this is the first object to have this high-level cue, we create the cue. for (int i = 0; i < memNode.RelatedCues.Length; i++) { MemoryGraphNode cueNode; //Debug.Log("Creating cue node: " + memNode.RelatedCues[i]); if (Contains(memNode.RelatedCues[i]) == false) cueNode = AddNamedNodeToGraph(new MemoryNode(memNode.RelatedCues[i], MemoryType.Cue)); else cueNode = GetNamedNodeFromGraph(memNode.RelatedCues[i]); AddDirectedEdge(cueNode, mgn, 11.0f, mgn.MemoryNode.GetInitialOpinion()); } return mgn; }
public void CompileFunctionCall(Source s, Parameter[] paramList, Expression[] args) { // Compile arguments while setting the 'out' flag when appropriate // The out-flag will suspend emitting of node reads for variables, fields and parameters var outNodes = new MemoryNode[args.Length]; for (int i = 0; i < args.Length; i++) { if (paramList[i].Modifier == ParameterModifier.Out) { outNodes[i] = CompileExpression(args[i], null, false, false); } else { CompileExpression(args[i]); } } // Go over out-nodes again and mark them as written foreach (var o in outNodes) { if (o == null) { continue; } EmitWriteNode(s, o); } }
private void IncreaseActivation(int rank, MemoryNode n, float activationAmount) { if (activationAmount < n.Activation) { n.Activation = ((float)(rank * n.Activation) + (n.Activation + activationAmount)) / (float)(rank + 1.0f); } }
public MemoryPattern RetrieveMemoryPattern(string keyword) { hashmap.Clear(); MemoryNode k = GetMemoryNodeByKeyword(keyword); if (k != null) { SpreadActivation(1, k, 0.5f); hashmap = hashmap.OrderByDescending(x => x.Activation).ToList(); float highestActivation = hashmap[0].Activation; List <MemoryNode> topN = new List <MemoryNode>(); int count = 1; foreach (MemoryNode node in hashmap) { if (node.Activation == highestActivation) { topN.Add(node); } else if (node.Activation < highestActivation && count < n) { count++; highestActivation = node.Activation; topN.Add(node); } else if (node.Activation < highestActivation && count >= n) { break; } } return(GetMatch(topN, keyword)); } return(null); }
public static bool Contains <TSource>(this ReadOnlyMemory <TSource> source, TSource value, IEqualityComparer <TSource> comparer) { var aggregate = new ContainsByComparer <TSource>(comparer, value); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public JoinNodeLocator(RuntimeConfigurator runtimeConfigurator, MemoryNode <T> left, MemoryNode <T> right) { _configurator = runtimeConfigurator; _left = left; _matchRight = node => MatchNode(node, right); _rightActivation = () => right as RightActivation <T>; }
public static bool All <TSource>(this ReadOnlyMemory <TSource> source, Func <TSource, bool> predicate) { var aggregate = new All <TSource, FuncToIFunc <TSource, bool> >(new FuncToIFunc <TSource, bool>(predicate)); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public static int Count <TSource>(this ReadOnlyMemory <TSource> source, Func <TSource, bool> predicate) { var aggregate = new CountIf <TSource>(predicate); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public static TResult Aggregate <TSource, TAccumulate, TResult>(this ReadOnlyMemory <TSource> source, TAccumulate seed, Func <TAccumulate, TSource, TAccumulate> func, Func <TAccumulate, TResult> resultSelector) { var aggregate = new FoldForward <TSource, TAccumulate>(func, seed); MemoryNode.ProcessMemory(source, ref aggregate); return(resultSelector(aggregate.GetResult())); }
public static TSource Aggregate <TSource>(this ReadOnlyMemory <TSource> source, Func <TSource, TSource, TSource> func) { var aggregate = new ReduceForward <TSource>(func); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public static HashSet <TSource> ToHashSet <TSource>(this ReadOnlyMemory <TSource> source, IEqualityComparer <TSource> comparer = null) { var aggregate = new ToHashSet <TSource>(comparer); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public void Clear( ) { forcelink = false; update_type = 0; baseline = EntityState.Empty; msgtime = 0; msg_origins[0] = Vector3.Zero; msg_origins[1] = Vector3.Zero; origin = Vector3.Zero; msg_angles[0] = Vector3.Zero; msg_angles[1] = Vector3.Zero; angles = Vector3.Zero; model = null; efrag = null; frame = 0; syncbase = 0; colormap = null; effects = 0; skinnum = 0; visframe = 0; dlightframe = 0; dlightbits = 0; trivial_accept = 0; topnode = null; }
public static TSource Single <TSource>(this ReadOnlyMemory <TSource> source) { var aggregate = new Single <TSource>(); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public override void PropagateUpdate(IExecutionContext context, List <Tuple> tuples) { if (_isSubnetJoin) { return; } var toUpdate = new TupleFactList(); var toRetract = new TupleFactList(); using (var counter = PerfCounter.Update(context, this)) { var joinedSets = JoinedSets(context, tuples); foreach (var set in joinedSets) { foreach (var fact in set.Facts) { if (MatchesConditions(context, set.Tuple, fact)) { toUpdate.Add(set.Tuple, fact); } else { toRetract.Add(set.Tuple, fact); } } } counter.AddInputs(tuples.Count); counter.AddOutputs(toUpdate.Count + toRetract.Count); } MemoryNode.PropagateRetract(context, toRetract); MemoryNode.PropagateUpdate(context, toUpdate); }
public static TSource SingleOrDefault <TSource>(this ReadOnlyMemory <TSource> source, Func <TSource, bool> predicate) { var aggregate = new SingleOrDefaultPredicate <TSource>(predicate); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public static Dictionary <TKey, TValue> ToDictionary <TSource, TKey, TValue>(this ReadOnlyMemory <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TValue> elementSelector, IEqualityComparer <TKey> comparer = null) { var aggregate = new ToDictionary <TSource, TKey, TValue>(keySelector, elementSelector, comparer); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public override void PropagateUpdate(IExecutionContext context, List <Tuple> tuples) { var toAssert = new TupleFactList(); var toUpdate = new TupleFactList(); var toRetract = new TupleFactList(); using (var counter = PerfCounter.Update(context, this)) { foreach (var tuple in tuples) { var fact = context.WorkingMemory.GetState <Fact>(this, tuple); if (fact != null) { UpdateBinding(context, tuple, fact, toUpdate, toRetract); } else { AssertBinding(context, tuple, toAssert); } } counter.AddItems(tuples.Count); } MemoryNode.PropagateRetract(context, toRetract); MemoryNode.PropagateUpdate(context, toUpdate); MemoryNode.PropagateAssert(context, toAssert); }
private void AddConnections(string keyword, List <string> keywords) { MemoryNode a = GetMemoryNodeByKeyword(keyword); if (a != null) { foreach (string k in keywords) { MemoryNode b = GetMemoryNodeByKeyword(k); if (b != null) { Connection newConnection = new Connection(b); Connection c = SearchForConnection(a, newConnection); if (c == null) { a.Connections.Add(newConnection); } else { c.IncreaseStrength(); } } } } }
public static bool Contains <TSource>(this ReadOnlyMemory <TSource> source, TSource value) { var aggregate = new Contains <TSource>(value); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public void PropagateUpdate(IExecutionContext context, List <Fact> facts) { var toUpdate = new List <Fact>(); var toRetract = new List <Fact>(); foreach (var fact in facts) { if (IsSatisfiedBy(context, fact)) { toUpdate.Add(fact); } else { toRetract.Add(fact); } } if (toUpdate.Count > 0) { foreach (var childNode in ChildNodes) { childNode.PropagateUpdate(context, toUpdate); } MemoryNode?.PropagateUpdate(context, toUpdate); } if (toRetract.Count > 0) { UnsatisfiedFactUpdate(context, toRetract); } }
public void Clear( ) { this.forcelink = false; this.update_type = 0; this.baseline = EntityState.Empty; this.msgtime = 0; this.msg_origins[0] = Vector3.Zero; this.msg_origins[1] = Vector3.Zero; this.origin = Vector3.Zero; this.msg_angles[0] = Vector3.Zero; this.msg_angles[1] = Vector3.Zero; this.angles = Vector3.Zero; this.model = null; this.efrag = null; this.frame = 0; this.syncbase = 0; this.colormap = null; this.effects = 0; this.skinnum = 0; this.visframe = 0; this.dlightframe = 0; this.dlightbits = 0; this.trivial_accept = 0; this.topnode = null; }
public string ColumnValue(object objNode, int columnNumber) { if (columnNumber >= 3) { return(""); } ITreeViewControllerNode treeNode = (ITreeViewControllerNode)objNode; if (treeNode.IsRootNode || treeNode.IsRefByNode) { return(""); } // Case 2 all other nodes. MemoryNode node = (MemoryNode)m_graph.GetNode(treeNode.m_nodeIdx, m_nodeStorage); if (columnNumber == 0) // Value { return("0x" + node.Address.ToString("x")); } else if (columnNumber == 1) // Size { return(node.Size.ToString()); // return "0x" + node.Size.ToString("x"); } else if (columnNumber == 2) // Type { var type = node.GetType(m_typeStorage); return(type.FullName); } return(""); }
public void MatchJoinNode <T>(MemoryNode <T> left, MemoryNode <T> right, Action <JoinNode <T> > callback) where T : class { var locator = new JoinNodeLocator <T>(this, left, right); locator.Find(callback); }
public static System.Linq.ILookup <TKey, TElement> ToLookup <TSource, TKey, TElement>(this ReadOnlyMemory <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, IEqualityComparer <TKey> comparer = null) { var aggregate = new ToLookup <TSource, TKey, TElement>(comparer, keySelector, elementSelector); MemoryNode.ProcessMemory(source, ref aggregate); return(aggregate.GetResult()); }
public override void PropagateUpdate(IExecutionContext context, IList <Tuple> tuples) { if (_isSubnetJoin) { return; } var joinedSets = JoinedSets(context, tuples); var toUpdate = new TupleFactList(); var toRetract = new TupleFactList(); foreach (var set in joinedSets) { foreach (var fact in set.Facts) { if (MatchesConditions(context, set.Tuple, fact)) { toUpdate.Add(set.Tuple, fact); } else { toRetract.Add(set.Tuple, fact); } } } MemoryNode.PropagateUpdate(context, toUpdate); MemoryNode.PropagateRetract(context, toRetract); }
public virtual void PropagateAssert(IExecutionContext context, List <Fact> facts) { var toAssert = new List <Fact>(); using (var counter = PerfCounter.Assert(context, this)) { foreach (var fact in facts) { if (IsSatisfiedBy(context, fact)) { toAssert.Add(fact); } } counter.AddInputs(facts.Count); counter.AddOutputs(toAssert.Count); } if (toAssert.Count > 0) { foreach (var childNode in ChildNodes) { childNode.PropagateAssert(context, toAssert); } MemoryNode?.PropagateAssert(context, toAssert); } }
/// <summary> /// Insert the memory node into the linked list. /// </summary> /// <param name="memoryNode"></param> /// <param name="unitCount"></param> public void Insert(MemoryNode memoryNode, uint unitCount) { Link(memoryNode); memoryNode.Stamp = uint.MaxValue; memoryNode.UnitCount = unitCount; Stamp++; }
public LeftJoinNodeLocator(RuntimeConfigurator runtimeConfigurator, MemoryNode <Token <T, TDiscard> > left) { _configurator = runtimeConfigurator; _left = left; _matchRight = MatchConstantNode; _rightActivation = _configurator.Constant <T>; }
private void PropagateAggregation(IExecutionContext context, Aggregation aggregation) { foreach (var aggregateList in aggregation.AggregateLists) { if (aggregateList.Count == 0) { continue; } switch (aggregateList.Action) { case AggregationAction.Added: MemoryNode.PropagateAssert(context, aggregateList); break; case AggregationAction.Modified: MemoryNode.PropagateUpdate(context, aggregateList); break; case AggregationAction.Removed: MemoryNode.PropagateRetract(context, aggregateList); break; } } }
private void GlueFreeBlocks() { MemoryNode memoryNode = new MemoryNode(LocalOffset, Memory); memoryNode.Stamp = 0; memoryNode.Next = MemoryNode.Zero; memoryNode.UnitCount = 0; MemoryNode memoryNode0; MemoryNode memoryNode1; MemoryNode memoryNode2; if (LowUnit != HighUnit) LowUnit[0] = 0; // Find all unused memory nodes. memoryNode1 = memoryNode; for (uint index = 0; index < IndexCount; index++) { while (MemoryNodes[index].Available) { memoryNode0 = MemoryNodes[index].Remove(); if (memoryNode0.UnitCount != 0) { while ((memoryNode2 = memoryNode0 + memoryNode0.UnitCount).Stamp == uint.MaxValue) { memoryNode0.UnitCount = memoryNode0.UnitCount + memoryNode2.UnitCount; memoryNode2.UnitCount = 0; } memoryNode1.Link(memoryNode0); memoryNode1 = memoryNode0; } } } // Coalesce the memory represented by the unused memory nodes. while (memoryNode.Available) { memoryNode0 = memoryNode.Remove(); uint unitCount = memoryNode0.UnitCount; if (unitCount != 0) { for (; unitCount > 128; unitCount -= 128, memoryNode0 += 128) MemoryNodes[IndexCount - 1].Insert(memoryNode0, 128); uint index = unitsToIndex[unitCount - 1]; if (indexToUnits[index] != unitCount) { uint unitCountDifference = unitCount - indexToUnits[--index]; MemoryNodes[unitCountDifference - 1].Insert(memoryNode0 + (unitCount - unitCountDifference), unitCountDifference); } MemoryNodes[index].Insert(memoryNode0, indexToUnits[index]); } } GlueCount = 1 << 13; }
/// <summary> /// Initialize or reset the memory allocator (so that the single, large array can be re-used without destroying /// and re-creating it). /// </summary> public void Initialize() { for (int index = 0; index < IndexCount; index++) { MemoryNodes[index] = new MemoryNode((uint)(NodeOffset + index * MemoryNode.Size), Memory); MemoryNodes[index].Stamp = 0; MemoryNodes[index].Next = MemoryNode.Zero; MemoryNodes[index].UnitCount = 0; } Text = Heap; uint difference = UnitSize * (AllocatorSize / 8 / UnitSize * 7); HighUnit = Heap + AllocatorSize; LowUnit = HighUnit - difference; BaseUnit = HighUnit - difference; GlueCount = 0; }
public MemoryGraphNode(MemoryNode memNode) { this.MemoryNode = memNode; //LastUpdated = Time.time; //LastActive = Time.time; IsActive = false; Neighbours = new List<MemoryGraphNode>(); MemStrengths = new List<float>(); OpinionStrengths = new List<float>(); PrimaryStrengths = new List<float>(); SecondaryStrengths = new List<float>(); }
internal void ForceDebugAllocation(MemoryNode memoryNode) { MemoryGraphNode mgn = new MemoryGraphNode(memoryNode); MemoryNodes.Add(mgn); }
internal float GetCueOpinion(MemoryNode memNode) { if(memNode.RelatedCues == null) return 0.0f; MemoryGraphNode cueNode = GetNamedNodeFromGraph(memNode.RelatedCues[0]); if (cueNode == null) return 0.0f; for (int j = 0; j < cueNode.Neighbours.Count; j++) if (cueNode.Neighbours[j].UID == memNode.UID) return cueNode.OpinionStrengths[j]; return 0.0f; }
internal void UpdateCueOpinion(MemoryNode memNode, float strengthFactor) { for (int i = 0; i < memNode.RelatedCues.Length; i++) { MemoryGraphNode cueNode = GetNamedNodeFromGraph(memNode.RelatedCues[i]); for (int j = 0; j < cueNode.Neighbours.Count; j++) { if (cueNode.Neighbours[j].UID == memNode.UID) { cueNode.StrengthenOpinion(j, strengthFactor); break; } } } }