} // GetStringFromPtr(pointer, nLength) /// <summary> /// Get string from ptr /// </summary> internal static string GetStringFromPtrLA(IntPtr pointer, int nLength) { string sResult = Marshal.PtrToStringAnsi(pointer, nLength); LA.FreeVector(pointer); return(sResult); } // GetStringFromPtrLA(pointer, nLength)
public DotItem CreateNextItem() { return(new DotItem(production, Position + 1) { LA = LA.EditCopy() }); }
public void calcDeterminant(double[][] a, int N, out double determinant) { double realFit = 0.0; double imagFit = 0.0; int eigen_rows; var wr = new List <double>(); var wi = new List <double>(); Complex[] read_eigen_array = LA.GetEigenValues(a); eigen_rows = read_eigen_array.Length; N = eigen_rows; for (int i = 0; i < N; i++) { wr.Add(read_eigen_array[i].Real); wi.Add(read_eigen_array[i].Imag); } /*Calculate the product of eigen values*/ realFit = wr[0]; imagFit = wi[0]; double tempRealFit = 0.0; for (int i = 1; i < N; i++) { tempRealFit = realFit; realFit = realFit * wr[i] - imagFit * wi[i]; imagFit = tempRealFit * wi[i] + imagFit * wr[i]; } determinant = realFit; //Using only real part because, we assume the eigen values //come in complex conjugates, so the imag parts will be gone //when we take the product. }
} // GetIntArrayFromPtr(pointer, nLength) /// <summary> /// Get int array from ptr /// </summary> internal static int[] GetIntArrayFromPtrLA(IntPtr pointer, int nLength) { int[] oResult = new int[nLength]; Marshal.Copy(pointer, oResult, 0, nLength); LA.FreeVector(pointer); return(oResult); } // GetIntArrayFromPtr(pointer, nLength)
} // GetDoubleArrayFromPtr(pointer, nLength) /// <summary> /// Get double array from ptr /// </summary> internal static double[] GetDoubleArrayFromPtrLA(IntPtr pointer, int nLength) { double[] oResult = new double[nLength]; Marshal.Copy(pointer, oResult, 0, nLength); LA.FreeVector(pointer); return(oResult); } // GetDoubleArrayFromPtr(pointer, nLength)
public LA Out() { Tables.CreateTables(); this.WriteTable(FileName, FileResult); LA resulstruct = new LA(lexemslist, ReverseConstants, ReverseIdentifiers); return(resulstruct); }
public static void SetVar(VariableType var, VarMemType mem, int num, double value) { switch (mem) { case VarMemType.IC: break; case VarMemType.LA: LA.Set(var, num, value); break; case VarMemType.RA: RA.Set(var, num, value); break; } }
public static float GetVar(VariableType var, VarMemType mem, int num) { switch (mem) { case VarMemType.IC: return(IC.Get(var, num)); case VarMemType.LA: return(LA.Get(var, num)); case VarMemType.RA: return(RA.Get(var, num)); } return(0.0f); }
//*class function public void GenerateBid(int ToD) { foreach (LaneAgent LA in Lanes) { LA.PopulateAgentData(ToD); //AH's function LA.GenerateBidTurns(); //AH's function //LA.PullDataAtTime(ToD); //SB's original function //LA.GenerateBid(); //SB's original function } Strat.ProcessStage(this); }
} // GetIntMatrixFromPtr(pointer, nRows, nCols) /// <summary> /// Get int matrix from ptr /// </summary> internal static int[][] GetIntMatrixFromPtrLA(IntPtr pointer, int nRows, int nCols) { IntPtr[] rawRows = new IntPtr[nRows]; int[][] oResult = new int[nRows][]; Marshal.Copy(pointer, rawRows, 0, nRows); for (int i = 0; i < nRows; i++) { oResult[i] = new int[nCols]; Marshal.Copy(rawRows[i], oResult[i], 0, nCols); } // for (int) LA.FreeMatrix(pointer, nRows); return(oResult); } // GetIntMatrixFromPtr(pointer, nRows, nCols)
} // GetStringArrayFromPtr(pointer, nLength) /// <summary> /// Get string array from ptr /// </summary> internal static string[] GetStringArrayFromPtrLA(IntPtr pointer, int nLength) { IntPtr[] rawRows = new IntPtr[nLength]; string[] oResult = new string[nLength]; Marshal.Copy(pointer, rawRows, 0, nLength); for (int i = 0; i < nLength; i++) { oResult[i] = Marshal.PtrToStringAnsi(rawRows[i]); } // for (int) LA.FreeMatrix(pointer, nLength); return(oResult); } // GetStringArrayFromPtrLA(pointer, nLength)
//Mutation //Description: The members are mutated based on mutation probability - Pm. //Generates a random number 'r'. If the random number generated is less than Pm then mutation is carried. //The selection of the parameter that undergoes mutation is again based on a random number - 'randomParam' //which can take any value from 0 to num_of_parameters. public double getRealPart_ComplexEigenVal_MinReal() { bool hasImagEigenValue = false; rr.setTimeStart(0); rr.setTimeEnd(simulationTime); BringToSteadyStateOrThrow(); var redJacobian = rr.getReducedJacobian(); var eigenValues = LA.GetEigenValues(redJacobian); var bufferArray = new List <double>(); for (int i = 0; i < eigenValues.Length; i++) { if (Math.Abs(eigenValues[i].Imag) == 0.0) // Check if the imaginary part is greater than zero. { // If it is so then assign 10^6 to bufferArray Element. bufferArray.Add(10E6); } else // Else store the absolute value of real eigen value. { bufferArray.Add(Math.Abs(eigenValues[i].Real)); hasImagEigenValue = true; } } double result; if (hasImagEigenValue) { int minEigenIndex = findMinRealEigenValueIndex(bufferArray); result = eigenValues[minEigenIndex].Real; } else { result = 0.0; } return(result); }
private double ComputeScoreAndUpdateEigenValues(Member m) { double norm; double[][] jacobian = rr.getReducedJacobian(); Complex[] eigenValues = LA.GetEigenValues(jacobian); int N = eigenValues.Length; var wr = new List <double>(); var wi = new List <double>(); for (int i = 0; i < N; i++) { wr.Add(eigenValues[i].Real); wi.Add(eigenValues[i].Imag); } norm = ComputeScore(N, wr, wi); m.SetEigenValues(eigenValues); return(norm); }
private void runButton_Click(object sender, RoutedEventArgs e) { TextRange textRange = new TextRange(workField.Document.ContentStart, workField.Document.ContentEnd); string s; s = textRange.Text; LA.Source = s; ErrorMessages = new StringBuilder(); try { LA.Build(); } catch (LexicException ex) { ErrorMessages.Append(ex.Message).Append('\n'); ShowErrors(); return; } outputGrid.ItemsSource = LA.OutputTable; identificatorGrid.ItemsSource = LA.IdentificatorTable; constantGrid.ItemsSource = LA.ConstantTable; // Initializes Syntax analyzator SA = new SyntaxAnalyzator3() { Source = LA.Source, LexemTable = LA.LexemTable, ClassTable = LA.ClassTable, IdentificatorTable = LA.IdentificatorTable, ConstantTable = LA.ConstantTable, OutputTable = LA.OutputTable, CompareTable = form1.GetCompareTable }; // Syntax analyzator start try { SA.Start(); } catch (SyntaxException ex) { ErrorMessages.Append(ex.Message).Append('\n'); ShowErrors(); return; } resultGrid.ItemsSource = SA.ResultTable; // Initializes Dextri Dextri D = new Dextri { LexemTable = SA.LexemTable, ClassTable = SA.ClassTable, IdentificatorTable = SA.IdentificatorTable, ConstantTable = SA.ConstantTable, OutputTable = SA.OutputTable }; // Builds Polir. try { D.BuildPolir(); } catch { throw new Exception("Polir exception"); } polirGrid.ItemsSource = D.PolirTable; TextRange polirtextRange = new TextRange(polirField.Document.ContentStart, polirField.Document.ContentEnd); polirtextRange.Text = D.PolirToString(); labelGrid.ItemsSource = D.LabelTable; identificatorGrid.ItemsSource = D.IdentificatorTable; identificatorGrid.Items.Refresh(); // Initializes PolirCalculator PolirCalculator polirCalculator = new PolirCalculator { Polir = D.Polir, IdentificatorsTable = D.IdentificatorTable, LabelsTable = D.LabelTable }; // Calculates Polir. try { polirCalculator.Calculate(); } catch (Exception ex) { throw new Exception(ex.Message + "; Calculate exception"); } identificatorGrid.ItemsSource = polirCalculator.IdentificatorsTable; ShowErrors(); }
private void Add_Article(object sender, RoutedEventArgs e) { LA = articles.Length; articles = articles.Concat(new string[] { text }).ToArray(); // Ajout d'un nouvel article. info.Text = LA.ToString(); }