Пример #1
0
 public SLAE(src.GUI.IGUI igui)
 {
     iGui = igui;
     MaxIter = DefaultMaxIter;
     MinResidual = DefaultMinResidual;
     MGMRES = DefaultMGMRES;
     Relaxation = DefaultRelaxation;
 }
Пример #2
0
        public static List<Tuple<uint, uint>> getCover(src.Board board, src.Piece piece)
        {
            // Get cover
            List<Tuple<uint, uint>> cover = new List<Tuple<uint, uint>>();

            int x = (int)piece.getX();
            int y = (int)piece.getY();

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        // Do not cover self
                        continue;
                    }
                    int nx = x + i;
                    int ny = y + j;
                    if (board.withinBoard(nx, ny))
                    {
                        Square s = board.getSquareAt((uint)nx, (uint)ny);
                        if ((piece.getColour() == "white" && s.getBlackCover() == 0) ||
                            (piece.getColour() == "black" && s.getWhiteCover() == 0))
                        {
                            Tuple<uint, uint> t = new Tuple<uint, uint>((uint)nx, (uint)ny);
                            if (!getEnemyKingReach(board, piece).Contains(t))
                            {
                                cover.Add(t);
                            }
                        }
                    }
                }
            }

            return cover;
        }
Пример #3
0
 => ShiftRightLogicalVariable(src, control);
Пример #4
0
 ref readonly var part = ref skip(src, i0);
Пример #5
0
 src.Preconditioner.IPreconditioner GeneratePreconditioner(src.Preconditioner.Type type, Matrix.BaseMatrix matrix)
 {
     switch (type) {
         case src.Preconditioner.Type.NoPrecond:
             return src.Preconditioner.EmptyPreconditioner.Create(matrix);
         case src.Preconditioner.Type.Diagonal:
             return src.Preconditioner.DiagonalPreconditioner.Create(matrix);
         case src.Preconditioner.Type.LLT:
             return src.Preconditioner.LLTPreconditioner.Create(matrix);
         case src.Preconditioner.Type.LU:
             return src.Preconditioner.LUPreconditioner.Create(matrix);
         case src.Preconditioner.Type.LUsq:
             return src.Preconditioner.LUsqPreconditioner.Create(matrix);
     }
     return null;
 }
Пример #6
0
 void capFile_onReadDataFrame(src.Packets.DataFrame dataFrame)
 {
     DataFrameCount++;
     RefreshValues();
 }
Пример #7
0
 => Xor(src, CompareEqual(src, src));
Пример #8
0
 => ShuffleHigh(src, control);
Пример #9
0
 ReadRaw(new BinaryReader(src, Encoding.UTF8));
Пример #10
0
        private void updateDgvResult(src.Vector_.Vector vec)
        {
            tabControl1.SelectedIndex = 2;
            ClearDgv(dgvResult);

            if (vec == null)
                return;

            if (vec.Size > maxDrawSize)
            {
                dgvResult.Rows.Add("Vector is too big to draw");
                return;
            }
            for (var i = 0; i < vec.Size; i++)
                dgvResult.Rows.Add(vec[i].ToString());
        }
Пример #11
0
        private void updateDgvRightPart(src.Vector_.Vector vec)
        {
            tabControl1.SelectedIndex = 0;
            ClearDgv(dgvRightPart);
            if (vec.Size > maxDrawSize)
            {
                dgvRightPart.Rows.Add("Vector is too big to draw");
                return;
            }
            for (var i = 0; i < vec.Size; i++) {
                String[] strs = new String[1];
                strs[0] = vec[i].ToString();

                dgvRightPart.Rows.Add(strs);
            }
        }
Пример #12
0
        private void updateDgvMatrix(src.Matrix.BaseMatrix matrix)
        {
            tabControl1.SelectedIndex = 0;

            dgvMatrix.Rows.Clear();
            dgvMatrix.Columns.Clear();

            if  (matrix.Size > maxDrawSize)
            {
                dgvMatrix.Columns.Add("", "");
                dgvMatrix.Rows.Add("Matrix is too big to draw");
                return;
            }
            for(var i=0; i < matrix.Size; i++)
                dgvMatrix.Columns.Add("","");

            string[][] strs = new string[matrix.Size][];
            for(int i=0;i < matrix.Size;i++)
                strs[i] = new string[matrix.Size];
            matrix.Run((i, j, u) => strs[i][j] = u.ToString());

            for (int i = 0; i < matrix.Size; i++)
                dgvMatrix.Rows.Add(strs[i]);
        }
Пример #13
0
 private void UpdateDgvResult(src.Vector_.Vector vec)
 {
     if (this.dgvRightPart.InvokeRequired)
         this.Invoke(new UpdateDgvResultCallback(UpdateDgvResult), new object[] { vec });
     else
         updateDgvResult(vec);
 }
Пример #14
0
 s.source.init(src, errh);
Пример #15
0
 => TestC(src, mask);
Пример #16
0
 => ShiftRightLogicalVariable(src, offset);
Пример #17
0
        // Saves all moves done in a game
        public static void saveMove(src.Move m, string fileName)
        {
            // Create directory if not exists
            bool exists = System.IO.Directory.Exists(savePath);
            if (!exists)
            {
                System.IO.Directory.CreateDirectory(savePath);
            }

            // Append move to file
            using (StreamWriter sw = File.AppendText(savePath + fileName + "_" + MOVES + "." + fileEnding))
            {
                sw.WriteLine(m.ToString());
            }
        }
Пример #18
0
 => ShiftLeftLogical(src, offset);
Пример #19
0
 // Loads current game at startup
 public static bool loadCurrent(ref src.Board board)
 {
     return SaveManager.loadState(ref board, CURRENT);
 }
Пример #20
0
 => Extract(src, pos);
Пример #21
0
 => Shuffle(src, mask);
Пример #22
0
 => ExtractVector128(src, pos);
Пример #23
0
 => ShiftLeftLogicalVariable(src, offset);
Пример #24
0
 => MaskMove(src, mask, refptr(ref dst));
Пример #25
0
 => shuffle(src, Vec128Pattern.Swap <byte>(swaps));
Пример #26
0
 ref readonly var record = ref skip(src, i);
Пример #27
0
 => xor(src, sll(src, offset));
Пример #28
0
        // --- Graphics interface ---
        // Functions for printing the text and image versions of the board.
        // Update the board and render the GUI. Also reset the selected move.
        public void updateBoard(src.Board board)
        {
            this.board = board;
            drawControl.setBoard(board);

            selectedMove = new src.Move();

            renderGUI();
        }
Пример #29
0
 src.Solver.ISolverParametrs GenerateParameters(src.Solver.Type type, int maxIter, double eps, double relaxation = 1,int mGMRES = 5)
 {
     switch(type) {
         case src.Solver.Type.GMRES:
             return new Solver.GMRESParameters(eps, maxIter, mGMRES);
         case src.Solver.Type.Jacobi:
             return new Solver.JacobiParametrs(eps, maxIter, relaxation);
         case src.Solver.Type.GaussSeidel:
             return new Solver.GaussSeidelParametrs(eps, maxIter, relaxation);
         case src.Solver.Type.MSG:
             return new Solver.MSGParametrs(eps, maxIter);
         case src.Solver.Type.BCGStab:
             return new Solver.BCGStabParametrs(eps, MaxIter);
         case src.Solver.Type.LOS:
             return new Solver.LOSParametrs(eps, MaxIter);
     }
     return null;
 }
Пример #30
0
 => !TestZ(src, src);
Пример #31
0
 ref readonly var path = ref skip(src, i);
Пример #32
0
 src = rotr(src, offset);
Пример #33
0
 src = rotl(src, offset);
Пример #34
0
 public DLCommand(IList <byte> src, uint offset) => this.Update(src, offset);
Пример #35
0
 // Savefile that is saved after every move and loaded at startup
 public static void saveCurrent(src.Board board)
 {
     SaveManager.saveState(board, CURRENT);
 }
Пример #36
0
        private void fillTableResult(DataGridView dgv, Task task, src.SMethod.SimplexMethodSolver slv)
        {
            dgv.Rows.Clear();
              dgv.Columns.Clear();

              if (slv.errMsg != "OK") {
            return;
              }

              List<OrderPair> savedOrder = new List<OrderPair>();
              foreach (OrderPair p in order)
            savedOrder.Add(new OrderPair(new Detail1D(pgrdOrderDetail, new double[]{p.Detail.Volume}),p.Num));

              String[] strs = new String[3];
              strs[0] = "Число заготовок:";
              strs[1] = "Разрез:";
              strs[2] = "Остатки:";

              dgv.Columns.Add("", ""); dgv.Columns.Add("", ""); dgv.Columns.Add("", "");

              dgv.Rows.Add(strs);
              dgv.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;
              dgv.Columns[0].Width = 150;dgv.Columns[2].Width = 100;

              double allLeft = 0.0;

              for (int i = 0; i < slv.xsCol.Count - 1; i++) {
            if(slv.table[i, slv.table.GetLength(1) - 1] == 0.0) continue;

            int rounded = (int)slv.table[i, slv.table.GetLength(1) - 1];

            strs[0] = rounded.ToString();
            strs[1] = "";
            foreach (OrderPair p in task.AllCuts[slv.xsCol[i] - 1].Pairs) {
              for (int j = 0; j < p.Num; j++) {
            strs[1] += (((Detail1D)p.Detail).Length).ToString().Replace(',','.');
            foreach (OrderPair oP in order) {
              if (((Detail1D)oP.Detail).Length == ((Detail1D)p.Detail).Length) {
                oP.Num -= rounded;
                break;
              }
            }

            if (j == p.Num - 1) {
              if (p != task.AllCuts[slv.xsCol[i] - 1].Pairs.Last())
                strs[1] += ",";
            }
            else
              strs[1] += ",";
              }
            }
            strs[2] = Math.Round(task.AllCuts[slv.xsCol[i] - 1].Left, 3).ToString().Replace(',', '.');
            allLeft += task.AllCuts[slv.xsCol[i] - 1].Left * rounded;
            dgv.Rows.Add(strs);
              }

              // ЖАДНЫЙ
              List<src.Cut> leftCuts = greedyAlgorithm();
              double greedyCutLeft = 0.0;
              foreach (Cut cut in leftCuts) {
            strs[0] = "1"; strs[1] = "";
            foreach (OrderPair p in cut.Pairs) {
              for (int j = 0; j < p.Num; j++) {
            strs[1] += (((Detail1D)p.Detail).Length).ToString().Replace(',', '.');
            foreach (OrderPair oP in order) {
              if (((Detail1D)oP.Detail).Length == ((Detail1D)p.Detail).Length) {
                oP.Num -= 1;
                break;
              }
            }

            if (j == p.Num - 1) {
              if (p != cut.Pairs.Last())
                strs[1] += ",";
            }
            else
              strs[1] += ",";
              }
            }
            strs[2] = Math.Round(cut.Left, 3).ToString().Replace(',', '.');
            greedyCutLeft += cut.Left;
            dgv.Rows.Add(strs);
              }

              strs[0] = strs[1] = strs[2] = "";
              dgv.Rows.Add(strs);
              strs[0] = "Общие:";
              strs[2] = Math.Round(allLeft, 3).ToString().Replace(',', '.') + " + " + Math.Round(greedyCutLeft, 3).ToString().Replace(',', '.');
              dgv.Rows.Add(strs);
              dgv.Rows[dgv.Rows.Count-1].DefaultCellStyle.BackColor = Color.Gray;

              order = savedOrder;
        }
Пример #37
0
        // Saves current save state. The filename is put in a textbox in the GUI
        public static void saveState(src.Board b, string fileName)
        {
            // Create directory if not exists
            bool exists = System.IO.Directory.Exists(savePath);
            if (!exists)
            {
                System.IO.Directory.CreateDirectory(savePath);
            }

            // Clear file, might be a better way
            string fullName = savePath + fileName + "_" + STATE + "." + fileEnding;
            File.WriteAllText(fullName, string.Empty);

            // Create Xml tree root
            XElement tree = new XElement("Board");
            tree.Add(new XElement("Turn", b.getTurn()));

            // Get all squares with a piece
            var saveSquares = from s in b.getAllSquares()
                              where s.getPiece() != null
                              select s.getPiece();

            // Create squares subtree tree
            foreach (src.Piece p in saveSquares)
            {
                XElement piece = new XElement("Piece",
                                              new XElement("X-coordinate", p.getX()),
                                              new XElement("Y-coordinate", p.getY()),
                                              new XElement("Type", p.GetType().Name),
                                              new XElement("Colour", p.getColour()),
                                              new XElement("Moved", p.movedFromInit()));
                if (p is src.Pawn)
                {
                    piece.Add(new XElement("DoubleStepTurn", ((src.Pawn)p).getDoubleStepTurn()));
                }
                tree.Add(piece);
            }

            using (StreamWriter sw = File.AppendText(fullName))
            {
                sw.WriteLine(tree);
            }
        }
Пример #38
0
        private void fillTableSimplexMethod(DataGridView dgv, src.SMethod.SimplexMethodSolver slv)
        {
            dgv.Rows.Clear();
              dgv.Columns.Clear();
              if (slv.errMsg != "OK") {
            MessageBox.Show(slv.errMsg, "Симплекс-метод", MessageBoxButtons.OK);
              }

              String[] strs = new String[slv.xsStr.Count + 2];
              strs[0] = "";

              for (int i = 0; i < slv.xsStr.Count; i++)
            strs[i + 1] = "-x" + slv.xsStr[i].ToString();
              strs[slv.xsStr.Count + 1] = "1";

              for (int i = 0; i < slv.xsStr.Count + 2; i++)
            dgv.Columns.Add("", strs[i]);
              dgv.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
              dgv.Rows.Add(strs);
              dgv.Rows[0].DefaultCellStyle.BackColor = Color.LightGray;
              dgv.Columns[0].Width = 50;
              for (int i = 0; i < slv.xsCol.Count - 1; i++) {
            strs = new String[slv.xsStr.Count + 2];
            int index = 0;
            if (slv.xsCol[i] != 0)
              strs[index] = "x" + slv.xsCol[i].ToString() + "=";
            else
              strs[index] = "0=";

            index++;
            for (int j = 0; j < slv.table.GetLength(1); j++) {
              strs[index] += slv.table[i, j].ToString().Replace(',', '.');
              index++;
            }
            dgv.Rows.Add(strs);
              }
              strs = new String[slv.xsStr.Count + 2];
              strs[0] = "Q";
              for (int i = 0; i < slv.table.GetLength(1); i++)
            strs[i + 1] = Math.Abs(slv.table[slv.table.GetLength(0) - 1, i]).ToString().Replace(',', '.') + "\t";

              dgv.Rows.Add(strs);
        }
Пример #39
0
        //Loads the boardstate from the file written in the GUI textbox
        public static bool loadState(ref src.Board board, string fileName)
        {
            // Clear file, might be a better way
            string fullName = savePath + fileName + "_" + STATE + "." + fileEnding;

            // Check if file exists
            if (!File.Exists(fullName))
            {
                return false;
            }

            // Clear the board
            board.clearBoard();

            // Read the savefile
            var loadFile = XElement.Load(fullName);
            IEnumerable<XElement> elements = from el in loadFile.Elements() select el;

            // Insert in board
            foreach (XElement el in elements)
            {
                if (el.Name == "Turn")
                {
                    board.setTurn(Convert.ToUInt32(el.Value));
                }
                else if (el.Name == "Piece")
                {
                    // The pieces values
                    uint x = Convert.ToUInt32(el.Element("X-coordinate").Value);
                    uint y = Convert.ToUInt32(el.Element("Y-coordinate").Value);
                    string type = el.Element("Type").Value;
                    string col = el.Element("Colour").Value;
                    bool moved = Convert.ToBoolean(el.Element("Moved").Value);

                    src.Piece piece;

                    switch (type)
                    {
                        case "Pawn":
                            piece = new src.Pawn(x, y, col);
                            ((src.Pawn)piece).setDoubleStepTurn(Convert.ToUInt32(el.Element("DoubleStepTurn").Value));
                            break;
                        case "Rook":
                            piece = new src.Rook(x, y, col);
                            break;
                        case "Knight":
                            piece = new src.Knight(x, y, col);
                            break;
                        case "Bishop":
                            piece = new src.Bishop(x, y, col);
                            break;
                        case "Queen":
                            piece = new src.Queen(x, y, col);
                            break;
                        case "King":
                            piece = new src.King(x, y, col);
                            break;
                        default:
                            //Should not happen
                            return false;
                    }

                    // Update pieces
                    piece.setHasMoved(moved);
                    board.setPiece(x, y, piece);

                }
            }

            return true;
        }
Пример #40
0
 => xor(src, srl(src, offset));
Пример #41
0
 => ShuffleLow(src, control);
Пример #42
0
 => ShiftLeftLogical128BitLane(src, bytes);
Пример #43
0
 => Shuffle(src, control);
Пример #44
0
 => ShiftRightArithmetic(src, offset);
Пример #45
0
 var(comp, _, exceptionDiagnostics) = await TestCaseCompilation.CreateCompilation(src, analyzerOptions, additionalReferences);
Пример #46
0
 => ShiftRightArithmeticVariable(src, control);
Пример #47
0
 => ShiftRightLogical128BitLane(src, bytes);
Пример #48
0
 void capFile_onReadBeacon(src.Packets.BeaconFrame beacon)
 {
     RefreshValues();
 }