Ejemplo n.º 1
0
        public void PostTransition(TransitionModel transition)
        {
            TransitionData data   = new TransitionData(_config);
            string         userid = User.FindFirstValue(ClaimTypes.NameIdentifier);

            data.MakeTransition(transition, userid);
        }
Ejemplo n.º 2
0
 public HiddenMarkovModel(RandomVariable priorDistribution,
         TransitionModel tm, SensorModel sm)
 {
     this.priorDistribution = priorDistribution;
     this._transitionModel = tm;
     this._sensorModel = sm;
 }
Ejemplo n.º 3
0
 public HiddenMarkovModel(RandomVariable priorDistribution,
                          TransitionModel tm, SensorModel sm)
 {
     this.priorDistribution = priorDistribution;
     this._transitionModel  = tm;
     this._sensorModel      = sm;
 }
Ejemplo n.º 4
0
        public virtual void load()
        {
            KaldiTextParser parser          = new KaldiTextParser(this.location);
            TransitionModel transitionModel = new TransitionModel(parser);

            this.senonePool = new KaldiGmmPool(parser);
            File              file              = new File(this.location, "phones.txt");
            InputStream       inputStream       = new URL(file.getPath()).openStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader    bufferedReader    = new BufferedReader(inputStreamReader);
            HashMap           hashMap           = new HashMap();
            string            text;

            while (null != (text = bufferedReader.readLine()))
            {
                string[] array = String.instancehelper_split(text, " ");
                if (Character.isLetter(String.instancehelper_charAt(array[0], 0)))
                {
                    hashMap.put(array[0], Integer.valueOf(Integer.parseInt(array[1])));
                }
            }
            this.contextIndependentUnits = new HashMap();
            this.hmmManager = new LazyHmmManager(parser, transitionModel, this.senonePool, hashMap);
            Iterator iterator = hashMap.keySet().iterator();

            while (iterator.hasNext())
            {
                string text2 = (string)iterator.next();
                Unit   unit  = this.unitManager.getUnit(text2, String.instancehelper_equals("SIL", text2));
                this.contextIndependentUnits.put(unit.getName(), unit);
                this.hmmManager.get(HMMPosition.__UNDEFINED, unit);
            }
            this.loadTransform();
            this.loadProperties();
        }
Ejemplo n.º 5
0
 public override void Initialize(UIType UIName)
 {
     base.Initialize(UIName);
     UnityTool.M_Debug("过渡场景游戏UI");
     m_userModel   = new TransitionModel(UIName);
     m_userView    = new TransitionView(m_userModel, m_RootUI);
     m_userControl = new TransitionControl(m_userModel, m_userView);
 }
Ejemplo n.º 6
0
 // Crea un problema partiendo de todos sus componentes
 public Problem(object iSetup, ApplicableOperatorsFunction aoFunction, TransitionModel tModel, GoalTest gTest, StepCostFunction scFunction)
 {
     this.InitialSetup = iSetup;
     this.ApplicableOperatorsFunction = aoFunction;
     this.TransitionModel             = tModel;
     this.GoalTest         = gTest;
     this.StepCostFunction = scFunction;
 }
Ejemplo n.º 7
0
 // Devuelve el modelo de transición, creándolo por primera vez si no existiera
 public static TransitionModel GetTransitionModel()
 {
     if (transitionModel == null)
     {
         transitionModel = new SlidingPuzzleResultFunction();
     }
     return(transitionModel);
 }
Ejemplo n.º 8
0
 public LazyHmmManager(KaldiTextParser parser, TransitionModel transitionModel, Pool senonePool, Map symbolTable)
 {
     this.transitionModel = transitionModel;
     this.senonePool      = senonePool;
     this.symbolTable     = symbolTable;
     parser.expectToken("ContextDependency");
     parser.getInt();
     parser.getInt();
     parser.expectToken("ToPdf");
     this.eventMap = this.parseEventMap(parser);
     parser.expectToken("EndContextDependency");
 }
Ejemplo n.º 9
0
 public TransitionFluent <TS, TT> TransitionTo(TS state)
 {
     currentTransition = Tuple.Create(currentState.Item1, state);
     if (!transitionModels.ContainsKey(currentTransition))
     {
         transitionModels[currentTransition] = new TransitionModel <TS, TT>(currentState.Item1,
                                                                            state);
         stateModels[currentState].Transitions[state] =
             new Transition <TS, TT>(transitionModels[currentTransition]);
     }
     return(this);
 }
Ejemplo n.º 10
0
        public void testTransitionModelGeneratesNewStateWhenGivenOldStateAndProbability()
        {
            TransitionModel tm       = rainman.transitionModel();
            String          oldState = HmmConstants.RAINING;
            String          state1   = tm.getStateForProbability(oldState, randomizer
                                                                 .nextDouble());
            String state2 = tm.getStateForProbability(oldState, randomizer
                                                      .nextDouble());

            Assert.AreEqual(state1, HmmConstants.RAINING);
            Assert.AreEqual(state2, HmmConstants.NOT_RAINING);
        }
Ejemplo n.º 11
0
        /*Asynchronously searches for a user at that index*/
        private async Task SearchIndexAsync(object sender, RoutedEventArgs e, int index)
        {
            //Onclick get the index
            await Task.Run(() =>             //Async
            {
                //Setting up the api method
                RestRequest request = new RestRequest("api/getvalues/" + index.ToString());
                IRestResponse resp  = client.Get(request);               //Uses Get over POST

                //JSON deserialiser to deserialize our object to the class we want

                //Async
                this.Dispatcher.Invoke(() =>
                {
                    if (resp.IsSuccessful)                                                                             //If the httpresponse was successful
                    {
                        TransitionModel transModel = JsonConvert.DeserializeObject <TransitionModel>(resp.Content);    //Contains a message and the dataintermed obj
                        DataIntermed dataIntermed  = JsonConvert.DeserializeObject <DataIntermed>(transModel.message); //Getting the dataintermed obj

                        //Setting the values in the gui
                        FNameBox.Text   = dataIntermed.fName;
                        LNameBox.Text   = dataIntermed.lName;
                        BalanceBox.Text = dataIntermed.bal.ToString("C");
                        AcctNoBox.Text  = dataIntermed.acctNo.ToString();
                        PinBox.Text     = dataIntermed.pin.ToString("D4");

                        /* Sourced from to figure out how to change byte array to bitmap
                         * https://stackoverflow.com/questions/21555394/how-to-create-bitmap-from-byte-array
                         *
                         */
                        Bitmap bmp;
                        using (var ms = new MemoryStream(dataIntermed.image))
                        {
                            bmp = new Bitmap(ms);
                        }

                        Photo.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    }
                    else                     //if the httpresponse isn't successful
                    {
                        string errmsg = resp.Content;
                        MessageBox.Show(errmsg);

                        AfterError();                        //dispaly in everyfield that the user input is wrong
                    }
                    //Go back from searching visual
                    ChangeUIElements(false);
                    ProgressBar.Visibility = Visibility.Hidden;
                    SearchBox.Visibility   = Visibility.Visible;
                });
            });
        }
Ejemplo n.º 12
0
        public GlobalTransitionFluent <TS, TT> GlobalTransitionTo(TS state)
        {
            currentGlobalTransition = Tuple.Create(state);
            if (globalTransitionModels.ContainsKey(currentGlobalTransition))
            {
                return(this);
            }

            globalTransitionModels[currentGlobalTransition] = new TransitionModel <TS, TT>(startState, state);
            FsmModel.GlobalTransitions[state] =
                new Transition <TS, TT>(globalTransitionModels[currentGlobalTransition]);
            return(this);
        }
Ejemplo n.º 13
0
        /*Asynchronously searching for someone with that last name*/
        private async Task SearchNameAsync(object sender, RoutedEventArgs e)
        {
            SearchData mySearch = new APIClasses.SearchData();

            mySearch.searchStr = SearchBox.Text.ToUpper();

            ProgressBar.Visibility = Visibility.Visible;
            ChangeUIElements(true);
            await Task.Run(() =>
            {
                RestRequest request = new RestRequest("api/search");
                request.AddJsonBody(mySearch);
                //Do the request
                IRestResponse resp = client.Post(request);
                this.Dispatcher.Invoke(() =>
                {
                    if (resp.IsSuccessful)                    //IF that name exists in the database
                    {
                        TransitionModel transModel = JsonConvert.DeserializeObject <TransitionModel>(resp.Content);
                        DataIntermed dataIntermed  = JsonConvert.DeserializeObject <DataIntermed>(transModel.message);

                        /*Updating the users fields*/
                        FNameBox.Text   = dataIntermed.fName;
                        LNameBox.Text   = dataIntermed.lName;
                        BalanceBox.Text = dataIntermed.bal.ToString("C");                        //"C" so its in money form
                        AcctNoBox.Text  = dataIntermed.acctNo.ToString();
                        PinBox.Text     = dataIntermed.pin.ToString("D4");
                        IndexBox.Text   = dataIntermed.index.ToString();
                        Bitmap bmp;
                        using (var ms = new MemoryStream(dataIntermed.image))
                        {
                            bmp = new Bitmap(ms);
                        }
                        //Converting byte array to bitmap -> see below for reference
                        Photo.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        ChangeUIElements(false);
                        ProgressBar.Visibility = Visibility.Hidden;
                    }
                    else                     //If the response isn't successful
                    {
                        string errmsg = resp.Content;
                        MessageBox.Show(errmsg);
                        AfterError();
                    }
                    //Return ui back to normal
                    ChangeUIElements(false);
                    ProgressBar.Visibility = Visibility.Hidden;
                    SearchBox.Visibility   = Visibility.Visible;
                });
            });
        }
Ejemplo n.º 14
0
        private string GetNewWord(string word, TransitionModel transition)
        {
            var newWord = "";

            if (transition.Value != "ε")
            {
                newWord = word + transition.Value;
            }
            else
            {
                newWord = word;
            }
            return(newWord);
        }
Ejemplo n.º 15
0
        private void TryAddTransitionOnItself(AutomatonModel automaton, TransitionModel transition, string newWord)
        {
            var moreTransitions = automaton.Transitions.Where(
                x =>
                x.BeginState == x.EndState &&
                x.BeginState == transition.EndState);

            if (moreTransitions.Count() > 0)
            {
                foreach (var moreTransition in moreTransitions)
                {
                    _words.Add(GetNewWord(newWord, moreTransition));
                }
            }
        }
Ejemplo n.º 16
0
        // Construye un resolutor de dimensiones (rows) por (columns), como mínimo debe ser de 1x1
        // No necesita el puzle en sí, pues eso lo recibirá después
        public SlidingPuzzleSolver(uint rows, uint columns)
        {
            if (rows == 0)
            {
                throw new ArgumentException(string.Format("{0} is not a valid rows value", rows), "rows");
            }
            if (columns == 0)
            {
                throw new ArgumentException(string.Format("{0} is not a valid columns value", columns), "columns");
            }

            aoFunction = SlidingPuzzleFunctionFactory.GetApplicableOperatorsFunction();
            tModel     = SlidingPuzzleFunctionFactory.GetTransitionModel();
            gTest      = new SlidingPuzzleGoalTest(rows, columns);
        }
Ejemplo n.º 17
0
        public void MakeTransition(TransitionModel transition, string userId)
        {
            SqlDataAccess sql = new SqlDataAccess(_config);
            var           p   = new
            {
                UserId           = userId,
                WalletId         = transition.Wallet.Id,
                TransitionAmount = transition.Amount,
                TransitionDate   = transition.TransitionDate,
                TransitionType   = transition.TransitionType,
                ArticleId        = transition.Article.Id
            };

            sql.Execute("spTransitions_MakeTransitions", p, "FinAppData");
        }
Ejemplo n.º 18
0
        public ViewResult TestMap()
        {
            var transactionLines = from t in repository.Transitions
                                   join r1 in repository.Regions on t.RegionId1 equals r1.RegionId
                                   join r2 in repository.Regions on t.RegionId2 equals r2.RegionId
                                   select new TransitionLine {
                RegionName1        = t.RegionId1, X1 = r1.X, Y1 = r1.Y,
                RegionName2        = t.RegionId2, X2 = r2.X, Y2 = r2.Y,
                PermittedForPlayer = t.PermittedForPlayer
            };
            var data = new TransitionModel {
                Regions = repository.Regions, TransitionLines = transactionLines
            };

            return(View(data));
        }
Ejemplo n.º 19
0
        public async Task GetBalanceHistory_Success(TransitionModel model1, TransitionModel model2)
        {
            var list = new List <TransitionModel>()
            {
                model1, model2
            };

            _balanceManager.Setup(c => c.GetHistoryBalance(It.IsAny <int>())).ReturnsAsync(list);

            var response = await _controller.GetBalanceHistory() as OkObjectResult;

            var received = response.Value.AsSource().OfLikeness <List <TransitionModel> >();

            Assert.True(response.StatusCode == (int)HttpStatusCode.OK);
            Assert.True(received.Equals(list));
        }
Ejemplo n.º 20
0
        public HiddenMarkovModel GetModel(object owner, IContextLookup globalVars)
        {
            var randomVar  = StateVariable.GetRandomVariable(owner, globalVars);
            var transition = TransitionModel.GetMatrix();
            var sensor     = new HashMap();

            foreach (SensorMapRowInfo row in SensorModel)
            {
                var value        = row.Value.Evaluate(owner, globalVars);
                var distribution = row.SensorModel.GetMatrix();
                sensor.put(value, distribution);
            }
            var objPrior = Prior.GetMatrix();

            return(new HMM(randomVar, transition, sensor, objPrior));
        }
Ejemplo n.º 21
0
        private List <TransitionModel> ReadRegularAutomatonTransitions(GraphVizFileModel graphVizFileModel, int lower, int upper, AutomatonModel automaton)
        {
            var transitions = new List <TransitionModel>();

            for (int i = lower; i < upper; i++)
            {
                var transition = new TransitionModel();

                var transitionString = graphVizFileModel.Lines[i];
                var beginStateString = transitionString.Substring(0, transitionString.IndexOf(',')).Trim();
                var valueString      =
                    transitionString.Substring(transitionString.IndexOf(',') + 1, transitionString.IndexOf('-') - 2)
                    .Trim();
                var endStateString = transitionString.Substring(transitionString.IndexOf('>') + 1).Trim();

                foreach (var state in automaton.States)
                {
                    if (state.Name.Equals(beginStateString) && i == lower)
                    {
                        transition.BeginState = state;
                        state.IsInitial       = true;
                    }
                    else if (state.Name.Equals(beginStateString))
                    {
                        transition.BeginState = state;
                    }
                    if (state.Name.Equals(endStateString))
                    {
                        transition.EndState = state;
                    }
                    if (transition.BeginState != null && transition.EndState != null)
                    {
                        break;
                    }
                }
                valueString = valueString.ToLower();
                if (valueString.Equals("_"))
                {
                    valueString = "ε";
                }
                transition.Value = valueString;

                transitions.Add(transition);
            }
            return(transitions);
        }
Ejemplo n.º 22
0
        public async Task GetHistoryBalance_Success(TransitionModel model1, TransitionModel model2, int userId)
        {
            var list = new List <TransitionModel>()
            {
                model1, model2
            };

            _balanceRepository.Setup(c => c.GetBalanceHistory(userId)).ReturnsAsync(list);

            var result = await _manager.GetHistoryBalance(userId);

            var first = result.First();
            var last  = result.Last();

            Assert.True(result.Count == 2);
            Assert.True(last.ResultingBalance == list.First(c => last.TransitionId == c.TransitionId).Amount);
            Assert.True(first.ResultingBalance == list.Sum(c => c.Amount));
            Assert.True(result.First().CreationDate > last.CreationDate);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Implementation of the activity
        /// </summary>
        /// <param name="context">The context used to schedule</param>
        protected override HiddenMarkovModel Execute(CodeActivityContext context)
        {
            List <String>   statesList = States.ToList <String>();
            RandomVariable  prior      = new RandomVariable(statesList);
            TransitionModel tm         = new TransitionModel(States.ToList <String>());

            foreach (Triplet <string, string, double> transitionProbability in TransitionProbabilities)
            {
                tm.setTransitionProbability(transitionProbability.First, transitionProbability.Second, transitionProbability.Third);
            }

            SensorModel sm = new SensorModel(States.ToList <String>(), Perceptions.ToList <String>());

            foreach (Triplet <string, string, double> sensingProbability in SensingProbabilities)
            {
                sm.setSensingProbability(sensingProbability.First, sensingProbability.Second, sensingProbability.Third);
            }
            HiddenMarkovModel result = new HiddenMarkovModel(prior, tm, sm);

            return(result);
        }
        private AutomatonModel BuildAutomaton(NodeModel currentNode, NodeModel previousNode, StateModel leftState, StateModel rightState)
        {
            if (currentNode == null)
            {
                return(null);
            }

            #region dot
            if (currentNode.Value == Dot)
            {
                if (previousNode == null) //initial aut.
                {
                    var state1 = new StateModel {
                        IsInitial = true, IsFinal = false, Name = _stateCount++.ToString()
                    };
                    var state2 = new StateModel {
                        IsInitial = false, IsFinal = false, Name = _stateCount++.ToString()
                    };
                    var state3 = new StateModel {
                        IsInitial = false, IsFinal = true, Name = _stateCount++.ToString()
                    };

                    var dotAutomaton = new AutomatonModel()
                    {
                        States = { state1, state2, state3 },
                    };
                    _automaton = dotAutomaton;

                    if (IsOperandOrAsterix(currentNode.LeftChild.Value))
                    {
                        BuildAutomaton(currentNode.LeftChild, currentNode, state1, state2);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel
                        {
                            BeginState = state1, EndState = state2, Value = currentNode.LeftChild.Value
                        });
                    }

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, state2, state3);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel
                        {
                            BeginState = state2, EndState = state3, Value = currentNode.RightChild.Value
                        });
                    }
                }
                else
                {
                    var middleState = new StateModel {
                        Name = _stateCount++.ToString()
                    };
                    _automaton.States.Add(middleState);

                    if (IsOperandOrAsterix(currentNode.LeftChild.Value))
                    {
                        BuildAutomaton(currentNode.LeftChild, currentNode, leftState, middleState);
                    }
                    else
                    {
                        if (currentNode.LeftChild != null)
                        {
                            var trans = new TransitionModel
                            {
                                BeginState = leftState,
                                EndState   = middleState,
                                Value      = currentNode.LeftChild.Value
                            };
                            _automaton.Transitions.Add(trans);
                        }
                    }

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, middleState, rightState);
                    }
                    else // in the value
                    {
                        if (currentNode.RightChild != null)
                        {
                            var trans = new TransitionModel()
                            {
                                BeginState = middleState,
                                EndState   = rightState,
                                Value      = currentNode.RightChild.Value
                            };
                            _automaton.Transitions.Add(trans);
                        }
                    }
                }
            }
            #endregion

            #region asterix
            else if (currentNode.Value == Asterix)
            {
                if (previousNode == null) //initial aut.
                {
                    var state1 = new StateModel {
                        IsFinal = false, IsInitial = true, Name = _stateCount++.ToString()
                    };
                    var state2 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var state3 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var state4 = new StateModel {
                        IsFinal = true, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var trans1 = new TransitionModel {
                        BeginState = state1, EndState = state2, Value = "ε"
                    };
                    var trans3 = new TransitionModel {
                        BeginState = state3, EndState = state4, Value = "ε"
                    };
                    var trans4 = new TransitionModel {
                        BeginState = state1, EndState = state4, Value = "ε"
                    };
                    var trans5 = new TransitionModel {
                        BeginState = state3, EndState = state2, Value = "ε"
                    };

                    var asterixAutomaton = new AutomatonModel()
                    {
                        States      = { state1, state2, state3, state4 },
                        Transitions = { trans1, trans3, trans4, trans5 }
                    };
                    _automaton = asterixAutomaton;

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, state2, state3);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel()
                        {
                            BeginState = state2, EndState = state3, Value = currentNode.RightChild.Value
                        });
                    }
                }
                else
                {
                    var state1 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var state2 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var state3 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };
                    var state4 = new StateModel {
                        IsFinal = false, IsInitial = false, Name = _stateCount++.ToString()
                    };

                    var transLeftTo1 = new TransitionModel {
                        BeginState = leftState, EndState = state1, Value = "ε"
                    };
                    var trans4ToRight = new TransitionModel {
                        BeginState = state4, EndState = rightState, Value = "ε"
                    };
                    var trans1To2 = new TransitionModel {
                        BeginState = state1, EndState = state2, Value = "ε"
                    };
                    var trans1To4 = new TransitionModel {
                        BeginState = state1, EndState = state4, Value = "ε"
                    };
                    var trans3To2 = new TransitionModel {
                        BeginState = state3, EndState = state2, Value = "ε"
                    };
                    var trans3To4 = new TransitionModel {
                        BeginState = state3, EndState = state4, Value = "ε"
                    };

                    _automaton.States.Add(state1);
                    _automaton.States.Add(state2);
                    _automaton.States.Add(state3);
                    _automaton.States.Add(state4);

                    _automaton.Transitions.Add(transLeftTo1);
                    _automaton.Transitions.Add(trans4ToRight);
                    _automaton.Transitions.Add(trans1To2);
                    _automaton.Transitions.Add(trans1To4);
                    _automaton.Transitions.Add(trans3To2);
                    _automaton.Transitions.Add(trans3To4);

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, state2, state3);
                    }
                    else
                    {
                        if (currentNode.RightChild != null)
                        {
                            _automaton.Transitions.Add(new TransitionModel()
                            {
                                BeginState = state2,
                                EndState   = state3,
                                Value      = currentNode.RightChild.Value
                            });
                        }
                    }
                }
            }
            #endregion

            #region or
            else if (currentNode.Value == Or)
            {
                if (previousNode == null)
                {
                    var state1 = new StateModel {
                        IsInitial = true, IsFinal = false, Name = _stateCount++.ToString()
                    };
                    var state2 = new StateModel {
                        IsInitial = false, IsFinal = true, Name = _stateCount++.ToString()
                    };
                    var orAutomaton = new AutomatonModel
                    {
                        States = { state1, state2 }
                    };

                    _automaton = orAutomaton;

                    if (IsOperandOrAsterix(currentNode.LeftChild.Value))
                    {
                        BuildAutomaton(currentNode.LeftChild, currentNode, state1, state2);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel
                        {
                            BeginState = state1, EndState = state2, Value = currentNode.LeftChild.Value
                        });
                    }

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, state1, state2);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel
                        {
                            BeginState = state1, EndState = state2, Value = currentNode.RightChild.Value
                        });
                    }
                }
                else
                {
                    if (IsOperandOrAsterix(currentNode.LeftChild.Value))
                    {
                        BuildAutomaton(currentNode.LeftChild, currentNode, leftState, rightState);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel()
                        {
                            BeginState = leftState,
                            EndState   = rightState,
                            Value      = currentNode.LeftChild.Value
                        });
                    }

                    if (IsOperandOrAsterix(currentNode.RightChild.Value))
                    {
                        BuildAutomaton(currentNode.RightChild, currentNode, leftState, rightState);
                    }
                    else
                    {
                        _automaton.Transitions.Add(new TransitionModel()
                        {
                            BeginState = leftState,
                            EndState   = rightState,
                            Value      = currentNode.RightChild.Value
                        });
                    }
                }
            }
            #endregion

            return(_automaton);
        }
Ejemplo n.º 25
0
        public void ConvertNdfaToDfa_Test1()
        {
            //arrange
            DfaService dfaService = new DfaService();

            AutomatonModel ndfa = new AutomatonModel();

            StateModel stateA = new StateModel()
            {
                IsFinal = true, IsInitial = true, Name = "A"
            };
            StateModel stateB = new StateModel()
            {
                IsFinal = false, IsInitial = false, Name = "B"
            };
            StateModel stateC = new StateModel()
            {
                IsFinal = false, IsInitial = false, Name = "C"
            };
            StateModel stateD = new StateModel()
            {
                IsFinal = false, IsInitial = false, Name = "D"
            };

            ndfa.States.Add(stateA);
            ndfa.States.Add(stateB);
            ndfa.States.Add(stateC);
            ndfa.States.Add(stateD);

            TransitionModel trans1 = new TransitionModel()
            {
                BeginState = stateA, EndState = stateB, Value = "a"
            };
            TransitionModel trans2 = new TransitionModel()
            {
                BeginState = stateA, EndState = stateC, Value = "a"
            };
            TransitionModel trans3 = new TransitionModel()
            {
                BeginState = stateB, EndState = stateA, Value = "b"
            };
            TransitionModel trans4 = new TransitionModel()
            {
                BeginState = stateC, EndState = stateB, Value = "b"
            };
            TransitionModel trans5 = new TransitionModel()
            {
                BeginState = stateC, EndState = stateD, Value = "b"
            };
            TransitionModel trans6 = new TransitionModel()
            {
                BeginState = stateD, EndState = stateB, Value = "b"
            };

            ndfa.Transitions.Add(trans1);
            ndfa.Transitions.Add(trans2);
            ndfa.Transitions.Add(trans3);
            ndfa.Transitions.Add(trans4);
            ndfa.Transitions.Add(trans5);
            ndfa.Transitions.Add(trans6);

            ndfa.Alphabet.Add('a');
            ndfa.Alphabet.Add('b');

            int expected_nr_transitions     = 6;
            int expected_transitions_with_a = 3;
            int expected_transitions_with_b = 3;
            int expected_nr_states          = 4;

            //act
            var dfa = dfaService.ConvertNdfaToDfa(ndfa);

            int actual_nr_transitions     = dfa.Transitions.Count;
            int actual_transitions_with_a = dfa.Transitions.Where(t => t.Value == "a").ToList().Count;
            int actual_transitions_with_b = dfa.Transitions.Where(t => t.Value == "b").ToList().Count;
            int actual_nr_states          = dfa.States.Count;

            //assert
            Assert.AreEqual(expected_nr_states, actual_nr_states);
            Assert.AreEqual(expected_nr_transitions, actual_nr_transitions);
            Assert.AreEqual(expected_transitions_with_a, actual_transitions_with_a);
            Assert.AreEqual(expected_transitions_with_b, actual_transitions_with_b);
        }
Ejemplo n.º 26
0
        public void ConvertNdfaToDfa_Test2()
        {
            //arrange
            DfaService dfaService = new DfaService();

            AutomatonModel ndfa = new AutomatonModel();

            StateModel state1 = new StateModel()
            {
                IsFinal = false, IsInitial = true, Name = "1"
            };
            StateModel state2 = new StateModel()
            {
                IsFinal = false, IsInitial = false, Name = "2"
            };
            StateModel state3 = new StateModel()
            {
                IsFinal = true, IsInitial = false, Name = "3"
            };
            StateModel state4 = new StateModel()
            {
                IsFinal = false, IsInitial = false, Name = "4"
            };

            ndfa.States.Add(state1);
            ndfa.States.Add(state2);
            ndfa.States.Add(state3);
            ndfa.States.Add(state4);

            TransitionModel trans1 = new TransitionModel()
            {
                BeginState = state1, EndState = state2, Value = "a"
            };
            TransitionModel trans2 = new TransitionModel()
            {
                BeginState = state1, EndState = state4, Value = "c"
            };
            TransitionModel trans3 = new TransitionModel()
            {
                BeginState = state2, EndState = state1, Value = "ε"
            };
            TransitionModel trans4 = new TransitionModel()
            {
                BeginState = state2, EndState = state3, Value = "b"
            };
            TransitionModel trans5 = new TransitionModel()
            {
                BeginState = state3, EndState = state2, Value = "a"
            };
            TransitionModel trans6 = new TransitionModel()
            {
                BeginState = state4, EndState = state3, Value = "ε"
            };
            TransitionModel trans7 = new TransitionModel()
            {
                BeginState = state4, EndState = state3, Value = "c"
            };

            ndfa.Transitions.Add(trans1);
            ndfa.Transitions.Add(trans2);
            ndfa.Transitions.Add(trans3);
            ndfa.Transitions.Add(trans4);
            ndfa.Transitions.Add(trans5);
            ndfa.Transitions.Add(trans6);
            ndfa.Transitions.Add(trans7);

            ndfa.Alphabet.Add('a');
            ndfa.Alphabet.Add('b');
            ndfa.Alphabet.Add('c');

            int expected_nr_transitions     = 8;
            int expected_transitions_with_a = 4;
            int expected_transitions_with_b = 1;
            int expected_transitions_with_c = 3;
            int expected_nr_states          = 4;

            //act
            var dfa = dfaService.ConvertNdfaToDfa(ndfa);

            int actual_nr_transitions     = dfa.Transitions.Count;
            int actual_transitions_with_a = dfa.Transitions.Where(t => t.Value == "a").ToList().Count;
            int actual_transitions_with_b = dfa.Transitions.Where(t => t.Value == "b").ToList().Count;
            int actual_transitions_with_c = dfa.Transitions.Where(t => t.Value == "c").ToList().Count;
            int actual_nr_states          = dfa.States.Count;

            //assert
            Assert.AreEqual(expected_nr_states, actual_nr_states);
            Assert.AreEqual(expected_nr_transitions, actual_nr_transitions);
            Assert.AreEqual(expected_transitions_with_a, actual_transitions_with_a);
            Assert.AreEqual(expected_transitions_with_b, actual_transitions_with_b);
            Assert.AreEqual(expected_transitions_with_c, actual_transitions_with_c);
        }
Ejemplo n.º 27
0
 // Crea un problema partiendo de todos sus componentes, menos la función de coste de paso donde se usará una por defecto
 public Problem(object iSetup, ApplicableOperatorsFunction aoFunction, TransitionModel tModel, GoalTest gTest)
     : this(iSetup, aoFunction, tModel, gTest, new DefaultStepCostFunction())
 {
 }
Ejemplo n.º 28
0
 protected bool Equals(TransitionModel other)
 {
     return string.Equals(Identifier, other.Identifier);
 }
Ejemplo n.º 29
0
        private void FindNewTransitions(List <IntermediateDfaStateModel> stackHistory, AutomatonModel ndfa, AutomatonModel dfa, Dictionary <StateModel, List <StateModel> > stateToEpsilonN)
        {
            //check each transition in original automaton for each letter
            //beginstate must be in stackhistory and endstate is E*
            //then the transition is beginstate = stackhistory combined and end state is E*
            //there must be verified if the transition in the new automaton already exists
            foreach (var history in stackHistory)
            {
                foreach (var historyState in history.States)
                {
                    foreach (var transition in ndfa.Transitions)
                    {
                        foreach (var letter in ndfa.Alphabet)
                        {
                            if (historyState == transition.BeginState &&
                                transition.Value == letter.ToString())
                            {
                                var epsilonStates = stateToEpsilonN[transition.EndState];
                                if (history.States.Count == 1)
                                {
                                    if (historyState.IsInitial ||
                                        historyState.IsFinal)
                                    {
                                        var endStateName = "";
                                        foreach (var epsilonState in epsilonStates)
                                        {
                                            if (epsilonState == epsilonStates[epsilonStates.Count - 1])
                                            {
                                                endStateName += epsilonState.Name;
                                            }
                                            else
                                            {
                                                endStateName += epsilonState.Name + ",";
                                            }
                                        }
                                        var endState = new StateModel {
                                            Name = endStateName
                                        };

                                        var trans = new TransitionModel
                                        {
                                            BeginState = historyState,
                                            EndState   = endState,
                                            Value      = letter.ToString()
                                        };

                                        if (dfa.States.All(s => s.Name != historyState.Name))
                                        {
                                            dfa.States.Add(historyState);
                                        }
                                        if (dfa.States.All(s => s.Name != endState.Name))
                                        {
                                            dfa.States.Add(endState);
                                        }
                                        dfa.Transitions.Add(trans);
                                    }
                                }
                                else if (history.States.Count > 1)
                                {
                                    var beginStateName = "";
                                    foreach (var state in history.States)
                                    {
                                        if (state == history.States[history.States.Count - 1])
                                        {
                                            beginStateName += state.Name;
                                        }
                                        else
                                        {
                                            beginStateName += state.Name + ",";
                                        }
                                    }
                                    var beginState = new StateModel {
                                        Name = beginStateName
                                    };

                                    var endStateName = "";
                                    foreach (var epsilonState in epsilonStates)
                                    {
                                        if (epsilonState == epsilonStates[epsilonStates.Count - 1])
                                        {
                                            endStateName += epsilonState.Name;
                                        }
                                        else
                                        {
                                            endStateName += epsilonState.Name + ",";
                                        }
                                    }
                                    var endState = new StateModel {
                                        Name = endStateName
                                    };

                                    var trans = new TransitionModel
                                    {
                                        BeginState = beginState,
                                        EndState   = endState,
                                        Value      = letter.ToString()
                                    };
                                    if (dfa.States.All(s => s.Name != endState.Name))
                                    {
                                        dfa.States.Add(endState);
                                    }
                                    if (dfa.States.All(s => s.Name != beginState.Name))
                                    {
                                        dfa.States.Add(beginState);
                                    }
                                    dfa.Transitions.Add(trans);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private List <TransitionModel> ReadPdaTransitions(GraphVizFileModel graphVizFileModel, int lower, int upper, AutomatonModel automaton)
        {
            var transitions = new List <TransitionModel>();

            for (int i = lower; i < upper; i++)
            {
                var transition = new TransitionModel();

                var transitionString = graphVizFileModel.Lines[i];
                var beginStateString = transitionString.Substring(0, transitionString.IndexOf(',')).Trim();

                string valueString = "", leftStackString = "", rightStackString = "";
                if (transitionString.Contains("["))
                {
                    valueString =
                        transitionString.Substring(transitionString.IndexOf(',') + 1, transitionString.IndexOf('[') - 2)
                        .Trim();
                    leftStackString = transitionString.Substring(transitionString.IndexOf('[') + 1,
                                                                 transitionString.IndexOf(',')).ToLower();

                    rightStackString = transitionString.Substring(transitionString.IndexOf(',', transitionString.IndexOf(',') + 1) + 1, 1).ToLower();
                }
                else
                {
                    valueString =
                        transitionString.Substring(transitionString.IndexOf(',') + 1, transitionString.IndexOf(',') + 3)
                        .Trim();
                    leftStackString  = "_";
                    rightStackString = "_";
                }
                var endStateString = transitionString.Substring(transitionString.IndexOf('>') + 1).Trim();

                foreach (var state in automaton.States)
                {
                    if (state.Name.Equals(beginStateString) && i == lower)
                    {
                        transition.BeginState = state;
                        state.IsInitial       = true;
                    }
                    else if (state.Name.Equals(beginStateString))
                    {
                        transition.BeginState = state;
                    }
                    if (state.Name.Equals(endStateString))
                    {
                        transition.EndState = state;
                    }
                    if (transition.BeginState != null && transition.EndState != null)
                    {
                        break;
                    }
                }
                valueString = valueString.ToLower();
                if (valueString.Equals("_"))
                {
                    valueString = "ε";
                }
                if (leftStackString.Equals("_"))
                {
                    leftStackString = "ε";
                }
                if (rightStackString.Equals("_"))
                {
                    rightStackString = "ε";
                }

                transition.PushStack = rightStackString;
                transition.PopStack  = leftStackString;
                transition.Value     = valueString;
                transitions.Add(transition);
            }
            return(transitions);
        }
Ejemplo n.º 31
0
 public TransitionViewModel(TransitionModel model, SceneViewModel parent)
 {
     Model  = model;
     Parent = parent;
 }
Ejemplo n.º 32
0
        public void IsAcceptedStringByPda_Test()
        {
            //arrange
            string empty = "ε";

            LanguageCheckService languageCheckService = new LanguageCheckService();

            AutomatonModel pda = new AutomatonModel();

            StateModel stateS = new StateModel()
            {
                IsFinal   = true,
                IsInitial = true,
                Name      = "S"
            };

            pda.States.Add(stateS);

            TransitionModel transition1 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = "a", PopStack = empty, PushStack = "x"
            };
            TransitionModel transition2 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = "b", PopStack = empty, PushStack = "y"
            };
            TransitionModel transition3 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = "c", PopStack = "x", PushStack = empty
            };
            TransitionModel transition4 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = "d", PopStack = "y", PushStack = empty
            };
            TransitionModel transition5 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = empty, PopStack = "x", PushStack = empty
            };
            TransitionModel transition6 = new TransitionModel()
            {
                BeginState = stateS, EndState = stateS, Value = empty, PopStack = "y", PushStack = empty
            };

            pda.Transitions.Add(transition1);
            pda.Transitions.Add(transition2);
            pda.Transitions.Add(transition3);
            pda.Transitions.Add(transition4);
            pda.Transitions.Add(transition5);
            pda.Transitions.Add(transition6);

            pda.AccecptedStack.Add("x");
            pda.AccecptedStack.Add("y");

            pda.Alphabet.Add('a');
            pda.Alphabet.Add('b');
            pda.Alphabet.Add('c');
            pda.Alphabet.Add('d');

            var word1  = "";
            var word2  = "a";
            var word3  = "ac";
            var word4  = "b";
            var word5  = "bd";
            var word6  = "aacc";
            var word7  = "bbdd";
            var word8  = "bc";
            var word9  = "c";
            var word10 = "d";

            var expectedWord1  = false;
            var expectedWord2  = true;
            var expectedWord3  = true;
            var expectedWord4  = true;
            var expectedWord5  = true;
            var expectedWord6  = true;
            var expectedWord7  = true;
            var expectedWord8  = false;
            var expectedWord9  = false;
            var expectedWord10 = false;

            //act
            var actualWord1  = languageCheckService.IsAcceptedStringByPda(word1, pda);
            var actualWord2  = languageCheckService.IsAcceptedStringByPda(word2, pda);
            var actualWord3  = languageCheckService.IsAcceptedStringByPda(word3, pda);
            var actualWord4  = languageCheckService.IsAcceptedStringByPda(word4, pda);
            var actualWord5  = languageCheckService.IsAcceptedStringByPda(word5, pda);
            var actualWord6  = languageCheckService.IsAcceptedStringByPda(word6, pda);
            var actualWord7  = languageCheckService.IsAcceptedStringByPda(word7, pda);
            var actualWord8  = languageCheckService.IsAcceptedStringByPda(word8, pda);
            var actualWord9  = languageCheckService.IsAcceptedStringByPda(word9, pda);
            var actualWord10 = languageCheckService.IsAcceptedStringByPda(word10, pda);

            //assert
            Assert.AreEqual(expectedWord1, actualWord1);
            Assert.AreEqual(expectedWord2, actualWord2);
            Assert.AreEqual(expectedWord3, actualWord3);
            Assert.AreEqual(expectedWord4, actualWord4);
            Assert.AreEqual(expectedWord5, actualWord5);
            Assert.AreEqual(expectedWord6, actualWord6);
            Assert.AreEqual(expectedWord7, actualWord7);
            Assert.AreEqual(expectedWord8, actualWord8);
            Assert.AreEqual(expectedWord9, actualWord9);
            Assert.AreEqual(expectedWord10, actualWord10);
        }