예제 #1
0
        /**
    * Create an instance for shifting sheets.
    *
    * For example, this will be called on {@link org.apache.poi.hssf.usermodel.HSSFWorkbook#setSheetOrder(String, int)}  
    */
        private FormulaShifter(int srcSheetIndex, int dstSheetIndex)
        {
            _externSheetIndex = _firstMovedIndex = _lastMovedIndex = _amountToMove = -1;

            _srcSheetIndex = srcSheetIndex;
            _dstSheetIndex = dstSheetIndex;
            _mode = ShiftMode.Sheet;
        }
 public TuringMachineProperties(int m, int n, int shiftLength, ShiftMode shiftMode, bool enabled, int heads)
 {
     M = m;
     N = n;
     ShiftLength = shiftLength;
     ShiftMode = shiftMode;
     Enabled = enabled;
     Heads = heads;
 }
예제 #3
0
        private FormulaShifter(int externSheetIndex, int firstMovedIndex, int lastMovedIndex, int amountToMove)
        {
            if (amountToMove == 0)
            {
                throw new ArgumentException("amountToMove must not be zero");
            }
            if (firstMovedIndex > lastMovedIndex)
            {
                throw new ArgumentException("firstMovedIndex, lastMovedIndex out of order");
            }
            _externSheetIndex = externSheetIndex;
            _firstMovedIndex = firstMovedIndex;
            _lastMovedIndex = lastMovedIndex;
            _amountToMove = amountToMove;
            _mode = ShiftMode.Row;

            _srcSheetIndex = _dstSheetIndex = -1;
        }
        public void UpdateImage(ShiftMode shiftMode)
        {
            Debug.Log("Image : " + _image.gameObject.name);

            Debug.Log("Updating image... Mode : " + shiftMode);

            switch (shiftMode)
            {
            case ShiftMode.None:
                _image.sprite = _keyboardSkin.Load <Sprite>(_keyboardObject.ImageKey);
                break;

            case ShiftMode.UppercaseSingle:
                _image.sprite = _keyboardSkin.Load <Sprite>(_keyboardObject.ImageToggledOnKey);
                break;

            case ShiftMode.UppercaseLock:
                _image.sprite = _keyboardSkin.Load <Sprite>(_keyboardObject.ImageCapsLockKey);
                break;
            }
        }
        public TuringMachineProperties(XmlElement xmlConfig)
        {
            Enabled = XmlUtils.TryGetValueAsBool(xmlConfig, "Enabled") ?? true;
            M = XmlUtils.GetValueAsInt(xmlConfig, "M");
            N = XmlUtils.TryGetValueAsInt(xmlConfig, "N") ?? -1;
            Heads = XmlUtils.TryGetValueAsInt(xmlConfig, "Heads") ?? 1;
            ShiftLength = XmlUtils.GetValueAsInt(xmlConfig, "ShiftLength");
            MinSimilarityToJump = XmlUtils.TryGetValueAsDouble(xmlConfig, "MinSimilarityToJump") ?? 0;

            string shiftModeStr = XmlUtils.TryGetValueAsString(xmlConfig, "ShiftMode");
            ShiftMode = shiftModeStr == null ? ShiftMode.Multiple : (ShiftMode) Enum.Parse(typeof(ShiftMode), shiftModeStr);

            string writeModeStr = XmlUtils.TryGetValueAsString(xmlConfig, "WriteMode");
            WriteMode = writeModeStr == null ? WriteMode.Interpolate : (WriteMode) Enum.Parse(typeof(WriteMode), writeModeStr);

            InitalizeWithGradient = XmlUtils.TryGetValueAsBool(xmlConfig, "InitalizeWithGradient") ?? false;

            InitalValue = XmlUtils.TryGetValueAsDouble(xmlConfig, "InitalValue") ?? 0;

            UseMemoryExpandLocation = XmlUtils.TryGetValueAsBool(xmlConfig, "UseMemoryExpandLocation") ?? false;
            DidWriteThreshold = XmlUtils.TryGetValueAsDouble(xmlConfig, "DidWriteThreshold") ?? 0.9d;
        }
예제 #6
0
    /// <summary>
    /// Adds a character to the target input field.
    /// Is called when a key is pressed.
    /// </summary>
    private void Write(string keyName)
    {
        Debug.Log("[Keyboard] Writing '" + keyName + "'.");

        string initialContent = Target.text;

        if (_shiftMode != ShiftMode.None)
        {
            keyName = keyName.ToUpper();
        }

        string resultContent = initialContent + keyName;

        Target.text = resultContent;

        // Disable shift if it's in single uppercase letter mode (not caps lock)
        if (_shiftMode == ShiftMode.UppercaseSingle)
        {
            _shiftMode = ShiftMode.None;
            UpdateUppercase();
        }
    }
예제 #7
0
        public TuringMachineProperties(XmlElement xmlConfig)
        {
            Enabled             = XmlUtils.TryGetValueAsBool(xmlConfig, "Enabled") ?? true;
            M                   = XmlUtils.GetValueAsInt(xmlConfig, "M");
            N                   = XmlUtils.TryGetValueAsInt(xmlConfig, "N") ?? -1;
            Heads               = XmlUtils.TryGetValueAsInt(xmlConfig, "Heads") ?? 1;
            ShiftLength         = XmlUtils.GetValueAsInt(xmlConfig, "ShiftLength");
            MinSimilarityToJump = XmlUtils.TryGetValueAsDouble(xmlConfig, "MinSimilarityToJump") ?? 0;

            string shiftModeStr = XmlUtils.TryGetValueAsString(xmlConfig, "ShiftMode");

            ShiftMode = shiftModeStr == null ? ShiftMode.Multiple : (ShiftMode)Enum.Parse(typeof(ShiftMode), shiftModeStr);

            string writeModeStr = XmlUtils.TryGetValueAsString(xmlConfig, "WriteMode");

            WriteMode = writeModeStr == null ? WriteMode.Interpolate : (WriteMode)Enum.Parse(typeof(WriteMode), writeModeStr);

            InitalizeWithGradient = XmlUtils.TryGetValueAsBool(xmlConfig, "InitalizeWithGradient") ?? false;

            InitalValue = XmlUtils.TryGetValueAsDouble(xmlConfig, "InitalValue") ?? 0;

            UseMemoryExpandLocation = XmlUtils.TryGetValueAsBool(xmlConfig, "UseMemoryExpandLocation") ?? false;
            DidWriteThreshold       = XmlUtils.TryGetValueAsDouble(xmlConfig, "DidWriteThreshold") ?? 0.9d;
        }
        // Number of times each location was accessed during livetime of the tm
        // private List<int> _writeActivities = new List<int>();
        // private List<int> _readActivities = new List<int>();

        public MinimalTuringMachine(TuringMachineProperties props)
        {
            _enabled                 = props.Enabled;
            _m                       = props.M;
            _n                       = props.N;
            _heads                   = props.Heads;
            _shiftLength             = props.ShiftLength;
            _shiftMode               = props.ShiftMode;
            _writeMode               = props.WriteMode;
            _minSimilarityToJump     = props.MinSimilarityToJump;
            _tape                    = new List <double[]>();
            _initalizeWithGradient   = props.InitalizeWithGradient;
            _initalValue             = props.InitalValue;
            _didWriteThreshold       = props.DidWriteThreshold;
            _useMemoryExpandLocation = props.UseMemoryExpandLocation;

            Reset();

            _initialRead = new double[_heads][];
            for (int i = 0; i < _heads; i++)
            {
                _initialRead[i] = GetRead(i);
            }
        }
예제 #9
0
            /// <summary>
            /// Prints eigenvalues and eigenvectors of symmetric generalized eigen-problems.
            /// </summary>
            public static void Symmetric(SparseMatrix A, SparseMatrix B, SpectraResult result, ShiftMode mode)
            {
                if (!EnsureSuccess(result))
                {
                    return;
                }

                int n     = A.RowCount;
                int nconv = result.ConvergedEigenValues;

                Console.WriteLine();
                Console.WriteLine("Testing ARPACK++ class ARluSymGenEig");
                Console.WriteLine("Real symmetric generalized eigenvalue problem: A*x - lambda*B*x");
                Console.WriteLine();

                switch (mode)
                {
                case ShiftMode.None:
                    Console.WriteLine("Regular mode");
                    break;

                case ShiftMode.Regular:
                    Console.WriteLine("Shift and invert mode");
                    break;

                case ShiftMode.Buckling:
                    Console.WriteLine("Buckling mode");
                    break;

                case ShiftMode.Cayley:
                    Console.WriteLine("Cayley mode");
                    break;
                }

                Console.WriteLine();
                Console.WriteLine("Dimension of the system            : " + n);
                Console.WriteLine("Number of 'requested' eigenvalues  : " + result.Count);
                Console.WriteLine("Number of 'converged' eigenvalues  : " + nconv);
                Console.WriteLine("Number of Arnoldi vectors generated: " + result.ArnoldiCount);
                Console.WriteLine("Number of iterations taken         : " + result.IterationsTaken);
                Console.WriteLine();

                var evals = result.EigenValuesReal();
                var evecs = result.EigenVectorsReal();

                // Printing eigenvalues.

                Console.WriteLine("Eigenvalues:");

                for (int i = 0; i < nconv; i++)
                {
                    Console.WriteLine("  lambda[" + (i + 1) + "]: " + evals[i]);
                }

                Console.WriteLine();

                if (evecs != null)
                {
                    // Printing the residual norm || A*x - lambda*B*x ||
                    // for the nconv accurately computed eigenvectors.

                    var x = new double[n];
                    var y = new double[n];
                    var r = new double[nconv]; // residuals

                    for (int i = 0; i < nconv; i++)
                    {
                        var lambda = evals[i];

                        evecs.Column(i, x);

                        Vector.Copy(x, y);

                        // y = B*x
                        B.Multiply(x, y);

                        // y = A*x - lambda*B*x
                        A.Multiply(1.0, x, -lambda, y);

                        r[i] = Vector.Norm(y) / Math.Abs(lambda);
                    }

                    for (int i = 0; i < nconv; i++)
                    {
                        Console.WriteLine("||A*x(" + i + ") - lambda(" + i + ")*B*x(" + i + ")||: " + r[i]);
                    }

                    Console.WriteLine();
                }
            }
예제 #10
0
 private int ShiftID(int id, ShiftMode mode)
 {
     switch (mode)
     {
         case ShiftMode.Left:
             if (id % Tileset.TilesAcross == 0)
                 id += Tileset.TilesAcross;
             id--;
             break;
         case ShiftMode.Right:
             id++;
             if (id % Tileset.TilesAcross == 0)
                 id -= Tileset.TilesAcross;
             break;
         case ShiftMode.Up:
             id -= Tileset.TilesAcross;
             if (id < 0)
                 id += Tileset.TilesTotal;
             break;
         case ShiftMode.Down:
             id += Tileset.TilesAcross;
             if (id >= Tileset.TilesTotal)
                 id -= Tileset.TilesTotal;
             break;
     }
     return id;
 }
예제 #11
0
        public static string PromptKeyboard(string fieldName, string defaultValue, bool isPassword, ShiftMode keyboardShiftMode)
        {
            KeyboardEntryControl control = new KeyboardEntryControl();
            PosDialogWindow      window  = new PosDialogWindow(control, fieldName);

            control.UsePasswordTextField = isPassword;
            control.ShiftMode            = keyboardShiftMode;
            control.Text      = defaultValue;
            window.IsClosable = false;
            window.Width      = 835;
            window.Height     = 390;
            window.ShowDialogForActiveWindow();
            if (control.WasCanceled)
            {
                return(null);
            }
            if (control.Text == null)
            {
                return("");
            }
            return(control.Text);
        }