public SirtAgorythmWorker(AlgorythmSettings settings) { this.signals = settings.Signals; this.times = settings.Times; this.iterations = settings.Iterations; this.randomStart = settings.RandomStartPoint; }
private void GenerateFirstNode(bool randomStart) { var matrix = new MathMatrix <decimal>(1, signals.Width); if (!randomStart) { decimal averageVelocity = 0; for (int i = 0; i < times.Height; i++) { averageVelocity += signals.RowSum(i) / times[i, 0]; } averageVelocity = averageVelocity / times.Height; averageVelocity -= averageVelocity - (int)averageVelocity; averageVelocity -= averageVelocity % 100; for (int i = 0; i < matrix.Height; i++) { matrix[i, 0] = averageVelocity; } } else { matrix.PutRandomValuesIntoMatrix(300, 2000, 2); } var node = new Node(matrix, this); firstNode = node; bestNode = firstNode; AddNewNode(firstNode); }
public static MathMatrix <decimal> Multiply(this MathMatrix <decimal> m1, MathMatrix <decimal> m2) { if (m1.Width != m2.Height) { throw new Exception("Macierze muszą się zgadzać aby je mnożyć!!!"); } MathMatrix <decimal> result = new MathMatrix <decimal>(m2.Width, m1.Height); for (int i = 0; i < result.Width; i++) { for (int j = 0; j < result.Height; j++) { decimal res = 0; for (int z = 0; z < m1.Width; z++) { res += m1[j, z] * m2[z, i]; } if (res != 0) { result[j, i] = res; } } } return(result); }
public double[,] MakeRayDensity() { List <PointF> temporaryPointFs; signalsMatrix = new MathMatrix <decimal>(matrixCells.Count(), allSignals.AllRoutes.Count()); timesMatrix = new MathMatrix <decimal>(1, allSignals.AllRoutes.Count()); signalIndex = 0; foreach (var signal in allSignals.AllRoutes) { timesMatrix[0, signalIndex] = signal.Time; temporaryPointFs = new List <PointF>(); temporaryPointFs.Add(signal.StartPoint); temporaryPointFs.Add(signal.EndPoint); GelAllCrossingsWithXBoarders(temporaryPointFs, signal); GetAllCrossingsWithYBoarders(temporaryPointFs, signal); if (temporaryPointFs.Count() == 0) { continue; } var tmpList1 = temporaryPointFs.Distinct().ToList(); var tmpList2 = tmpList1.Where(PointF => PointF.IsBetweenTwoPointFs(signal.StartPoint, signal.EndPoint)).ToList(); List <PointF> sortedPointFs = PointFsSort.SortByDistanceFromPointF(signal.StartPoint, tmpList2); AddSignalLengthsToCells(sortedPointFs); signalIndex++; } return(transposedMatrix); }
/// <summary> /// Transforms this UnityEngine.Color into CIEColor.CIE_XYZColor. /// </summary> /// <returns>The CIE XYZ value of the Color.</returns> public static CIE_XYZColor ToCIE_XYZ(this Color color) { //Ecuations: http://www.brucelindbloom.com/ CIE_XYZColor cieXyz = new CIE_XYZColor(); //Inverse companding float auxR = color.r <= 0.04045f ? color.r / 12.92f : Mathf.Pow((color.r + 0.055f) / 1.055f, 2.4f); float auxG = color.g <= 0.04045f ? color.g / 12.92f : Mathf.Pow((color.g + 0.055f) / 1.055f, 2.4f); float auxB = color.b <= 0.04045f ? color.b / 12.92f : Mathf.Pow((color.b + 0.055f) / 1.055f, 2.4f); //Linear RGB to XYZ float[][] transformationMatrix = { new float[] { 0.4124564f, 0.3575761f, 0.1804375f }, new float[] { 0.2126729f, 0.7151522f, 0.0721750f }, new float[] { 0.0193339f, 0.1191920f, 0.9503041f } }; float[][] rgbMatrix = { new float[] { auxR }, new float[] { auxG }, new float[] { auxB } }; float[][] cieXyzMatrix = MathMatrix.MatrixMultiplication(transformationMatrix, rgbMatrix); cieXyz._x = cieXyzMatrix[0][0]; cieXyz._y = cieXyzMatrix[1][0]; cieXyz._z = cieXyzMatrix[2][0]; return(cieXyz); }
// Materialf (GLenum face, GLenum pname, GLfloat param); // Materialfv (GLenum face, GLenum pname, const GLfloat *params); public virtual void MultMatrixf(float[] m) //, int ofs) { int ofs = 0; MathMatrix.MultiplyMM(_tmpMatrix, 0, _currentMatrix, 0, m, ofs); JSArrayEx.Copy(_tmpMatrix, 0, _currentMatrix, 0, 16); _mvpDirty = true; }
public WebGLES11RenderingContext(int width, int height) { MathMatrix.SetIdentityM(_modelViewMatrix, 0); MathMatrix.SetIdentityM(_projectionMatrix, 0); MathMatrix.SetIdentityM(_textureMatrix, 0); _width = width; _height = height; }
public Node(MathMatrix <decimal> newMatrix, Colony colony) { matrix = newMatrix; sense = 1; connectedNodes = new List <Node>(); antsOnNode = new List <Ant>(); error = colony.GetStatisticErrorForNode(this); visited = 0; }
// PolygonOffset (GLfloat factor, GLfloat units); public virtual void Rotatef(float angle, float x, float y, float z) { if ((x != 0) || (y != 0) || (z != 0)) { // right thing to do? or rotate around a default axis? MathMatrix.RotateM2(_currentMatrix, 0, angle, x, y, z); } _mvpDirty = true; }
public static decimal ColumnSum(this MathMatrix <decimal> matrix, int col) { decimal res = 0; for (int i = 0; i < matrix.Height; i++) { res += matrix[i, col]; } return(res); }
public void MatrixRowSumTest() { MathMatrix <decimal> m = CreateMatrix(); var rowSum1 = m.RowSum(0); var rowSum2 = m.RowSum(1); Assert.AreEqual(4, rowSum1); Assert.AreEqual(6, rowSum2); }
public void MatrixColumnSumTest() { MathMatrix <decimal> m = CreateMatrix(); var colSum1 = m.ColumnSum(0); var colSum2 = m.ColumnSum(1); Assert.AreEqual(3, colSum1); Assert.AreEqual(7, colSum2); }
public static MathMatrix <decimal> ConvertResultToVelociti(this MathMatrix <decimal> m) { var result = new MathMatrix <decimal>(m.Width, m.Height); for (int i = 0; i < result.Height; i++) { result[i, 0] = m[i, 0] == 0 ? 0 : 1 / m[i, 0]; } return(result); }
public static decimal RowSum(this MathMatrix <decimal> matrix, int row) { decimal res = 0; for (int i = 0; i < matrix.Width; i++) { res += matrix[row, i]; } return(res); }
/* Available only here */ protected bool UpdateMvpMatrix() { if (!_mvpDirty) { return(false); } MathMatrix.MultiplyMM(_mvpMatrix, 0, _projectionMatrix, 0, _modelViewMatrix, 0); _mvpDirty = false; return(true); }
public Colony(AlgorythmSettings settings) { iterations = settings.Iterations; signals = settings.Signals; times = settings.Times; rand = new Random(); Ants = new List <Ant>(); AllNodes = new Dictionary <string, Node>(); GenerateFirstNode(settings.RandomStartPoint); AddAnts(settings.AntNumber); }
private MathMatrix <decimal> CreateMatrix() { MathMatrix <decimal> m = new MathMatrix <decimal>(2, 2); m[0, 0] = 1; m[1, 0] = 2; m[0, 1] = 3; m[1, 1] = 4; return(m); }
public void Sirt() { settings.Signals = matrix.SignalsMatrix; settings.Times = matrix.TimesMatrix; var sirtWorker = new SirtAgorythmWorker(settings); sirtWorker.SubscribeStoper(stoper); sirtWorker.resetProgressBar += resetProgressBar; sirtWorker.updateProgressBar += updateProgressBar; result = sirtWorker.Result; isCalculated = true; }
public void AntColony() { settings.Signals = matrix.SignalsMatrix; settings.Times = matrix.TimesMatrix; var antColonytWorker = new AntColonyWorker(settings); antColonytWorker.SubscribeStoper(stoper); antColonytWorker.resetProgressBar += resetProgressBar; antColonytWorker.updateProgressBar += updateProgressBar; result = antColonytWorker.Result; isCalculated = true; }
public void MatrixAddTest() { MathMatrix <decimal> m1 = CreateMatrix(); MathMatrix <decimal> m2 = CreateMatrix(); var res = m1.Add(m2); Assert.AreEqual(2, res[0, 0]); Assert.AreEqual(4, res[1, 0]); Assert.AreEqual(6, res[0, 1]); Assert.AreEqual(8, res[1, 1]); }
private void Compute() { colony.resetProgressBar += resetProgressBar; colony.updateProgressBar += updateProgressBar; start(); result = colony.Compute(); stop(); var tmp = DateTime.Now; var filename = ("\\" + "Ant_Result" + tmp.ToShortDateString() + tmp.ToShortTimeString()).Replace('.', '_').Replace(':', '_') + ".txt"; result.PrinttoFile(filename); }
public MathMatrix <decimal> GetRealVelocities() { if (realModel == null) { realModel = new MathMatrix <decimal>(1, matrixCells.Count()); int index = 0; foreach (var cell in matrixCells) { realModel[index, 0] = Convert.ToDecimal(cell.velocity); } } return(realModel); }
public void CanculateDistance() { foreach (Hatch hatch in DistanceCalculate.hatches) { if (hatch.state == State.unDrawed) { rotation = MathMatrix.RotateAroundY(GPSTraker.angleToNorth); initialPose = new Vector4(0f, 0f, hatch.distance, 1f); hatch.position = MathMatrix.TransformMatrix(GPSTraker.currentlocation, hatch.location, rotation * initialPose); } } }
public WebGL15Context(int width, int height) { SE.WriteSingle(_st0011, 0f); SE.WriteSingle(_st0011, 0f); SE.WriteSingle(_st0011, 1f); SE.WriteSingle(_st0011, 0f); SE.WriteSingle(_st0011, 1f); SE.WriteSingle(_st0011, 1f); SE.WriteSingle(_st0011, 0f); SE.WriteSingle(_st0011, 1f); _st0011.Position = 0; // MathMatrix.SetIdentityM(_modelViewMatrix, 0); MathMatrix.SetIdentityM(_projectionMatrix, 0); MathMatrix.SetIdentityM(_textureMatrix, 0); _width = width; _height = height; }
public void SetView(EOrthographicView view) { float rot90deg = (float)(Math.PI * 0.5); switch (view) { case EOrthographicView.XY: SetRotationMatrixAsXYPlane(); break; case EOrthographicView.XZ: { float[,] rotMatrix = MathMatrix.CalcHomogeneousRotMatrix(-1 * rot90deg, 0, 0); SetRotationMatrixAsXYPlane(); m_RotationMatrix = m_RotationMatrix.Multiply(rotMatrix); } break; case EOrthographicView.YZ: { float[,] rotMatrix = MathMatrix.CalcHomogeneousRotMatrix(0, -1 * rot90deg, 0); SetRotationMatrixAsXYPlane(); m_RotationMatrix = m_RotationMatrix.Multiply(rotMatrix); } break; case EOrthographicView.Isometric: { // Assume currently is XY plane, rotate to isometric position // Rot X 45 deg float thetaX = -1 * (float)(0.25 * Math.PI); float thetaY = 0f; // Then Rot Z 135 deg float thetaZ = (float)(-135f / 180 * Math.PI); float[,] rotMatrix = MathMatrix.CalcHomogeneousRotMatrix(thetaX, thetaY, thetaZ); float[,] vec = new float[3, 1] { { (float)(1f / Math.Sqrt(3)) }, { (float)(1f / Math.Sqrt(3)) }, { (float)(1f / Math.Sqrt(3)) } }; SetRotationMatrixAsXYPlane(); m_RotationMatrix = m_RotationMatrix.Multiply(rotMatrix); } break; default: // undone break; } }
public static string GetMatrixHash(this MathMatrix <decimal> m1) { if (m1.Width != 1) { throw new Exception("Wrong value exception"); } string tmp = "["; for (int i = 0; i < m1.Height; i++) { tmp += string.Format("\t{0},", m1[i, 0]); } tmp += "]"; return(string.Format("{0:X}", tmp.GetHashCode())); }
public static void PrinttoFile(this MathMatrix <decimal> m1, string fileName) { var writer = new StreamWriter(fileName); for (int i = 0; i < m1.Height; i++) { string line = ""; for (int j = 0; j < m1.Width; j++) { line += m1[i, j] + "\t"; } writer.WriteLine(line); } writer.Close(); }
public static void PutRandomValuesIntoMatrix(this MathMatrix <decimal> m, int min, int max, int zeros = 0) { int zer = 1; for (int k = 0; k < zeros; k++) { zer = zer * 10; } var r = new Random(); for (int i = 0; i < m.Height; i++) { for (int j = 0; j < m.Width; j++) { m[i, j] = r.Next(min / zer, max / zer) * zer; } } }
public VelocityChartCreator(MathMatrix <decimal> velocityMatrix, ProjectionsData data) { var rows = data.MatrixCells.Select(c => c.yIndex).Max() + 1; var cols = data.MatrixCells.Select(c => c.xIndex).Max() + 1; matrix = new MathMatrix <decimal>(cols, rows); for (int i = 0; i < velocityMatrix.Height; i++) { var row = i / matrix.Width; var col = i % matrix.Width; matrix[row, col] = velocityMatrix[i, 0]; } maxValue = 2500; minValue = 300; numberOfColors = (int)(((maxValue - minValue) / 100) + 1); colors = new ColorPicker().InterpolateColors(numberOfColors); }
public static decimal AverageStatisticError(this MathMatrix <decimal> m1, MathMatrix <decimal> m2) { List <decimal> errorsList = new List <decimal>(); if (m1.Height == m2.Height && m1.Width == m2.Width) { for (int i = 0; i < m1.Height; i++) { for (int j = 0; j < m1.Width; j++) { errorsList.Add(Math.Abs(m2[i, j] - m1[i, j])); } } } var error = errorsList.Count == 0 ? 0 : errorsList.Average() * 100 / m1.GetAllValues().Average(); return(error); }