public static TransitionSet GetDefaultTransitionSet() { return (TransitionSet.FromRuleSet("Two shifts, 2 days off; No 2 nights in a row", new RuleSet() { InitialState = 1, AcceptingStates = new int[] { 1, 2, 3, 4, 5 }, Tuples = new[, ] { /* State 1 - either a day shift, a night shift or an off shift */ { 1, 1, 2 }, // d --> 2 { 1, 2, 3 }, // n --> 3 { 1, 3, 1 }, // o --> 1 /* State 2 - if day and night shift, go to 4 for two days off */ { 2, 1, 4 }, // d --> 4 { 2, 2, 4 }, // n --> 4 { 2, 3, 1 }, // o --> 1 /* State 3 - no night shift if had a night shift before, either day shift or off */ { 3, 1, 4 }, // d --> 4 { 3, 3, 1 }, // o --> 1 /* State 4 - only an off shift and continuing to another off */ { 4, 3, 5 }, // o --> 5 /* State 5 - another off shift and reset the cycle */ { 5, 3, 1 } // o --> 1 } })); }
private void OnTransitioning(object sender, bool transitioning) { var container = Container; if (container == null) { return; } if (!transitioning) { return; } #pragma warning disable CA2000 // Dispose objects before losing scope var trans = new TransitionSet(); trans.SetOrdering(TransitionOrdering.Together); trans.AddListener(new TransitionCompletion(this, container)); #pragma warning restore CA2000 // Dispose objects before losing scope foreach (var t in BuildTransitions(_transition?.Element)) { trans.AddTransition(t); } TransitionManager.BeginDelayedTransition(container, trans); }
private void OnTransitioning(object sender, bool transitioning) { var container = Container; if (container == null) { return; } if (!transitioning) { return; } var trans = new TransitionSet(); trans.SetOrdering(TransitionOrdering.Together); trans.AddListener(new TransitionCompletion(this, container)); foreach (var t in BuildTransitions(_transition?.Element)) { trans.AddTransition(t); } TransitionManager.BeginDelayedTransition(container, trans); }
// Update is called once per frame public virtual void CallUpdate(float _DeltaTime) { TransitionSet currentStateFuncs = null; m_Transitions.TryGetValue(m_CurrentValue, out currentStateFuncs); if (false == m_IsInTransition) { if (null != currentStateFuncs) { currentStateFuncs.OnUpdate(_DeltaTime); } } else { m_Transitions.TryGetValue(m_CurrentValue, out currentStateFuncs); if (null != currentStateFuncs) { currentStateFuncs.OnExit(); } m_PreviousValue = m_CurrentValue; m_CurrentValue = m_NextValue; m_Transitions.TryGetValue(m_CurrentValue, out currentStateFuncs); if (null != currentStateFuncs) { currentStateFuncs.OnEnter(); currentStateFuncs.OnUpdate(_DeltaTime); } m_IsInTransition = false; } }
/* You can build any transitions based on your business and add them to database, * Then use them later in your schedules as rules */ public static List <TransitionSet> GetDefaultTransitionSets() { return(new List <TransitionSet> { TransitionSet.FromRuleSet("Two shifts, 2 days off; No 2 nights in a row", new RuleSet() { InitialState = 1, AcceptingStates = new int[] { 1, 2, 3, 4, 5 }, Tuples = new[, ] { /* State 1 - either a day shift, a night shift or an off shift */ { 1, 1, 2 }, // d --> 2 { 1, 2, 3 }, // n --> 3 { 1, 3, 1 }, // o --> 1 /* State 2 - if day and night shift, go to 4 for two days off */ { 2, 1, 4 }, // d --> 4 { 2, 2, 4 }, // n --> 4 { 2, 3, 1 }, // o --> 1 /* State 3 - no night shift if had a night shift before, either day shift or off */ { 3, 1, 4 }, // d --> 4 { 3, 3, 1 }, // o --> 1 /* State 4 - only an off shift and continuing to another off */ { 4, 3, 5 }, // o --> 5 /* State 5 - another off shift and reset the cycle */ { 5, 3, 1 } // o --> 1 } }), TransitionSet.FromRuleSet("Three shifts, 1 day off; No 3 nights in a row", new RuleSet() { InitialState = 1, AcceptingStates = new int[] { 1, 2, 3, 4, 5, 6 }, Tuples = new[, ] { /* State 1 - either a day shift, a night shift or an off shift */ { 1, 1, 2 }, // d --> 2 { 1, 2, 3 }, // n --> 3 { 1, 3, 1 }, // o --> 1 /* State 2 - if day and night shift, go to 4 */ { 2, 1, 4 }, // d --> 4 { 2, 2, 4 }, // n --> 4 { 2, 3, 1 }, // o --> 1 /* State 3 - either a day shift, a night shift or an off shift */ { 3, 1, 4 }, // d --> 4 { 3, 2, 5 }, // n --> 5 { 3, 3, 1 }, // o --> 1 /* State 4 - any shift will go for an off day in 6 */ { 4, 1, 6 }, // d --> 6 { 4, 2, 6 }, // n --> 6 { 4, 3, 1 }, // o --> 1 /* State 5 - no night shift if had two night shift before */ { 5, 1, 6 }, // d --> 6 { 5, 3, 1 }, // o --> 1 /* State 6 - only an off shift and reset the cycle */ { 6, 3, 1 } // o --> 1 } }) }); }
/// <summary> /// Pops the top page from Navigator. /// </summary> /// <returns>The popped page.</returns> /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception> /// <since_tizen> 9 </since_tizen> public Page PopWithTransition() { if (!transitionFinished) { Tizen.Log.Error("NUI", "Transition is still not finished.\n"); return(null); } if (navigationPages.Count == 0) { throw new InvalidOperationException("There is no page in Navigator."); } var topPage = Peek(); if (navigationPages.Count == 1) { Remove(topPage); //Invoke Popped event Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage }); return(topPage); } var newTopPage = navigationPages[navigationPages.Count - 2]; //Invoke Page events newTopPage.InvokeAppearing(); topPage.InvokeDisappearing(); topPage.SaveKeyFocus(); transitionSet = CreateTransitions(topPage, newTopPage, false); transitionSet.Finished += (object sender, EventArgs e) => { Remove(topPage); topPage.SetVisible(true); // Need to update Content of the new page ShowContentOfPage(newTopPage); //Invoke Page events newTopPage.InvokeAppeared(); newTopPage.RestoreKeyFocus(); topPage.InvokeDisappeared(); //Invoke Popped event Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage }); }; transitionFinished = false; return(topPage); }
protected TransitionMonitor(TransitionSet tset, IGate pre, IGate post) { _transitions = tset; Name = "internal"; PreCondition = pre; PostCondition = post; }
/// <summary> /// Pushes a page to Navigator. /// If the page is already in Navigator, then it is not pushed. /// </summary> /// <param name="page">The page to push to Navigator.</param> /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception> /// <since_tizen> 9 </since_tizen> public void PushWithTransition(Page page) { if (!transitionFinished) { Tizen.Log.Error("NUI", "Transition is still not finished.\n"); return; } if (page == null) { throw new ArgumentNullException(nameof(page), "page should not be null."); } //Duplicate page is not pushed. if (navigationPages.Contains(page)) { return; } var topPage = Peek(); if (!topPage) { Insert(0, page); return; } navigationPages.Add(page); Add(page); page.Navigator = this; //Invoke Page events page.InvokeAppearing(); topPage.InvokeDisappearing(); topPage.SaveKeyFocus(); transitionSet = CreateTransitions(topPage, page, true); transitionSet.Finished += (object sender, EventArgs e) => { if (page is DialogPage == false) { topPage.SetVisible(false); } // Need to update Content of the new page ShowContentOfPage(page); //Invoke Page events page.InvokeAppeared(); page.RestoreKeyFocus(); topPage.InvokeDisappeared(); NotifyAccessibilityStatesChangeOfPages(topPage, page); }; transitionFinished = false; }
public virtual void TryAddTransitionSet(T _State, TransitionSet _Set) { if (!m_Transitions.ContainsKey(_State)) { m_Transitions.Add(_State, _Set); } else { m_Transitions[_State] = _Set; } }
public void TransitionSetConstructor() { tlog.Debug(tag, $"TransitionSetConstructor START"); var testingTarget = new TransitionSet(); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.Dispose(); tlog.Debug(tag, $"TransitionSetConstructor END (OK)"); }
public static TransitionSetDto FromEntity(TransitionSet input) { if (input == null) { return(null); } return(new TransitionSetDto { Id = input.Id, Name = input.Name }); }
/// <summary> /// Initializes a new instance. /// </summary> public Worker(int index, InvariantChecker context, StateStack stateStack, Func <RuntimeModel> createModel, int successorCapacity) { _index = index; _context = context; _createModel = createModel; _model = _createModel(); _stateStack = stateStack; var invariant = CompilationVisitor.Compile(_model.Formulas[0]); _transitions = new TransitionSet(_model, successorCapacity, invariant); }
private void PrepareTransitionSet(Event e) { // next state inference ... _tset = new TransitionSet(); _tset.AddRange(e.Triggers .SelectMany(t => t.Transitions) ); // set of modified variable indexes _modified = e.Triggers .SelectMany(t => t.ModifiedVariables) .Distinct() .Select(z => z.Index).ToList(); }
public void TransitionSetFinished() { tlog.Debug(tag, $"TransitionSetFinished START"); var testingTarget = new TransitionSet(); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.Finished += OnFinished; testingTarget.Finished -= OnFinished; testingTarget.Dispose(); tlog.Debug(tag, $"TransitionSetFinished END (OK)"); }
private IGate ReplaceTransitionVariablesHandler(TransitionSet tset, IGate q, bool value) { var result = q; if (result is IVariableCondition) { var vc = ((IVariableCondition)result); if (!tset.Contains(vc.Variable)) { result = Gate.Constant(value); } } return(result); }
public void TransitionSetDownCast() { tlog.Debug(tag, $"TransitionSetDownCast START"); using (TransitionSet transitionSet = new TransitionSet()) { var testingTarget = TransitionSet.DownCast(transitionSet); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.Dispose(); } tlog.Debug(tag, $"TransitionSetDownCast END (OK)"); }
/// <summary> /// Create a new schedule from a given day. /// Some demo settings are in place here. /// </summary> /// <param name="scheduleRequest">Parameters for the search</param> /// <returns>Scheduled shifts</returns> public async Task <ScheduleDto> GetNewScheduleAsync(ScheduleRequestDto scheduleRequest) { // Get team members from repository var teamMembers = await _employeeRepository.QueryNoTracking() .Where(w => w.IsActive) // Active ones for next schedule .OrderBy(c => new Random().Next()) // Shuffle staff order .Take(scheduleRequest.NumberOfEmployees) // we take a number from all employees in demo .ToListAsync(); // Get transition set rules from repository var transitionSet = await _transitionSetRepository.QueryNoTracking() .Where(w => w.Id == scheduleRequest.TransitionSetId && w.IsActive) // active transition set .FirstOrDefaultAsync(); // We only have that number of employees if (teamMembers.Count < scheduleRequest.NumberOfEmployees) { throw new ArgumentOutOfRangeException($"Invalid number of employees for scheduling."); } // Check we have the active transition set if (transitionSet == null) { throw new ArgumentOutOfRangeException($"Invalid transition set defined."); } var ruleSet = TransitionSet.FromRuleSetString(transitionSet.Name, transitionSet.RuleSetString).RuleSet; // Take 5 solutions as a demo result var schedules = await _teamShiftScheduler.CreateNewScheduleAsync(ruleSet, teamMembers, scheduleRequest.StartDate.Date, scheduleRequest.Days, scheduleRequest.TeamSize, scheduleRequest.MinShiftsPerCycle, scheduleRequest.StartHour, scheduleRequest.ShiftHours, 5); // Play with results for demo if (schedules.Count > 0) { return(ScheduleDto.FromEntity(schedules[new Random().Next(schedules.Count)], GetLatestStatistics())); } // Return default with statistics on model error return(new ScheduleDto() { Statistics = GetLatestStatistics(), Error = GetLatestError() }); // Or just return first. // return ScheduleToDto(schedules.FirstOrDefault()); }
public void TransitionSetConstructorWithTransitionSet() { tlog.Debug(tag, $"TransitionSetConstructorWithTransitionSet START"); using (TransitionSet transition = new TransitionSet()) { var testingTarget = new TransitionSet(transition); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.Dispose(); // disposed testingTarget.Dispose(); } tlog.Debug(tag, $"TransitionSetConstructorWithTransitionSet END (OK)"); }
// private void AddTransitions(TransitionSet transitionSet) { //Get the Id of the source morpheme for this set of transitions var sourceId = transitionSet.SourceId; //First add 1-1 transitions var singleTransitions = GetSingleTransitions(sourceId, transitionSet.Targets); _graph.AddEdges(singleTransitions); var groupTransitions = GetGroupTransitions(sourceId, transitionSet.TargetGroups); _graph.AddEdges(groupTransitions); var copyTransitions = GetCopyTransitions(sourceId, transitionSet.Copies); _graph.AddEdges(copyTransitions); }
public void TransitionSetAddTransition() { tlog.Debug(tag, $"TransitionSetAddTransition START"); View view = new View() { Name = "view", TransitionOptions = new TransitionOptions(Window.Instance) }; view.TransitionOptions.TransitionTag = "Transition"; view.TransitionOptions.EnableTransition = true; TransitionItemBase transitionItemBase = null; using (TimePeriod timePeriod = new TimePeriod(500)) { using (AlphaFunction alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default)) { transitionItemBase = new TransitionItemBase(view, true, timePeriod, alphaFunction); } } var testingTarget = new TransitionSet(); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.Finished += OnFinished; try { testingTarget.AddTransition(transitionItemBase); } catch (Exception e) { tlog.Error(tag, "Caught Exception" + e.ToString()); LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } view.Dispose(); transitionItemBase.Dispose(); testingTarget.Dispose(); tlog.Debug(tag, $"TransitionSetAddTransition END (OK)"); }
/// <summary> /// Pushes a page to Navigator. /// If the page is already in Navigator, then it is not pushed. /// </summary> /// <param name="page">The page to push to Navigator.</param> /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception> /// <since_tizen> 9 </since_tizen> public void PushWithTransition(Page page) { if (!transitionFinished) { Tizen.Log.Error("NUI", "Transition is still not finished.\n"); return; } if (page == null) { throw new ArgumentNullException(nameof(page), "page should not be null."); } //Duplicate page is not pushed. if (navigationPages.Contains(page)) { return; } var topPage = Peek(); if (!topPage) { Insert(0, page); return; } navigationPages.Add(page); Add(page); //Invoke Page events page.InvokeAppearing(); topPage.InvokeDisappearing(); transitionSet = CreateTransition(topPage, page, true); transitionSet.Finished += (object sender, EventArgs e) => { topPage.SetVisible(false); //Invoke Page events page.InvokeAppeared(); topPage.InvokeDisappeared(); }; transitionFinished = false; }
public void TransitionSetDownCastWithNullHandle() { tlog.Debug(tag, $"TransitionSetDownCastWithNullHandle START"); using (TransitionSet transitionSet = new TransitionSet()) { try { TransitionSet.DownCast(null); } catch (ArgumentNullException e) { tlog.Debug(tag, e.Message.ToString()); tlog.Debug(tag, $"TransitionSetDownCastWithNullHandle END (OK)"); Assert.Pass("Caught ArgumentNullException : Passed!"); } } }
public void TransitionSetSignalDisconnect() { tlog.Debug(tag, $"TransitionSetSignalDisconnect START"); View view = new View() { Name = "view", TransitionOptions = new TransitionOptions(Window.Instance) }; view.TransitionOptions.TransitionTag = "Transition"; view.TransitionOptions.EnableTransition = true; TransitionItemBase transitionItemBase = null; using (TimePeriod timePeriod = new TimePeriod(500)) { using (AlphaFunction alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default)) { transitionItemBase = new TransitionItemBase(view, true, timePeriod, alphaFunction); } } var testingTarget = new TransitionSet(); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); testingTarget.AddTransition(transitionItemBase); var transitionSetSignal = testingTarget.FinishedSignal(); Assert.IsNotNull(transitionSetSignal, "Should be not null!"); Assert.IsInstanceOf <TransitionSetFinishedSignal>(transitionSetSignal, "Should be an Instance of TransitionSet!"); dummyCallback callback = OnDummyCallback; transitionSetSignal.Connect(callback); transitionSetSignal.Disconnect(callback); view.Dispose(); testingTarget.Dispose(); tlog.Debug(tag, $"TransitionSetSignalDisconnect END (OK)"); }
/// <summary> /// Pops the top page from Navigator. /// </summary> /// <returns>The popped page.</returns> /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception> /// <since_tizen> 9 </since_tizen> public Page PopWithTransition() { if (!transitionFinished) { Tizen.Log.Error("NUI", "Transition is still not finished.\n"); return(null); } if (navigationPages.Count == 0) { throw new InvalidOperationException("There is no page in Navigator."); } var topPage = Peek(); if (navigationPages.Count == 1) { Remove(topPage); return(topPage); } var newTopPage = navigationPages[navigationPages.Count - 2]; // newTopPage.RaiseAbove(topPage); //Invoke Page events newTopPage.InvokeAppearing(); topPage.InvokeDisappearing(); transitionSet = CreateTransition(topPage, newTopPage, false); transitionSet.Finished += (object sender, EventArgs e) => { Remove(topPage); topPage.SetVisible(true); //Invoke Page events newTopPage.InvokeAppeared(); topPage.InvokeDisappeared(); }; transitionFinished = false; return(topPage); }
public void TransitionSetAssign() { tlog.Debug(tag, $"TransitionSetAssign START"); View view = new View() { Name = "view", TransitionOptions = new TransitionOptions(Window.Instance) }; view.TransitionOptions.TransitionTag = "Transition"; view.TransitionOptions.EnableTransition = true; TransitionItemBase transitionItemBase = null; using (TimePeriod timePeriod = new TimePeriod(500)) { using (AlphaFunction alphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default)) { transitionItemBase = new TransitionItemBase(view, true, timePeriod, alphaFunction); } } var transitionSet = new TransitionSet(); Assert.IsNotNull(transitionSet, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(transitionSet, "Should be an Instance of TransitionSet!"); transitionSet.AddTransition(transitionItemBase); var testingTarget = new TransitionSet(); var result = transitionSet.Assign(testingTarget); Assert.IsNotNull(result, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(result, "Should be an Instance of TransitionSet!"); view.Dispose(); transitionItemBase.Dispose(); testingTarget.Dispose(); tlog.Debug(tag, $"TransitionSetAssign END (OK)"); }
public void CalculateEffects() { _tset = new TransitionSet(); // overall precondition for the event var c = new TriggerTermCollection<bool>(true); foreach (var t in Triggers) { c.Add(t); // add to event wide transition set _tset.AddRange(t.Transitions); } var guards = new GuardCollection(); var before = new EffectsCollection(); var after = new EffectsCollection(); foreach (var t in Triggers) { foreach (var g in t.Guards) { guards.AddGuard(t, g); } foreach (var effect in t.Effects) { after.AddEffect(t, effect); } } guards.AddLeaveEffects(before); guards.AddEnterEffects(after); // make results visible EffectsBefore = before; EffectsAfter = after; PreCondition = c.PreCondition; }
/// <summary> /// Replaces composite state conditions with their elementary equivalents. /// </summary> /// <param name="e"></param> /// <param name="post"></param> /// <returns></returns> private IGate ReplaceVariableConditionHandler(TransitionSet tset, IGate e, bool post) { IGate result = e; if (e is IVariableCondition) { var c = (IVariableCondition)e; var tlist = tset.GetTransitions(c.Variable); var count = tlist.Count(); if (0 == count) { // no transitions for this variable, keep } else if (count > 1) { throw new CompilerException(ErrorCode.AmbigousPreCondition, "multiple transitions for variable '" + c.Variable + "'."); } else { // unique post state required var t = tlist.First(); var stateindexes = post ? t.NewStateIndexes : t.PreStateIndexes; if (stateindexes.Length != 1) { throw new CompilerException(ErrorCode.AmbigousPreCondition, "ambigous variable condition."); } // replace with elementary result = c.CreateElementaryCondition(stateindexes.First()); } } // Gate.TraceDecompose(e, result, "var repl {0}", post); return(result); }
private void AnimateButtonClick(object sender, EventArgs e) { _currentSceneNumber = _currentSceneNumber == 1 ? 2 : 1; var scene = _currentSceneNumber switch { 1 => _scene1, 2 => _scene2, _ => throw new NotImplementedException() }; var set = new TransitionSet(); set.AddTransition(new Explode()); set.AddTransition(new ChangeBounds()); set.AddTransition(new CustomTransition()); set.SetOrdering(TransitionOrdering.Together); set.SetDuration(500); set.SetInterpolator(new DecelerateInterpolator()); TransitionManager.Go(scene, set); }
public void TransitionSetDispose() { tlog.Debug(tag, $"TransitionSetDispose START"); var testingTarget = new TransitionSet(); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); try { testingTarget.Dispose(); } catch (Exception e) { tlog.Error(tag, "Caught Exception" + e.ToString()); LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"TransitionSetDispose END (OK)"); }
public TransitionCondition(ICondition lcond, ICondition rcond) { if (lcond.ContainsTransitions() || rcond.ContainsTransitions()) { throw new CompilerException(ErrorCode.BadCondition, "arguments to transition condition must not include transitions."); } // right hand must be a product var r = rcond.Decompose(ConditionMode.Static); if (r.Type == GateType.OR) { throw new CompilerException(ErrorCode.BadCondition, "right side of a transition must be a product."); } _rgate = r; var rvclist = r.GetVariableConditions().ToArray(); var l = lcond.Decompose(ConditionMode.Static); // split left side into terms ... IEnumerable <IGate> terms = new[] { l }; if (l.Type == GateType.OR) { terms = l.GetInputs(); } // construct the transition set from the left side terms and the right side product. var tset = BuildTransitionSet(terms, rvclist); Left = lcond; Right = rcond; Transitions = tset; }
public void TransitionSetFinishedSignal() { tlog.Debug(tag, $"TransitionSetFinishedSignal START"); using (View view = new View()) { var testingTarget = new TransitionSet(view.SwigCPtr.Handle, false); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <TransitionSet>(testingTarget, "Should be an Instance of TransitionSet!"); try { testingTarget.FinishedSignal(); } catch (Exception e) { tlog.Error(tag, "Caught Exception" + e.ToString()); LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } } tlog.Debug(tag, $"TransitionSetFinishedSignal END (OK)"); }
//Each TransitionSet has exactly one source morpheme which is added as a vertex to the graph private void AddNode(TransitionSet transitionSet) { _graph.AddVertex(new Vertex(transitionSet.SourceId, transitionSet.IsTerminal)); }
/// <summary> /// Creates a trigger based on another trigger, with new conditions. /// </summary> /// <param name="parent">The original trigger.</param> /// <param name="tset">The corresponding transition set.</param> /// <param name="pre">The precondition for the new trigger.</param> /// <param name="post">The postcondition for the new trigger.</param> protected Trigger(Trigger parent, TransitionSet tset, IGate pre, IGate post) : base(tset, pre, post) { Event = parent.Event; AddEffects(parent.Effects); }
/// <summary> /// Replaces composite state conditions with their elementary equivalents. /// </summary> /// <param name="e"></param> /// <param name="post"></param> /// <returns></returns> private IGate ReplaceVariableConditionHandler(TransitionSet tset, IGate e, bool post) { IGate result = e; if (e is IVariableCondition) { var c = (IVariableCondition)e; var tlist = tset.GetTransitions(c.Variable); var count = tlist.Count(); if(0 == count) { // no transitions for this variable, keep } else if (count > 1) { throw new CompilerException(ErrorCode.AmbigousPreCondition, "multiple transitions for variable '" + c.Variable + "'."); } else { // unique post state required var t = tlist.First(); var stateindexes = post ? t.NewStateIndexes : t.PreStateIndexes; if (stateindexes.Length != 1) { throw new CompilerException(ErrorCode.AmbigousPreCondition, "ambigous variable condition."); } // replace with elementary result = c.CreateElementaryCondition(stateindexes.First()); } } // Gate.TraceDecompose(e, result, "var repl {0}", post); return result; }
/// <summary> /// Replaces variables conditions in a gate with the pre or post conditions. /// </summary> /// <param name="e">The gate to replace.</param> /// <param name="post">True if the post condition shall be evaluated, false otherwise.</param> /// <returns>The resulting gate.</returns> private IGate ReplaceVariableCondition(TransitionSet tset, IGate e, bool post) { return e.Replace(g => ReplaceVariableConditionHandler(tset, g, post)); }
private IGate ReplaceTransitionVariablesHandler(TransitionSet tset, IGate q, bool value) { var result = q; if (result is IVariableCondition) { var vc = ((IVariableCondition)result); if (!tset.Contains(vc.Variable)) { result = Gate.Constant(value); } } return result; }
/// <summary> /// Replaces variable conditions refering to a transition set with constants. /// </summary> /// <param name="tset">The transition set.</param> /// <param name="gate">The gate to translate.</param> /// <param name="value"></param> /// <returns>The resulting modified gate.</returns> private IGate ReplaceTransitionVariables(TransitionSet tset, IGate gate, bool value) { return gate .Replace(g => ReplaceTransitionVariablesHandler(tset, g, value)) .Simplify(); }
/// <summary> /// Adds a trigger to the state machine. /// </summary> /// <param name="trigger">The trigger object to add.</param> public void AddTrigger(Trigger trigger) { var e = trigger.Event; SetModify(); try { TraceDependencies("add trigger '{0}' ...", trigger.Name); // ValidateTrigger(trigger); var tlist = new List<ProductTrigger>(); // examinate the precondition ... var precondition = trigger.PreCondition; if (precondition.Type == GateType.Fixed) { // constant if (precondition is FalseGate) { Trace("SMG033: warning: trigger '{0}' precondition is never met.", trigger); } else if (precondition is TrueGate) { Trace("SMG034: warning: trigger '{0}' precondition is always true.", trigger); tlist.Add(new ProductTrigger(trigger)); } } else if (precondition.Type == GateType.OR) { // OR combination, split into multiple simple triggers var inputs = precondition.GetInputs(); TraceDependencies("split trigger [{0}] into its branches ...", inputs.ToSeparatorList()); // analyze conditions // TraceDependencies("{0}", trigger.Transitions.ToDebugString()); // split into multiple triggers foreach (var product in inputs) { // extract the transition subset for the guard condition var tset = new TransitionSet(trigger.Transitions, product); TraceDependencies(" transition set of branch [{0}]: {1}", product, tset.ToDebugString()); var pre = ReplaceVariableCondition(tset, product, false); var post = ReplaceVariableCondition(tset, product, true); TraceDependencies(" branch conditions [{0} => {1}].", pre, post); // add branch trigger tlist.Add(new ProductTrigger(trigger, tset, pre, post)); } } else { // add original trigger tlist.Add(new ProductTrigger(trigger)); } // process resulting triggers foreach (var t1 in tlist) { TraceDependencies("product trigger {0} ...", t1); TraceDependencies(" conditions [{0}, {1}] ...", t1.PreCondition, t1.PostCondition); TraceDependencies(" transitions {0}", trigger.Transitions.ToDebugString()); t1.Qualify(); // check if any existing trigger is conflicting foreach (var existingtrigger in e.Triggers) { // the new trigger precondition must not intersect any existing precondition var product = Gate.ComposeAND(existingtrigger.PreCondition, t1.PreCondition); product = ReplaceTransitionVariables(existingtrigger.Transitions, product, false); if (!product.IsFalse()) { throw new CompilerException(ErrorCode.AmbigousPreCondition, "ambigous transition conditions [" + existingtrigger.PreCondition + ", " + t1.PreCondition + "]."); } } e.Triggers.Add(t1); } } catch(CompilerException ex) { AddError(ex); } }
/// <summary> /// Create Transitions between currentTopPage and newTopPage /// </summary> /// <param name="currentTopPage">The top page of Navigator.</param> /// <param name="newTopPage">The new top page after transition.</param> /// <param name="pushTransition">True if this transition is for push new page</param> private TransitionSet CreateTransitions(Page currentTopPage, Page newTopPage, bool pushTransition) { currentTopPage.SetVisible(true); // Set Content visible because it was hidden by HideContentOfPage. (currentTopPage as ContentPage)?.Content?.SetVisible(true); newTopPage.SetVisible(true); // Set Content visible because it was hidden by HideContentOfPage. (newTopPage as ContentPage)?.Content?.SetVisible(true); List <View> taggedViewsInNewTopPage = new List <View>(); RetrieveTaggedViews(taggedViewsInNewTopPage, newTopPage, true); List <View> taggedViewsInCurrentTopPage = new List <View>(); RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage, true); List <KeyValuePair <View, View> > sameTaggedViewPair = new List <KeyValuePair <View, View> >(); foreach (View currentTopPageView in taggedViewsInCurrentTopPage) { bool findPair = false; foreach (View newTopPageView in taggedViewsInNewTopPage) { if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) && currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag) { sameTaggedViewPair.Add(new KeyValuePair <View, View>(currentTopPageView, newTopPageView)); findPair = true; break; } } if (findPair) { taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value); } } foreach (KeyValuePair <View, View> pair in sameTaggedViewPair) { taggedViewsInCurrentTopPage.Remove(pair.Key); } TransitionSet newTransitionSet = new TransitionSet(); foreach (KeyValuePair <View, View> pair in sameTaggedViewPair) { TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value, pushTransition); if (pair.Value.TransitionOptions?.TransitionWithChild ?? false) { pairTransition.TransitionWithChild = true; } newTransitionSet.AddTransition(pairTransition); } newTransitionSet.Finished += (object sender, EventArgs e) => { if (newTopPage.Layout != null) { newTopPage.Layout.RequestLayout(); } if (currentTopPage.Layout != null) { currentTopPage.Layout.RequestLayout(); } transitionFinished = true; InvokeTransitionFinished(); transitionSet.Dispose(); }; if (!pushTransition || newTopPage is DialogPage == false) { View transitionView = (currentTopPage is ContentPage) ? (currentTopPage as ContentPage).Content : (currentTopPage as DialogPage).Content; if (currentTopPage.DisappearingTransition != null && transitionView != null) { TransitionItemBase disappearingTransition = currentTopPage.DisappearingTransition.CreateTransition(transitionView, false); disappearingTransition.TransitionWithChild = true; newTransitionSet.AddTransition(disappearingTransition); } else { currentTopPage.SetVisible(false); } } if (pushTransition || currentTopPage is DialogPage == false) { View transitionView = (newTopPage is ContentPage) ? (newTopPage as ContentPage).Content : (newTopPage as DialogPage).Content; if (newTopPage.AppearingTransition != null && transitionView != null) { TransitionItemBase appearingTransition = newTopPage.AppearingTransition.CreateTransition(transitionView, true); appearingTransition.TransitionWithChild = true; newTransitionSet.AddTransition(appearingTransition); } } newTransitionSet.Play(); return(newTransitionSet); }
private TransitionSet BuildTransitionSet(IEnumerable<IGate> terms, IEnumerable<IVariableCondition> rvclist) { var tset = new TransitionSet(); var result = Gate.Constant(false); var staticvariables = new HashSet<int>(); foreach (var term in terms) { // populate a dictionary per variable factor var dict = new Dictionary<int, ConditionPair>(); // right sides first foreach (var right in rvclist) { dict.Add(right.Variable.Index, new ConditionPair { Right = right }); } foreach (var left in term.GetVariableConditions()) { ConditionPair cp; if(dict.TryGetValue(left.Variable.Index, out cp)) { // right side exists cp.Left = left; } else { dict.Add(left.Variable.Index, new ConditionPair { Left = left }); } } // evaluate new term var newterm = Gate.Constant(true); foreach(var p in dict.Values) { if(null == p.Left) { // right side factor not present on left side, move static condition newterm = Gate.ComposeAND(newterm, p.Right.Decompose()); } else if(null == p.Right) { // static condition newterm = Gate.ComposeAND(newterm, p.Left.Decompose()); } else if(p.Left.StateIndex == p.Right.StateIndex) { // no state change: static condition //newterm = Gate.ComposeAND(newterm, p.Left.Decompose()); throw new CompilerException(ErrorCode.BadCondition, "variable consition " + p.Left + " used on both sides of a transition."); } else { newterm = Gate.ComposeAND(newterm, p.Left.Decompose()); // add transition var x = new Transition(p.Left) { PreStateIndexes = new[] { p.Left.StateIndex }, NewStateIndexes = new[] { p.Right.StateIndex } }; tset.Add(x); } } result = Gate.ComposeOR(result, newterm); } _lgate = result; return tset; }
public static bool ContainsTransitions(this ICondition c) { var tset = new TransitionSet(c); return !tset.IsEmpty; }
/// <summary> /// Creates a trigger based on another trigger, with new conditions. /// </summary> /// <param name="parent">The original trigger.</param> /// <param name="tset">The corresponding transition set.</param> /// <param name="pre">The precondition for the new trigger.</param> /// <param name="post">The postcondition for the new trigger.</param> internal ProductTrigger(Trigger parent, TransitionSet tset, IGate pre, IGate post) : base(parent, tset, pre, post) { }