Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="MatrixOfLambda"></param>
        /// <param name="Units"></param>
        /// <returns></returns>
        public static double?MinOfLambda(string[,] MatrixOfLambda, double?[,] Units)
        {
            int n = MatrixOfLambda.GetLength(0), m = MatrixOfLambda.GetLength(1);

            var ListOfMin = new List <double?>();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (MatrixOfLambda[i, j] == "-")
                    {
                        ListOfMin.Add(Units[i, j]);
                    }
                }
            }

            var min = ListOfMin[0];

            for (int i = 0; i < ListOfMin.Count; i++)
            {
                if (ListOfMin[i] < min)
                {
                    min = ListOfMin[i];
                }
            }

            return(min);
        }
Ejemplo n.º 2
0
        public Heatmap PlotHeatmap(
            double?[,] intensities,
            Drawing.Colormap colormap = null,
            string label                 = null,
            double[] axisOffsets         = null,
            double[] axisMultipliers     = null,
            double?scaleMin              = null,
            double?scaleMax              = null,
            double?transparencyThreshold = null,
            Bitmap backgroundImage       = null,
            bool displayImageAbove       = false,
            bool drawAxisLabels          = true
            )
        {
            Heatmap heatmap = new Heatmap()
            {
                Label                 = label,
                AxisOffsets           = axisOffsets ?? new double[] { 0, 0 },
                AxisMultipliers       = axisMultipliers ?? new double[] { 1, 1 },
                TransparencyThreshold = transparencyThreshold,
                BackgroundImage       = backgroundImage,
                DisplayImageAbove     = displayImageAbove,
                ShowAxisLabels        = drawAxisLabels,
            };

            heatmap.Update(intensities, colormap ?? Drawing.Colormap.Viridis, scaleMin, scaleMax);

            Add(heatmap);
            Layout(top: 180);

            return(heatmap);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var typeZ = Operations.GetTypeZ(); //return z type in a string that contains a number 1 or 2

            Operations.SetNumberOfRestrictions();
            Operations.SetNumberOfVariables();
            double[] Z = Operations.GetZ(typeZ);                                           //returns a array with the values of the Z expression and the result after the check of the Z type

            double[,] variables = Operations.GetMatrixOfVaribles();                        // return a matrix of all the variable's values

            double?[,] restrictions = Operations.GetMatrixOfRestrictions();                // returns a matrix of all restriciton's values

            double?[,] mergedMatrices = Operations.MergeMatrices(variables, restrictions); //return the matrices together

            double?[,] CompleteMatrix = Operations.FinalMatrix(mergedMatrices, Z);         //puts te Z and result on the matrix

            Matrix.PrintMatrix(CompleteMatrix);                                            //prints any matrices

            bool isSimplex = Matrix.isSimplex(typeZ);

            if (isSimplex)
            {
                CompleteMatrix = Matrix.SimplexResolve(CompleteMatrix);
            }
            else
            {
                CompleteMatrix = Matrix.TwoPhasesResolve(CompleteMatrix);
            }

            Matrix.MatrixStatus(CompleteMatrix);
        }
Ejemplo n.º 4
0
        public static int?ProductionProcess(double?[,] matrix)
        {
            int    chosenColumn = GetChosenColumn(matrix);
            int?   line         = null;
            double?chosenLine   = 999999999;
            double?comp;
            int    s = 1;

            if (!simplex)
            {
                s = 2;
            }


            for (int i = 0; i < matrix.GetLength(0) - s; i++)
            {
                if (matrix[i, chosenColumn] == 0)
                {
                    comp = 999999999;
                }
                else
                {
                    comp = matrix[i, matrix.GetLength(1) - 1] / matrix[i, chosenColumn];
                }

                if (comp < chosenLine && comp >= 0)
                {
                    chosenLine = comp;
                    line       = i;
                }
            }

            return(line);
        }
Ejemplo n.º 5
0
        //---------------------------------------среднее---------------------
        public double?[,] metod_srednee(int razmer, double?[,] raznost)
        {
            double?[,] sr = new double?[razmer, razmer];
            //меняю в масиве sr null на нули
            for (int i = 0; i < razmer; i++)
            {
                sr[i, 0] = 0;
            }

            for (int i = 0; i < razmer; i++)
            {
                int n = 0;

                for (int j = 0; j < razmer; j++)
                {
                    double?chislo = raznost[j, i];
                    if (chislo != null)
                    {
                        sr[i, 0] = sr[i, 0] + chislo;
                        n++;
                    }
                    else
                    {
                        sr[i, 0] = sr[i, 0];
                    }
                }
                sr[i, 0] = sr[i, 0] / n;
            }
            return(sr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calculate valuations of empty cells
        /// </summary>
        /// <param name="x">Array containing the located units</param>
        /// <param name="c">Cost matrix</param>
        /// <param name="p">Potentials</param>
        /// <returns></returns>
        public static double?[,] Evaluation(double?[,] x, double[,] c, double?[][] p)
        {
            int n = x.GetLength(0), m = x.GetLength(1);

            var d = new double?[n, m]; // Evaluation of optimality

            // var P = GetPotentials(x, c);

            ///*Split array of arrays*/
            //var u = new double[n]; // U
            //for (int i = 0; i < n; i++)
            //    u[i] = (double)P[0][i];
            //var v = new double[m]; // V
            //for (int j = 0; j < m; j++)
            //    v[j] = (double)P[1][j];
            ///*------------------------*/

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (x[i, j] == null)
                    {
                        d[i, j] = System.Convert.ToInt32(c[i, j] - (p[0][i] + p[1][j]));
                    }
                }
            }

            return(d);
        }
Ejemplo n.º 7
0
        public static double?[,] FinalMatrix(double?[,] matrix, double[] z)
        {
            double?[,] newMatrix = new double?[matrix.GetLength(0) + 1, matrix.GetLength(1) + 1];

            double[] result = GetResult(newMatrix.GetLength(0) - 1);

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    newMatrix[i, j] = matrix[i, j];
                }
            }
            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                newMatrix[i, matrix.GetLength(1)] = result[i];
            }

            for (int i = 0; i < result.Length; i++)
            {
                newMatrix[newMatrix.GetLength(0) - 1, i] = z[i];
            }
            for (int i = result.Length; i < newMatrix.GetLength(1); i++)
            {
                newMatrix[newMatrix.GetLength(0) - 1, i] = 0;
            }
            return(newMatrix);
        }
Ejemplo n.º 8
0
 public GridLayer(GridGeometry gridGeometry, MAP map)
 {
     this.gridGeometry = gridGeometry;
     this.map          = map;
     matrix            = new double?[CountY, CountX];
     needRecoloring    = true;
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            bool[,] boolMap = GetBoolMapFromTxt(robotMapPath);
            ListGraph <MapElement> robotGraph = BooleanMapToGraph(boolMap);

            Console.WriteLine("//////////////////////////////////GRAFO ROBOT//////////////////////////////////\n\n");
            Node <MapElement> inicio = robotGraph.NodeList.Find(f => f.Element.Id == 73);

            robotGraph.RUNALL(robotGraph, inicio, 21);


            List <Airport> airports = new List <Airport>();

            foreach (string json in File.ReadAllLines(airportJsonFile))
            {
                airports.Add(JsonConvert.DeserializeObject <Airport>(json));
            }
            bool[,] relations    = GetRelations(airports);
            double?[,] distances = GetDistances(airports, relations);
            ListGraph <Airport> grafo = new MatrixGraph <Airport> {
                EdgesMatrix = distances, NodeDataList = airports
            }.GenerateListGraphFromMatrixGraph();

            Console.WriteLine("\n\n\n\n//////////////////////////////////GRAFO RYANAIR//////////////////////////////////\n\n");
            Node <Airport> inicioRyan = grafo.NodeList.Find(f => f.Element.Id == 73);

            grafo.RUNALL(grafo, inicioRyan, 21);

            Console.ReadLine();
        }
Ejemplo n.º 10
0
        public double?[,] method_number_group(int razmer, int num_string, double?[,] nums, int index_Tc)
        {
            double?[,] ddd = new double?[num_string, razmer + 1];
            int k = 1;

            for (int i = 0; i < num_string - 1; i++)
            {
                for (int j = 0; j < razmer; j++)
                {
                    ddd[i, j]     = nums[i, j];
                    ddd[i + 1, j] = nums[i + 1, j];
                }

                if (Math.Round((double)nums[i, index_Tc], 4) == (Math.Round((double)nums[i + 1, index_Tc], 4)))
                {
                    ddd[i, razmer] = k;
                }
                else
                {
                    ddd[i, razmer] = k;
                    k++;
                }
                ddd[i + 1, razmer] = k;
            }
            return(ddd);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Performs iteration step
        /// </summary>
        /// <returns>Sogma0</returns>
        public double Iterate()
        {
            MeasuresNames   = measurementsNames;
            SelectionsNames = selectionNames;
            Init();
            int n = Dimension;
            int l = selection.DataDimension;

            if (x == null)
            {
                x = new double[n];
            }
            else if (x.Length != n)
            {
                x = new double[n];
            }
            if (y == null)
            {
                y  = new double?[l];
                y1 = new double?[l];
            }
            else if (y.Length != l)
            {
                y  = new double?[l];
                y1 = new double?[l];
            }
            if (h == null)
            {
                h = new double?[n, l];
            }
            else if ((h.GetLength(0) != n) | (h.GetLength(1) != l))
            {
                h = new double?[n, l];
            }
            for (int i = 0; i < x.Length; i++)
            {
                IAliasName al = aliases[i];
                x[i] = (double)al.Value;

                /*!!! ====  Test of test ===========
                 * x[i] = (double) al.Value + 0.000001;
                 * //*///==============================
            }
            if (delta.Length != x.Length)
            {
                double[] d = new double[x.Length];
                for (int i = 0; (i < x.Length) & (i < delta.Length); i++)
                {
                    d[i] = delta[i];
                }
                delta = d;
            }
            method.Iterate(x, delta, dispersions, y, y1, h);
            for (int i = 0; i < x.Length; i++)
            {
                IAliasName al = aliases[i];
                al.Value = x[i];
            }
            return(standardDeviation);
        }
Ejemplo n.º 12
0
        public RegularGrid(double?[,] matrix, Node <double> position, double step) : this()
        {
            grid     = matrix;
            Step     = step;
            Position = position;

            CalcAndSetParams();
        }
Ejemplo n.º 13
0
 public GridSpace(int rows, int cols)
 {
     matrix = new double?[rows, cols];
     r_mask = new bool[rows, cols];
     R      = rows;
     C      = cols;
     init();
 }
Ejemplo n.º 14
0
 public StoppingProblem(int candidatesInit, int trialsInit, double mean, double sd, double minCost,
                        double maxCost)
 {
     _values  = new double?[candidatesInit + 1, trialsInit + 1];
     _mean    = mean;
     _sd      = sd;
     _minCost = minCost;
     _maxCost = maxCost;
 }
Ejemplo n.º 15
0
        //------------------------------------------------------------------

        //---------------------------------------Проверка---------------------
        public double?[] metod_proverka(int razmer, double?[,] start, double?[,] sr, int T_number)
        {
            double?[] conec_iterachii = new double?[razmer];
            for (int i = 0; i < razmer; i++)
            {
                conec_iterachii[i] = start[i, T_number] - sr[i, 0];
            }
            return(conec_iterachii);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method analyzes the intensities and colormap to create a bitmap
        /// with a single pixel for every intensity value. The bitmap is stored
        /// and displayed (without anti-alias interpolation) when Render() is called.
        /// </summary>
        /// <param name="intensities">2D array of data for the heatmap (null values are not shown)</param>
        /// <param name="colormap">update the Colormap to use this colormap</param>
        /// <param name="min">minimum intensity (according to the colormap)</param>
        /// <param name="max">maximum intensity (according to the colormap)</param>
        public void Update(double?[,] intensities, Colormap colormap = null, double?min = null, double?max = null)
        {
            Width    = intensities.GetLength(1);
            Height   = intensities.GetLength(0);
            Colormap = colormap ?? Colormap;
            ScaleMin = min;
            ScaleMax = max;

            double?[] intensitiesFlattened = intensities.Cast <double?>().ToArray();
            Min = double.PositiveInfinity;
            Max = double.NegativeInfinity;

            foreach (double?curr in intensitiesFlattened)
            {
                if (curr.HasValue && double.IsNaN(curr.Value))
                {
                    throw new ArgumentException("Heatmaps do not support intensities of double.NaN");
                }

                if (curr.HasValue && curr.Value < Min)
                {
                    Min = curr.Value;
                }

                if (curr.HasValue && curr.Value > Max)
                {
                    Max = curr.Value;
                }
            }

            // labels for colorbar ticks
            ColorbarMin = (ScaleMin.HasValue && ScaleMin > Min) ? $"≤ {ScaleMin:f3}" : $"{Min:f3}";
            ColorbarMax = (ScaleMax.HasValue && ScaleMax < Max) ? $"≥ {ScaleMax:f3}" : $"{Max:f3}";

            double normalizeMin = (ScaleMin.HasValue && ScaleMin.Value < Min) ? ScaleMin.Value : Min;
            double normalizeMax = (ScaleMax.HasValue && ScaleMax.Value > Max) ? ScaleMax.Value : Max;

            if (TransparencyThreshold.HasValue)
            {
                TransparencyThreshold = Normalize(TransparencyThreshold.Value, Min, Max, ScaleMin, ScaleMax);
            }

            double?[] NormalizedIntensities = Normalize(intensitiesFlattened, null, null, ScaleMin, ScaleMax);

            int[]     flatARGB         = Colormap.GetRGBAs(NormalizedIntensities, Colormap, minimumIntensity: TransparencyThreshold ?? 0);
            double?[] normalizedValues = Normalize(Enumerable.Range(0, 256).Select(i => (double?)i).Reverse().ToArray(), null, null, ScaleMin, ScaleMax);
            int[]     scaleRGBA        = Colormap.GetRGBAs(normalizedValues, Colormap);

            BmpHeatmap?.Dispose();
            BmpHeatmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
            Rectangle  rect    = new Rectangle(0, 0, BmpHeatmap.Width, BmpHeatmap.Height);
            BitmapData bmpData = BmpHeatmap.LockBits(rect, ImageLockMode.ReadWrite, BmpHeatmap.PixelFormat);

            Marshal.Copy(flatARGB, 0, bmpData.Scan0, flatARGB.Length);
            BmpHeatmap.UnlockBits(bmpData);
        }
Ejemplo n.º 17
0
        public static void SetColumn(double?[,] matrix, int colIndex, IEnumerable <double?> values)
        {
            int iRow = 0;

            foreach (var value in values)
            {
                matrix[iRow, colIndex] = value;
                iRow++;
            }
        }
Ejemplo n.º 18
0
        public static void SetRow(double?[,] matrix, int rowIndex, IEnumerable <double?> values)
        {
            int iCol = 0;

            foreach (var value in values)
            {
                matrix[rowIndex, iCol] = value;
                iCol++;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Calculte potentials U and V
        /// </summary>
        /// <param name="x">Array containing the located units</param>
        /// <param name="c">Cost matrix</param>
        /// <returns></returns>
        public static double?[][] GetPotentials(double?[,] x, double[,] c)
        {
            int n = x.GetLength(0), m = x.GetLength(1);

            var P = new double?[2][] { new double?[n] /*U*/, new double?[m] /*V*/ };

            P[0][0] = 0;

            bool noValue = true; int count = 0;

            startWhile : while (noValue)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (x[i, j] != null && P[0][i] != null)
                        {
                            P[1][j] = c[i, j] - P[0][i];
                        }

                        if (x[i, j] != null && P[1][j] != null)
                        {
                            P[0][i] = c[i, j] - P[1][j];
                        }
                    }
                }

                count++;

                if (count == 1000)
                {
                    return(null);
                }

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (P[0][i] == null || P[1][j] == null)
                        {
                            noValue = true;
                            goto startWhile;
                        }
                        else
                        {
                            noValue = false;
                        }
                    }
                }
            }

            return(P);
        }
Ejemplo n.º 20
0
        public static RegularGrid CreateTestGrid()
        {
            double?[,] testSurface = GenerateTestSurface();
            var edge = 2;
            var position = new Node<double>(
                -edge * testSurface.GetLength(0) / 2.0,
                edge * testSurface.GetLength(1) / 2.0
            );

            return new RegularGrid(testSurface, position, edge);
        }
Ejemplo n.º 21
0
        public StackDataRepo(int startYear, int startQuarter, int endYear, int endQuarter)
        {
            int noOfQuarters = GetNoOfQuarters(startYear, startQuarter, endYear, endQuarter);

            DataArr = new double?[noOfQuarters, 72];
            InitArray();
            this.StartYear    = startYear;
            this.StartQuarter = startQuarter;
            this.EndYear      = endYear;
            this.EndQuarter   = endQuarter;
        }
Ejemplo n.º 22
0
 public static void isInfinity(double?[,] matrix, int chosenColumn)
 {
     infinity = true;
     for (int i = 0; i < matrix.GetLength(0); i++)
     {
         if (matrix[i, chosenColumn] > 0)
         {
             infinity = false;
         }
     }
 }
Ejemplo n.º 23
0
        public StackDataRepo(StackDatedDataRepo[] stackRepo)
        {
            int noOfQuarters = GetNoOfQuarters(stackRepo[stackRepo.Length - 1].Year, stackRepo[stackRepo.Length - 1].Quarter, stackRepo[0].Year, stackRepo[0].Quarter);

            DataArr = new double?[noOfQuarters, 72];
            InitArray();
            PopulateArr(stackRepo);
            this.StartYear    = stackRepo[stackRepo.Length - 1].Year;
            this.StartQuarter = stackRepo[stackRepo.Length - 1].Quarter;
            this.EndYear      = stackRepo[0].Year;
            this.EndQuarter   = stackRepo[0].Quarter;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Add heatmap to the plot stretched to fit the given dimensions.
        /// Unlike the regular heatmap which gives each cell a size of 1x1 and starts at the axis origin,
        /// this heatmap stretches the array so that it covers the defined X and Y spans.
        /// </summary>
        /// <param name="intensities">2D array of intensities.
        /// WARNING: Rendering artifacts may appear for arrays larger than Bitmap can support (~10M total values).</param>
        /// <param name="xMin">position of the left edge of the far left column</param>
        /// <param name="xMax">position of the left edge of the far right column</param>
        /// <param name="yMin">position of the upper edge of the bottom row</param>
        /// <param name="yMax">position of the upper edge of the top row</param>
        /// <param name="colormap"></param>
        /// <returns>
        /// Returns the heatmap that was added to the plot.
        /// Act on its public fields and methods to customize it or update its data.
        /// </returns>
        public CoordinatedHeatmap AddHeatMapCoordinated(double?[,] intensities, double?xMin = null, double?xMax = null, double?yMin = null, double?yMax = null, Drawing.Colormap colormap = null)
        {
            var plottable = new CoordinatedHeatmap();

            // Solve all possible null combinations, if the boundaries are only partially provided use Step = 1;
            if (xMin == null && xMax == null)
            {
                plottable.XMin = 0;
                plottable.XMax = 0 + intensities.GetLength(0);
            }
            else if (xMin == null)
            {
                plottable.XMax = xMax.Value;
                plottable.XMin = xMax.Value - intensities.GetLength(0);
            }
            else if (xMax == null)
            {
                plottable.XMin = xMin.Value;
                plottable.XMax = xMin.Value + intensities.GetLength(0);
            }
            else
            {
                plottable.XMin = xMin.Value;
                plottable.XMax = xMax.Value;
            }

            if (yMin == null && yMax == null)
            {
                plottable.YMin = 0;
                plottable.YMax = 0 + intensities.GetLength(1);
            }
            else if (yMin == null)
            {
                plottable.YMax = yMax.Value;
                plottable.YMin = yMax.Value - intensities.GetLength(1);
            }
            else if (yMax == null)
            {
                plottable.YMin = yMin.Value;
                plottable.YMax = yMin.Value + intensities.GetLength(1);
            }
            else
            {
                plottable.YMin = yMin.Value;
                plottable.YMax = yMax.Value;
            }

            plottable.Update(intensities, colormap);
            Add(plottable);

            return(plottable);
        }
Ejemplo n.º 25
0
 //------------------------------------------------------------------
 //-------------------------------------Заполняю массив vichitaemoe-----------------------------
 public double?[,] metod_vichitaemoe(int razmer, double?[,] start, int T_number)
 {
     double?[,] vichitaemoe = new double?[razmer, razmer];
     for (int i = 0; i < razmer; i++)
     {
         for (int j = 0; j < razmer; j++)
         {
             int var = j;
             vichitaemoe[i, j] = start[var, T_number];
         }
     }
     return(vichitaemoe);
 }
Ejemplo n.º 26
0
        public int GetFirstNullRowIndexInColumn(double?[,] array, int startIndex, int columnIndex)
        {
            int length = array.GetLength(0);

            for (int i = startIndex; i < length; i++)
            {
                if (!array[i, columnIndex].HasValue)
                {
                    return(i);
                }
            }
            return(length);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Change double?[,] to string[,]
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string[,] NumberToString(double?[,] input)
        {
            string[,] result = new string[input.GetLength(0), input.GetLength(1)];

            for (int i = 0; i < input.GetLength(0); i++)
            {
                for (int j = 0; j < input.GetLength(1); j++)
                {
                    result[i, j] = input[i, j].ToString();
                }
            }
            return(result);
        }
Ejemplo n.º 28
0
 public RegularGrid2D(Point2D origin, Vector2D spacing, int sizeI, int sizeJ, double?initialValue)
 {
     this.origin  = origin;
     this.spacing = spacing;
     this.zs      = new double?[sizeI, sizeJ];
     for (int i = 0; i < sizeI; ++i)
     {
         for (int j = 0; j < sizeJ; ++j)
         {
             this.zs[i, j] = initialValue;
         }
     }
 }
Ejemplo n.º 29
0
        public void ExecuteRecipe(Plot plt)
        {
            double?[,] intensities =
            {
                {    1,    7,    4, null },
                {    9, null,    2,    4 },
                {    1,    4, null,    8 },
                { null,    2,    4, null }
            };

            var hmc = plt.AddHeatmap(intensities);
            var cb  = plt.AddColorbar(hmc);
        }
Ejemplo n.º 30
0
        private void Resize(int newCandidatesMax, int newTrialsMax)
        {
            var newValues = new double?[newCandidatesMax + 1, newTrialsMax + 1];

            for (var i = 0; i < CandidatesMax; i++)
            {
                for (var j = 0; j < TrialsMax; j++)
                {
                    newValues[i, j] = _values[i, j];
                }
            }
            _values = newValues;
        }