private LogicNode CreateNode(ILogicNode parent, string name) { var node = new LogicNode(parent, name); _nodes.Add(name, node); return(node); }
public LogicNode(ILogicNode parentNode, string name) { Parent = parentNode; Name = name; _completeFactor = _ownFactor.CombineLatest(parentNode.CompleteFactor, (own, parent) => own * parent).ToReactiveProperty(); }
private int GetChildRecursive(ILogicNode child, int amount) { var children = GetChildren(child); if (!children.Any()) { return(1); } var hasGrandChildren = children.SelectMany(GetChildren).Any(); if (!hasGrandChildren) { return(amount + children.Count); } var leaves = 0; foreach (var grandChild in children) { leaves += GetChildRecursive(grandChild, amount); } return(amount + leaves); }
public Node(Vector2 position, float width, float height, GUIStyle nodeStyle, GUIStyle selectedStyle, GUIStyle inPointStyle, GUIStyle outPointStyle, Action <ConnectionPoint> onClickInPoint, Action <ConnectionPoint> onClickOutPoint, Action <Node> onClickRemoveNode, ILogicNode logicNode) { Rect = new Rect(position.x, position.y, width, height); Style = nodeStyle; InPoint = new ConnectionPoint(this, ConnectionPointType.In, inPointStyle, onClickInPoint); OutPoint = new ConnectionPoint(this, ConnectionPointType.Out, outPointStyle, onClickOutPoint); DefaultNodeStyle = nodeStyle; SelectedNodeStyle = selectedStyle; OnRemoveNode = onClickRemoveNode; _logicNode = logicNode; }
private Node CreateNode(ILogicNode logicNode, float parentXPos) { var leftGrandChildrenCombinedCount = _tree.LeftSiblingsLeafCount(logicNode); int hierarchyLevel = _tree.GetHierarchyLevel(logicNode); var nodePos = GetNodePosition(hierarchyLevel, leftGrandChildrenCombinedCount, parentXPos); var node = _createNode(nodePos, logicNode); node.Title = logicNode.Name; return(node); }
public int LeftSiblingsLeafCount(ILogicNode node) { var leftSiblings = GetLeftSiblings(node); var sum = 0; foreach (var leftSibling in leftSiblings) { int amount = 0; sum += GetChildRecursive(leftSibling, amount); } return(sum); }
public int GetHierarchyLevel(ILogicNode logicNode) { var node = logicNode; var sum = 0; while (node.Parent != null) { sum++; node = node.Parent; } return(sum); }
private bool Satisfied(ILogicNode source, ISet <string> checkedLiterals) { if (checkedLiterals.Contains(source.Id)) { return(_satisfiedLiterals.Contains(source.Id)); } var satisfied = false; checkedLiterals.Add(source.Id); if (source.Fact) { satisfied = true; } else if (source is ILiteralNode) { satisfied = _graph.Outgoing(source).Any(dependency => Satisfied(dependency, checkedLiterals)); } else if (source is IClauseNode) { var dependencies = _graph.Outgoing(source).ToList(); satisfied = dependencies.Count > 0 && dependencies.All(dependency => Satisfied(dependency, checkedLiterals)); } if (satisfied) { if (!_satisfiedLiterals.Contains(source.Id)) { var negatedNode = _graph.GetNode(new Literal(source.Id).NegatedValue()); if (negatedNode != null && _satisfiedLiterals.Contains(negatedNode.Id)) { throw new Exception("KB is inconsistent, both " + source.Id + " and " + negatedNode.Id + " are true"); } Console.WriteLine(source.Id + " is satisfied"); _satisfiedLiterals.Add(source.Id); } } else { Console.WriteLine(source.Id + " is not satisfied"); } return(satisfied); }
private void FactFlow(ILogicNode startNode) { if (startNode is ILiteralNode && _graph.OutDegree(startNode) == 1) { foreach (var node in _graph.Outgoing(startNode).Where(node => !node.Fact)) { if (node is ILiteralNode) { var negNode = _graph.GetNode(Negate(node.Id)); if (negNode.Fact) { throw new Exception("KB is inconsistent, " + node.Id + " and " + negNode.Id + " are both facts!"); } } node.Fact = true; FactFlow(node); } } foreach (var node in _graph.Incoming(startNode).Where(node => !node.Fact)) { if (node is IClauseNode) { if (_graph.Outgoing(node).All(dependency => dependency.Fact)) { node.Fact = true; FactFlow(node); } } else if (node is ILiteralNode && (_graph.OutDegree(node) == 1 || node.Id.Contains("|"))) { var negNode = _graph.GetNode(Negate(node.Id)); if (negNode.Fact) { throw new Exception("KB is inconsistent, " + node.Id + " and " + negNode.Id + " are both facts!"); } node.Fact = true; FactFlow(node); } } }
public LinearLowerLimit(ILogicNode nodeL, ILogicLeaf leafR) { this.Add(nodeL); this.Add(leafR); }
public LinearLowerLimit(ILogicNode node, int limit) { this.Add(node); this.Add(new LogicNodeLeaf(new LogicLeaf(new LogicResult(limit)))); }
private List <ILogicNode> GetAllSiblings(ILogicNode node) { return(GetChildren(node.Parent).Where(child => child != node).ToList()); }
private Node CreateNode(Vector2 pos, ILogicNode logicNode) { return(new Node(pos, 100, 100, _nodeStyle, _selectedNodeStyle, _inPointStyle, _outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode, logicNode)); }
// Add more constructors later public AbsoluteEqual(ILogicNode actual, ILogicLeaf expected, int penalty) { this.Add(actual); this.Add(new LogicNodeLeaf(expected)); this.Add(new LogicNodeLeaf(new LogicLeaf(new LogicResult(penalty)))); }
private List <ILogicNode> GetLeftSiblings(ILogicNode node) { var allSiblings = GetAllSiblings(node); return(allSiblings.Where(sibling => string.Compare(sibling.Name, node.Name, StringComparison.Ordinal) < 1).ToList()); }
public int GetLeftSiblingCount(ILogicNode node) { return(GetLeftSiblings(node).Count); }
public List <ILogicNode> GetChildren(ILogicNode parent) { return(_nodes.Select(kvp => kvp.Value).Where(node => (node.Parent == parent)).ToList()); }
public LogicBitwiseAndTrue(ILogicNode nodeL, ILogicLeaf leafR) { this.Add(nodeL); this.Add(new LogicNodeLeaf(leafR)); }
public LogicBitwiseAndTrue(ILogicNode node, int limit) { this.Add(node); this.Add(new LogicNodeLeaf(new LogicLeaf(new LogicResult(limit)))); }
public LinearEqual(ILogicNode nodeL, ILogicLeaf leafR) { this.Add(nodeL); this.Add(new LogicNodeLeaf(leafR)); }