Ejemplo n.º 1
0
        internal void SetTree(ObjectFormulaTree tree,
                              bool next,
                              AssociatedAddition addition,
                              IList <IMeasurement> list)
        {
            string dn = "D" + symbol;

            this.tree = tree;
            IDistribution d = DeltaFunction.GetDistribution(tree);

            if (next)
            {
                if (d != null)
                {
                    temp = new FormulaMeasurementDerivationDistribution(tree, null, symbol, addition);
                }
                else
                {
                    temp = new FormulaMeasurementDerivation(tree, null, symbol, addition);
                }
                derivation = temp;
                list.Add(derivation);
                return;
            }
            if (d != null)
            {
                derivation = new FormulaMeasurementDistribution(tree, symbol, addition);
            }
            else
            {
                derivation = new FormulaMeasurement(tree, symbol, addition);
            }
            list.Add(derivation);
            return;
        }
Ejemplo n.º 2
0
    public void OutputUpdate()
    {
        try
        {
            tm = GameObject.FindGameObjectWithTag("GameController").GetComponent <TuringMachine>();

            index = int.Parse(GameObject.FindGameObjectWithTag("stateDisplay").GetComponent <TextMesh>().text);

            input = GameObject.FindGameObjectWithTag("readDisplay").GetComponent <TextMesh>().text;

            if (input.Equals(""))
            {
                df = tm.StateByIndex(index).LookForFunction('Ø');
            }
            else
            {
                df = tm.StateByIndex(index).LookForFunction(char.Parse(input));
            }

            if (df.getOutput().Equals('Ø'))
            {
                GetComponent <TextMesh>().text = "";
            }
            else
            {
                GetComponent <TextMesh>().text = df.getOutput() + "";
            }
        }
        catch { }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Iterates calculation of derivation
        /// </summary>
        /// <param name="next">The "next" msign</param>
        /// <param name="addition">Associated addition</param>
        /// <returns>Next derivation iteration</returns>
        public FormulaMeasurementDerivation Iterate(bool next, AssociatedAddition addition)
        {
            string             dn = "D" + name;
            ObjectFormulaTree  t  = tree.Derivation("d/dt");
            IDistribution      d  = DeltaFunction.GetDistribution(t);
            AssociatedAddition aa = FormulaMeasurementDerivation.Create(associated);

            if (next)
            {
                FormulaMeasurementDerivation der = null;
                if (d != null)
                {
                    der = new FormulaMeasurementDerivationDistribution(t, dn, aa);
                }
                else
                {
                    der = new FormulaMeasurementDerivation(t, dn, aa);
                }
                derivation = der;
                return(der);
            }
            if (d != null)
            {
                derivation = new FormulaMeasurementDistribution(t, dn, aa);
            }
            else
            {
                derivation = new FormulaMeasurement(t, dn, aa);
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates measure
        /// </summary>
        /// <param name="tree">Tree</param>
        /// <param name="n">Number of tree</param>
        /// <param name="name">Name</param>
        /// <param name="associated">Associated addition</param>
        /// <returns>Measurement</returns>
        public static FormulaMeasurement Create(ObjectFormulaTree tree, int n,
                                                string name, AssociatedAddition associated)
        {
            object ret = null;

            try
            {
                ret = tree.Result;
            }
            catch (Exception ex)
            {
                ex.ShowError(-1);
            }
            FormulaMeasurement fm;

            if (n == 0)
            {
                IDistribution d = DeltaFunction.GetDistribution(tree);
                if (d != null)
                {
                    return(new FormulaMeasurementDistribution(tree, name, associated));
                }
                fm     = new FormulaMeasurement(tree, name, associated);
                fm.ret = ret;
                return(fm);
            }
            string            dn = "D" + name;
            ObjectFormulaTree t  = tree.Derivation("d/dt");

            if (t == null)
            {
                throw new Exception("VariableMeasure.Derivation");
            }
            AssociatedAddition aa  = FormulaMeasurementDerivation.Create(associated);
            FormulaMeasurement der = Create(t, n - 1, dn, aa);

            fm = new FormulaMeasurementDerivation(tree, der, name, aa);
            try
            {
                fm.ret = t.Result;
            }
            catch (Exception exc)
            {
                exc.ShowError(10);
            }
            return(fm);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Calculates the difference between the first and last value of each time series element in a range vector, returning an instant vector with the given deltas and equivalent labels. The delta is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if the sample values are all integers.
 /// </summary>
 /// <returns></returns>
 public InstantVector Delta()
 {
     AddAction(DeltaFunction.Create());
     return(InstantVector.WithString(this));
 }
Ejemplo n.º 6
0
    public void LoadAllMachines(string description)
    {
        description = RemoveString(description, Environment.NewLine);
        description = RemoveString(description, "{");
        description = RemoveString(description, "\t");

        List <String> refine = new List <string>();

        foreach (String m in description.Split('}'))
        {
            if (m.Length > 1)
            {
                refine.Add(m);
            }
        }

        String[] allMachines = refine.ToArray();

        foreach (String m in allMachines)
        {
            String[] desc = m.Split('#');

            string   machineName = desc[0];
            Alphabet alph        = new Alphabet();
            string   mDesc       = desc[4];

            foreach (char c in desc[1])
            {
                alph.InsertSymbol(c);
            }

            int          nStates = int.Parse(desc[2]);
            List <State> states  = new List <State>();

            desc[4] = ReplaceString(desc[4], "def", ":");

            String[] rawDFunctions = desc[4].Split(':');

            for (int i = 0; i < rawDFunctions.Length; i++)
            {
                rawDFunctions[i] = RemoveString(rawDFunctions[i], " ");
            }

            foreach (string dFuncString in rawDFunctions)
            {
                List <DeltaFunction> functions = new List <DeltaFunction>();

                if (dFuncString.Length > 2)
                {
                    if (dFuncString.Contains("void"))
                    {
                        states.Add(new State());
                    }
                    else
                    {
                        string[] atomicFuncString = dFuncString.Split(';');

                        foreach (string function in atomicFuncString)
                        {
                            if (!function.Contains("void") && function.Length > 3)
                            {
                                string[]    aChar = function.Split(',');
                                List <char> fchar = new List <char>();

                                foreach (string s in aChar)
                                {
                                    if (s.Length == 1)
                                    {
                                        fchar.Add(char.Parse(s));
                                    }
                                }

                                DeltaFunction df = new DeltaFunction(fchar[0], fchar[1], fchar[2], int.Parse(fchar[3] + ""));

                                functions.Add(df);
                            }
                        }
                        states.Add(new State(functions));
                    }
                }
            }

            if (desc[2].Contains(","))
            {
                string[] finalStates = desc[2].Split(',');

                foreach (string s in finalStates)
                {
                    states[int.Parse(s)].DefineIdentity(Constants.FINAL);
                }
            }
            else
            {
                states[int.Parse(desc[2])].DefineIdentity(Constants.FINAL);
            }

            states[int.Parse(desc[1])].DefineInitial();

            names.Add(machineName);

            tms.Add(new MachineList(alph, states, machineName, mDesc));
        }
    }
Ejemplo n.º 7
0
    public ArrayList ProcessCell(State state, int index)
    {
        ArrayList  whatReturn = new ArrayList();
        GameObject cellTape   = GameObject.FindGameObjectWithTag("actualCell");

        if (state.HaveFunctions())
        {
            if (cellTape != null)
            {
                DeltaFunction df = state.LookForFunction(char.Parse(cellTape.GetComponent <TextMesh>().text));
                if (df != null)
                {
                    index = df.getNextState();
                    Utils.WriteOnDisplay("stateDisplay", index + "");
                    if (df.getOutput() == 'v')
                    {
                        try
                        {
                            Destroy(cellTape);
                        }
                        catch { }
                    }
                    else
                    {
                        cellTape.GetComponent <TextMesh>().text = df.getOutput() + "";
                    }

                    if (currentMoveMachineCoroutine != null)
                    {
                        StopCoroutine(currentMoveMachineCoroutine);
                    }

                    currentMoveMachineCoroutine = MoveMachine(df.getSide(), GameObject.FindGameObjectWithTag("TuringMachine").transform.position);
                    StartCoroutine(currentMoveMachineCoroutine);
                    whatReturn.Add(true);
                    whatReturn.Add(index);
                    return(whatReturn);
                }
            }
            else
            {
                DeltaFunction df = state.LookForFunction('v');
                if (df != null)
                {
                    index = df.getNextState();
                    Utils.WriteOnDisplay("stateDisplay", index + "");
                    if (df.getOutput() == 'v')
                    {
                        try
                        {
                            Destroy(cellTape);
                        }
                        catch { }

                        if (currentMoveMachineCoroutine != null)
                        {
                            StopCoroutine(currentMoveMachineCoroutine);
                        }

                        currentMoveMachineCoroutine = MoveMachine(df.getSide(), GameObject.FindGameObjectWithTag("TuringMachine").transform.position);
                        StartCoroutine(currentMoveMachineCoroutine);

                        whatReturn.Add(true);
                        whatReturn.Add(index);
                        return(whatReturn);
                    }
                    else
                    {
                        Utils.InstantiateCell(df.getOutput(), cellTapePrefab);

                        if (currentMoveMachineCoroutine != null)
                        {
                            StopCoroutine(currentMoveMachineCoroutine);
                        }

                        currentMoveMachineCoroutine = MoveMachine(df.getSide(), GameObject.FindGameObjectWithTag("TuringMachine").transform.position);
                        StartCoroutine(currentMoveMachineCoroutine);
                        whatReturn.Add(true);
                        whatReturn.Add(index);
                        return(whatReturn);
                    }
                }
                else
                {
                    whatReturn.Add(false);
                    whatReturn.Add(index);
                    return(whatReturn);
                }
            }
        }
        whatReturn.Add(false);
        whatReturn.Add(index);
        return(whatReturn);
    }
 void IDistribution.Reset()
 {
     DeltaFunction.Reset(tree);
 }