/// <summary> /// Gets possible inputs that allows for reaching the specified state from state 0 /// </summary> /// <param name="state">A LR state</param> /// <returns>A list of possible inputs for reaching the specified state</returns> public List <Phrase> GetInputsFor(State state) { List <Phrase> result = new List <Phrase>(); // for all paths from state 0 to the specified state foreach (ENode start in GetPathsTo(state)) { Phrase input = new Phrase(); ENode node = start; while (node.next != null) { Terminal terminal = node.transition as Terminal; if (terminal != null) { // this is terminal => simply add it to the input input.Append(terminal); } else { // this is a variable => try to decompose it BuildInput(input, node.transition as Variable, new Stack <RuleChoice>()); } node = node.next; } result.Add(input); } return(result); }
private void PrepareArrays() { GameObject go = GameObject.Find(PropertyName); if (go != null) { ENode eObject = go.GetComponent <ENode>(); int count = eObject._PastValues.Count; int nextIndex = (count - DataPoints); XValues[0] = nextIndex; Y1Values[0] = -1; nextIndex = (count - DataPoints) + (DataPoints - 1); XValues[DataPoints - 1] = nextIndex; Y1Values[DataPoints - 1] = 1; for (int i = 1; i < DataPoints - 1; i++) { nextIndex = (count - DataPoints) + i; XValues[i] = nextIndex; if (nextIndex < count && nextIndex >= 0) { Y1Values[i] = Convert.ToSingle(eObject._PastValues[nextIndex]); } else { Y1Values[i] = 0; } } } }
private double ClampToRange(double value, ENode range) { if (value < range.MinValue) { return(range.MinValue); } if (value > range.MaxValue) { return(range.MaxValue); } return(value); }
private void AddConnections() { foreach (Transform child in Container.transform) { ENode oc = child.gameObject.GetComponent <ENode>(); for (int i = 0; i < oc._SourceConnections.Count; i++) { AddConnection(oc._SourceConnections[i]); } for (int i = 0; i < oc._TargetConnections.Count; i++) { AddConnection(oc._TargetConnections[i]); } } }
public Cube(VNode _v0, VNode _v1, VNode _v2, VNode _v3, VNode _v4, VNode _v5, VNode _v6, VNode _v7, ENode _e0, ENode _e1, ENode _e2, ENode _e3, ENode _e4, ENode _e5, ENode _e6, ENode _e7, ENode _e8, ENode _e9, ENode _e10, ENode _e11) { v0 = _v0; v1 = _v1; v2 = _v2; v3 = _v3; v4 = _v4; v5 = _v5; v6 = _v6; v7 = _v7; e0 = _e0; e1 = _e1; e2 = _e2; e3 = _e3; e4 = _e4; e5 = _e5; e6 = _e6; e7 = _e7; e8 = _e8; e9 = _e9; e10 = _e10; e11 = _e11; vNodeArray[0] = v0; vNodeArray[1] = v1; vNodeArray[2] = v2; vNodeArray[3] = v3; vNodeArray[4] = v4; vNodeArray[5] = v5; vNodeArray[6] = v6; vNodeArray[7] = v7; eNodeArray[0] = e0; eNodeArray[1] = e1; eNodeArray[2] = e2; eNodeArray[3] = e3; eNodeArray[4] = e4; eNodeArray[5] = e5; eNodeArray[6] = e6; eNodeArray[7] = e7; eNodeArray[8] = e8; eNodeArray[9] = e9; eNodeArray[10] = e10; eNodeArray[11] = e11; }
void OnEnable() { if (Node == null) { Node = GetComponent <ENode>(); } if (Values.Count == 0) { Values = new List <ESpliterSlider>(); double count = Node._TargetConnections.Count; double startValue = 1; double splitValue = Math.Round(startValue / count, 2, MidpointRounding.AwayFromZero); double remainder = ((100 * startValue) % count) / 100; _ignoreSliderChanges = true; for (int i = 0; i < count; i++) { ESpliterSlider slider = new ESpliterSlider(Node._TargetConnections[i]); if (i == 0) { slider.Value.Value = splitValue + remainder; } else { slider.Value.Value = splitValue; } slider.oldValue = slider.Value.Value; startValue -= splitValue; slider.Value.Subscribe(_ => OnSliderValueChanged(slider)).AddTo(this); Values.Add(slider); } _ignoreSliderChanges = false; } else { _ignoreSliderChanges = true; for (int i = 0; i < Values.Count; i++) { ESpliterSlider ess = Values[i]; ess.Edge = Node._TargetConnections[i]; ess.Value.Subscribe(_ => OnSliderValueChanged(ess)).AddTo(this); } _ignoreSliderChanges = false; } }
void Start() { Debug.Log(test.Length); for (int i = 0; i < test.Length + 1; i++) { Debug.Log(i); } pos = transform.position; size = transform.localScale; v0 = new VNode(new Vector3(pos.x + (size.x / 2), pos.y - (size.y / 2), pos.z + (size.z / 2)), false); v1 = new VNode(new Vector3(pos.x - (size.x / 2), pos.y - (size.y / 2), pos.z + (size.z / 2)), false); v2 = new VNode(new Vector3(pos.x - (size.x / 2), pos.y + (size.y / 2), pos.z + (size.z / 2)), false); v3 = new VNode(new Vector3(pos.x + (size.x / 2), pos.y + (size.y / 2), pos.z + (size.z / 2)), false); v4 = new VNode(new Vector3(pos.x + (size.x / 2), pos.y - (size.y / 2), pos.z - (size.z / 2)), false); v5 = new VNode(new Vector3(pos.x - (size.x / 2), pos.y - (size.y / 2), pos.z - (size.z / 2)), false); v6 = new VNode(new Vector3(pos.x - (size.x / 2), pos.y + (size.y / 2), pos.z - (size.z / 2)), false); v7 = new VNode(new Vector3(pos.x + (size.x / 2), pos.y + (size.y / 2), pos.z - (size.z / 2)), false); e0 = new ENode(new Vector3(0, 0 - (size.y / 2), 0 + (size.z / 2))); e1 = new ENode(new Vector3(0 - (size.x / 2), 0, 0 + (size.z / 2))); e2 = new ENode(new Vector3(0, 0 + (size.y / 2), 0 + (size.z / 2))); e3 = new ENode(new Vector3(0 + (size.x / 2), 0, 0 + (size.z / 2))); e4 = new ENode(new Vector3(0, 0 - (size.y / 2), 0 - (size.z / 2))); e5 = new ENode(new Vector3(0 - (size.x / 2), 0, 0 - (size.z / 2))); e6 = new ENode(new Vector3(0, 0 + (size.y / 2), 0 - (size.z / 2))); e7 = new ENode(new Vector3(0 + (size.x / 2), 0, 0 - (size.z / 2))); e8 = new ENode(new Vector3(0 + (size.x / 2), 0 - (size.y / 2), 0)); e9 = new ENode(new Vector3(0 - (size.x / 2), 0 - (size.y / 2), 0)); e10 = new ENode(new Vector3(0 + (size.x / 2), 0 + (size.y / 2), 0)); e11 = new ENode(new Vector3(0 - (size.x / 2), 0 + (size.y / 2), 0)); mesh = new Mesh(); mf = GetComponent <MeshFilter>(); cube = new Cube(v0, v1, v2, v3, v4, v5, v6, v7, e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11); GenerateMesh(); }
/// <summary> /// Gets all the paths from state 0 to the specified one /// </summary> /// <param name="target">The target state</param> /// <returns>The paths</returns> private List <ENode> GetPathsTo(State target) { Dictionary <int, SortedList <int, ENode> > visited = new Dictionary <int, SortedList <int, ENode> >(); LinkedList <ENode> queue = new LinkedList <ENode>(); List <ENode> goals = new List <ENode>(); queue.AddFirst(new ENode(target, null, null)); while (queue.Count != 0) { ENode current = queue.First.Value; queue.RemoveFirst(); if (!inverseGraph.ContainsKey(current.state.ID)) { continue; } Dictionary <Symbol, List <State> > transitions = inverseGraph[current.state.ID]; foreach (Symbol s in transitions.Keys) { foreach (State previous in transitions[s]) { if (visited.ContainsKey(previous.ID)) { if (visited[previous.ID].ContainsKey(s.ID)) { continue; } } else { visited.Add(previous.ID, new SortedList <int, ENode>()); } ENode pnode = new ENode(previous, current, s); visited[previous.ID].Add(s.ID, pnode); if (previous.ID == 0) { goals.Add(pnode); } else { queue.AddLast(pnode); } } } } return(goals); }
/// <summary> /// Gets the states on all the paths to the specified target state /// </summary> /// <param name="target">The target state</param> /// <returns>The states on all the paths leading to the target state</returns> public List <List <State> > GetStatePathsTo(State target) { List <List <State> > result = new List <List <State> >(); foreach (ENode start in GetPathsTo(target)) { List <State> path = new List <State>(); ENode node = start; while (node.next != null) { path.Add(node.state); node = node.next; } result.Add(path); } return(result); }
public static void AddElement(SerializedProperty list, int index) { ENode objectComponent = list.serializedObject.targetObject as ENode; List <EEdge> _connections = GetParent(list) as List <EEdge>; EEdge connection = _connections[index]; connection.Index = index + 1; if (list.propertyPath == "_TargetConnections") { connection.SetSource(objectComponent); } else { connection.SetTarget(objectComponent); } GameMessage.Send <EEdgesRedrawAll>(message); }
public override void OnInspectorGUI() { ENode oc = (ENode)target; serializedObject.Update(); GUIContent addButtonContent = new GUIContent("PROCESS"); if (GUILayout.Button(addButtonContent, EditorStyles.miniButton)) { oc.Process(); } EditorGUILayout.PropertyField(serializedObject.FindProperty("_AutoTrigger")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_Name")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_Value")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_Delta")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_MinValue")); EditorGUILayout.PropertyField(serializedObject.FindProperty("_MaxValue")); EEditorUtility.Show(serializedObject.FindProperty("_SourceConnections"), EEditorUtilityOptions.Buttons | EEditorUtilityOptions.ListLabel); EEditorUtility.Show(serializedObject.FindProperty("_TargetConnections"), EEditorUtilityOptions.Buttons | EEditorUtilityOptions.ListLabel); //DrawDefaultInspector(); serializedObject.ApplyModifiedProperties(); }
void Start() { _node = gameObject.GetComponent <ENode>(); GameMessage.Listen <ClockTickMessage>(OnClockTick); }
/// <summary> /// Initializes this element /// </summary> /// <param name="state">The associated LR state</param> /// <param name="next">The next queue element</param> /// <param name="transition">The transition</param> public ENode(State state, ENode next, Symbol transition) { this.state = state; this.next = next; this.transition = transition; }
public void SetTarget(ENode node) { TargetFormula.Value = node.gameObject.name + "+1"; TargetName.Value = node.gameObject.name; Target = node; }
public void SetSource(ENode node) { SourceFormula.Value = node.gameObject.name + "-1"; SourceName.Value = node.gameObject.name; Source = node; }
private string Format(ENode node, EReceiver command, object data) { return($"[RECEIVED] To node: {node.ToString()} Cmd:{command.ToString()} Data: {data.ToString()}"); }