/// <summary> /// Initializes this machine. /// </summary> /// <returns></returns> private static FiniteStateMachineState <MicroPlannerMessage> Initialize() { // generate states. List <FiniteStateMachineState <MicroPlannerMessage> > states = FiniteStateMachineState <MicroPlannerMessage> .Generate(3); // state 2 is final. states[2].Final = true; // 0 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 0, typeof(MicroPlannerMessageArc)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 1, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestRoundaboutEntry)); // 1 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 1, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestNonRoundaboutExit)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 1, typeof(MicroPlannerMessageArc), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestRoundaboutArc)); // 2 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 2, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestRoundaboutExit)); // return the start automata with intial state. return(states[0]); }
/// <summary> /// Initializes this machine. /// </summary> /// <returns></returns> private static FiniteStateMachineState <MicroPlannerMessage> Initialize() { // generate states. List <FiniteStateMachineState <MicroPlannerMessage> > states = FiniteStateMachineState <MicroPlannerMessage> .Generate(5); // state 3 is final. states[4].Final = true; // 0 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 1, typeof(MicroPlannerMessageArc)); // 1 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 0, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestNonSignificantTurn)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 2, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestSignificantTurn)); // 2 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 2, 3, typeof(MicroPlannerMessageArc), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestVeryShortArc)); // 3 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 3, 4, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestSignificantTurn)); // return the start automata with intial state. return(states[0]); }
public override FiniteStateMachineTransition <T> Build <T>(int targetIndex) { var transition = new FiniteStateMachineTransition <Gatherer> { Condition = FoundResourceTransition.Condition, TargetState = targetIndex }; return(transition as FiniteStateMachineTransition <T>); }
public override FiniteStateMachineTransition <T> Build <T>(int targetIndex) { var transition = new FiniteStateMachineTransition <Gatherer> { Condition = Inversed ? (Func <Gatherer, bool>)AlarmIsRaisedTransition.InversedCondition : AlarmIsRaisedTransition.Condition, TargetState = targetIndex }; return(transition as FiniteStateMachineTransition <T>); }
/// <summary> /// Initializes this machine. /// </summary> /// <returns></returns> private static FiniteStateMachineState <MicroPlannerMessage> Initialize() { // generate states. List <FiniteStateMachineState <MicroPlannerMessage> > states = FiniteStateMachineState <MicroPlannerMessage> .Generate(2); // state 2 is final. states[1].Final = true; // 0 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 0, typeof(MicroPlannerMessageArc)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 0, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestNonSignificantTurnNonPoi)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 1, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestPoi)); // return the start automata with intial state. return(states[0]); }
/// <summary> /// Builds the initial states. /// </summary> /// <returns></returns> protected override FiniteStateMachineState <MicroPlannerMessage> BuildStates() { // generate states. List <FiniteStateMachineState <MicroPlannerMessage> > states = FiniteStateMachineState <MicroPlannerMessage> .Generate(3); // state 3 is final. states[2].Final = true; // 0 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 0, 1, typeof(MicroPlannerMessageArc)); // 1 FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 1, typeof(MicroPlannerMessageArc)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 1, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestNonSignificantTurnNonPoi)); FiniteStateMachineTransition <MicroPlannerMessage> .Generate(states, 1, 2, typeof(MicroPlannerMessagePoint), new FiniteStateMachineTransitionCondition <MicroPlannerMessage> .FiniteStateMachineTransitionConditionDelegate(TestPoi)); // return the start automata with intial state. return(states[0]); }
//this function will sort the transitions in order of decreasing priority private void SortTransitions() { //insertion sort for the nodes. //for each node, we check the nodes before it until we have found one that is less than it. once this happens we remove the node from the position we were currently at if (transitions.Count <= 1) { return; } for (int i = 1; i < transitions.Count; i++) { int j = i; while (j > 0 && transitions[i].Priority > transitions[j].Priority) { j--; } ; FiniteStateMachineTransition temp = transitions[i]; transitions.RemoveAt(i); transitions.Insert(j, temp); } }