private void LoadResearchAndGenerationParameters(Worksheet sheet, ResearchResult r) { int rowIndex = 12; string currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value; if ("Research Parameters" == sheet.get_Range("A11").Cells.Value) { while (currentParameter != null) { ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), currentParameter); r.ResearchParameterValues.Add(rp, sheet.get_Range("B" + rowIndex).Cells.Value); ++rowIndex; currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value; } rowIndex += 2; currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value; } while (currentParameter != null) { GenerationParameter gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), currentParameter); r.GenerationParameterValues.Add(gp, sheet.get_Range("B" + rowIndex).Cells.Value); ++rowIndex; currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value; } }
public bool AddResearchResult(ResearchResult researchResult) { bool f = false; try { sqlConnection = GetSqlConnection(); SqlCommand sql = new SqlCommand("INSERT INTO ResearchResult ([Id_Detail], [Name], [Parameter], [Iteration], [Stress], [Displacement]) VALUES (@idDet, @name, @param, @iter, @stress, @displ);", sqlConnection); sqlConnection.Close(); sqlConnection.Open(); sql.Parameters.AddWithValue("@idDet", researchResult.id_detail); sql.Parameters.AddWithValue("@name", researchResult.name); sql.Parameters.AddWithValue("@param", researchResult.parameter); sql.Parameters.AddWithValue("@iter", researchResult.iteration); sql.Parameters.AddWithValue("@stress", researchResult.stress); sql.Parameters.AddWithValue("@displ", researchResult.displacement); sql.ExecuteReader(); sqlConnection.Close(); f = true; } catch (System.Exception ex) { Console.WriteLine(ex); } return(f); }
private void LoadEnsembleResults(String folderName, ResearchResult r) { EnsembleResult e = new EnsembleResult(r.Size); e.EdgesCount = r.Edges; e.Result = new Dictionary <AnalyzeOption, Object>(); foreach (String fileName in Directory.GetFiles(folderName)) { /*reader.Read(); * while (reader.NodeType != XmlNodeType.EndElement) * { * AnalyzeOption opt = (AnalyzeOption)Enum.Parse(typeof(AnalyzeOption), reader.Name); * AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]); * switch (optInfo.OptionType) * { * case OptionType.Global: * e.Result.Add(opt, reader.ReadElementContentAsDouble()); * break; * case OptionType.ValueList: * case OptionType.Centrality: * e.Result.Add(opt, LoadValueList()); * reader.Read(); * break; * case OptionType.Distribution: * case OptionType.Trajectory: * e.Result.Add(opt, LoadDistribution()); * reader.Read(); * break; * default: * break; * } * }*/ } r.EnsembleResults.Add(e); }
public override ResearchResult Load(Guid researchID) { ResearchResult researchInfo = null; string folderNameToLoad = null; if (existingFolderNames != null && existingFolderNames.Keys.Contains(researchID)) { folderNameToLoad = existingFolderNames[researchID]; } else { folderNameToLoad = FileNameByGuid(researchID); } if (folderNameToLoad != null) { foreach (string folderName in Directory.GetDirectories(storageStr, "*", SearchOption.TopDirectoryOnly)) { researchInfo = new ResearchResult(); LoadGeneralInfo(folderName, researchInfo); LoadEnsembleResults(folderName, researchInfo); } } return(researchInfo); }
private void LoadResearchInfo(ResearchResult r) { if (reader.Name == "ResearchID") { r.ResearchID = new Guid(reader.ReadElementString()); } if (reader.Name == "ResearchName") { r.ResearchName = reader.ReadElementString(); } if (reader.Name == "ResearchType") { r.ResearchType = (ResearchType)Enum.Parse(typeof(ResearchType), reader.ReadElementString()); } if (reader.Name == "ModelType") { r.ModelType = (ModelType)Enum.Parse(typeof(ModelType), reader.ReadElementString()); } if (reader.Name == "RealizationCount") { r.RealizationCount = Int32.Parse(reader.ReadElementString()); } if (reader.Name == "Date") { r.Date = DateTime.Parse(reader.ReadElementString()); } if (reader.Name == "Size") { r.Size = UInt32.Parse(reader.ReadElementString()); } if (reader.Name == "Edges") { r.Edges = Double.Parse(reader.ReadElementString(), CultureInfo.InvariantCulture); } }
public override void Save(ResearchResult result) { string fileName = storageStr + result.ResearchName; if (File.Exists(fileName + ".xls") || File.Exists(fileName + ".xlsx")) { fileName += result.ResearchID; } InitializeExcelApplication(); workbook = excelApp.Workbooks.Add(); SaveGeneralInfo(result.ResearchID, result.ResearchName, result.ResearchType, result.ModelType, result.RealizationCount, result.Size, result.Edges, result.ResearchParameterValues, result.GenerationParameterValues); for (int i = 0; i < result.EnsembleResults.Count; ++i) { SaveEnsembleResult(result.ResearchName, result.EnsembleResults[i], i); } workbook.Sheets[1].Activate(); workbook.SaveAs(fileName + ".xlsx"); DestroyExcelApplication(); }
private void ManageAllocation(Entity nation, ResearchResult turn, TechTeam researcher, ResearchFrame target) { ProgressFrame liveFrame = nation.Status.Frames.FirstOrDefault(x => x.IdTag == target.IdTag); if (liveFrame != null) { // Should this check for Active/Accessible frames, or leave that to the assignment routines? Tuple <ProgressFrame, List <String> > outcome = ProcessTeam(researcher, liveFrame, BonusCalculator.CalculateEffectiveBonus(nation, researcher, target), // Get Admiral/Event Bonuses calculated for us BonusCalculator.MatchPreference(researcher, target)); // And double check the skill match turn.UpdateFrames.Add(researcher, outcome.Item1); // Commit our now updated frame to the results if (researcher.IncrementXP(target.Tree)) // Next we process xp gain and see if the team has levelled up { turn.LevelledUpTeams.Add(researcher); // If yes, make sure we mark that down } } else { throw new ArgumentException("An invalid frame was provided"); } }
public static void CheckAccessible(ResearchResult status) { Dictionary <ResearchFrame, ProgressFrame> matchup = new Dictionary <ResearchFrame, ProgressFrame>(); status.UpdateFrames.Values.ToList().ForEach(x => matchup.Add(x.ParentFrame, x)); EntityStateOfArt currentProgress = status.Parent.Status; foreach (KeyValuePair <ResearchFrame, ProgressFrame> pair in matchup) { ResearchFrame core = pair.Key; ProgressFrame active = pair.Value; if (active.IsComplete) // This will only be present if it was actively worked on this turn, so any IsComplete means it completed this turn { foreach (ResearchFrame target in core.LeadsToFrames) { ProgressFrame targetMatch = currentProgress.Frames.First(x => x.IdTag == target.IdTag); if (!targetMatch.IsComplete && !targetMatch.IsAccessible) { List <ProgressFrame> prereqs = currentProgress.Frames.Where(r => r.ParentFrame.PrereqFrames.Contains(target)).ToList(); if (prereqs.All(x => x.IsComplete)) { targetMatch.IsAccessible = true; } } } } } }
public override void Save(ResearchResult result) { string fileName = storageStr + result.ResearchName; if (File.Exists(fileName + ".xml")) { fileName += result.ResearchID; } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineOnAttributes = true; using (writer = XmlWriter.Create(fileName + ".xml", settings)) { writer.WriteStartDocument(true); writer.WriteStartElement("Research"); SaveResearchInfo(result.ResearchID, result.ResearchName, result.ResearchType, result.ModelType, result.RealizationCount, result.Date, result.Size, result.Edges); SaveResearchParameters(result.ResearchParameterValues); SaveGenerationParameters(result.GenerationParameterValues); writer.WriteStartElement("Ensembles"); for (int i = 0; i < result.EnsembleResults.Count; ++i) { SaveEnsembleResult(result.ResearchName, result.EnsembleResults[i], i); } writer.WriteEndElement(); writer.WriteEndElement(); } }
private static void SortExistingResultsByGroups() { existingResultsByGroups.Clear(); List <ResearchResult> temp = storage.LoadAllResearchInfo(); int k = 0; while (temp.Count != 0) { List <Guid> current = new List <Guid>(); ResearchResult currentResult = temp[0]; current.Add(currentResult.ResearchID); temp.Remove(currentResult); int i = 0; while (i < temp.Count()) { if (temp[i].ModelType == currentResult.ModelType && temp[i].ResearchType == currentResult.ResearchType && temp[i].Size == currentResult.Size && AreParametersCompatible(temp[i], currentResult)) { current.Add(temp[i].ResearchID); temp.Remove(temp[i]); } else { ++i; } } existingResultsByGroups.Add(k, current); ++k; } return; }
public override ResearchResult Load(Guid researchID) { ResearchResult r = null; string fileNameToLoad = null; if (existingFileNames != null && existingFileNames.Keys.Contains(researchID)) { fileNameToLoad = existingFileNames[researchID]; } else { fileNameToLoad = FileNameByGuid(researchID); } InitializeExcelApplication(); Workbook book = null; Worksheet sheet = null; if (fileNameToLoad != null) { r = new ResearchResult(); book = excelApp.Workbooks.Open(fileNameToLoad); sheet = (Worksheet)book.Worksheets[1]; LoadResearchInfo(sheet, r); LoadResearchAndGenerationParameters(sheet, r); LoadEnsembleResults(book, r); } book.Close(); Marshal.ReleaseComObject(book); DestroyExcelApplication(); return(r); }
private SortedDictionary <Double, Double> CalculateDoubleAverage(AnalyzeOption opt) { SortedDictionary <Double, Double> temp = new SortedDictionary <Double, Double>(); ResearchResult tr = null; foreach (Guid id in researches) { tr = StatSessionManager.GetResearchResult(id); Debug.Assert(tr.EnsembleResults.Count == 1); // TODO fix it if (!tr.EnsembleResults[0].Result.ContainsKey(opt)) { continue; } Debug.Assert(tr.EnsembleResults[0].Result[opt] != null); Debug.Assert(tr.EnsembleResults[0].Result[opt] is SortedDictionary <Double, Double>); SortedDictionary <Double, Double> d = tr.EnsembleResults[0].Result[opt] as SortedDictionary <Double, Double>; foreach (KeyValuePair <Double, Double> k in d) { double value = Math.Round(k.Value * tr.RealizationCount / RealizationCountSum, 4); if (temp.ContainsKey(k.Key)) { temp[k.Key] += value; } else { temp.Add(k.Key, value); } } } return(temp); }
public override ResearchResult Load(string name) { ResearchResult r = null; if (name != null) { r = new ResearchResult(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; using (reader = XmlReader.Create(name, settings)) { while (reader.Read() && (reader.NodeType != XmlNodeType.Element || reader.Name == "Research")) { } LoadResearchInfo(r); LoadResearchParameters(r); LoadGenerationParameters(r); LoadEnsembleResults(r); } } return(r); }
internal ResearchTopicInfo(ResearchProgress tech, ResearchResult investmentResult) { this.Topic = tech.Topic; this.textVars = new Var(DevelopmentTopic.LevelKey, tech.NextLevel).Get; this.Cost = tech.Topic.Cost.Evaluate(textVars); this.InvestedPoints = tech.InvestedPoints; this.Investment = investmentResult.InvestedPoints; this.Level = tech.Level; this.NextLevel = investmentResult.CompletedCount > 1 ? tech.Level + (int)investmentResult.CompletedCount : tech.NextLevel; }
private void LoadResearchInfo(Worksheet sheet, ResearchResult r) { r.ResearchID = new Guid((string)sheet.get_Range("B2").Cells.Value); r.ResearchName = sheet.get_Range("B3").Cells.Value; r.ResearchType = (ResearchType)Enum.Parse(typeof(ResearchType), (string)sheet.get_Range("B4").Cells.Value); r.ModelType = (ModelType)Enum.Parse(typeof(ModelType), (string)sheet.get_Range("B5").Cells.Value); r.RealizationCount = (Int32)sheet.get_Range("B6").Cells.Value; r.Date = sheet.get_Range("B7").Cells.Value; r.Size = (UInt32)sheet.get_Range("B8").Cells.Value; r.Edges = sheet.get_Range("B9").Cells.Value; }
/// <summary> /// Calculates summary of realizations and the average value of edges. /// </summary> private void CalculateInfo() { ResearchResult tr = null; foreach (Guid id in researches) { tr = StatSessionManager.GetResearchResult(id); RealizationCountSum += tr.RealizationCount; EdgesCountAvg += tr.Edges * tr.RealizationCount; } EdgesCountAvg = Math.Round(EdgesCountAvg / RealizationCountSum, 4); }
private void LoadGenerationParameters(ResearchResult r) { while (reader.Read()) { if (reader.Name == "GenerationParameter") { reader.MoveToAttribute("name"); string g = reader.ReadContentAsString(); GenerationParameter gp; if (g == "FileName") { gp = GenerationParameter.AdjacencyMatrix; } else { gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), g); } reader.MoveToAttribute("value"); GenerationParameterInfo gpInfo = (GenerationParameterInfo)(gp.GetType().GetField(gp.ToString()).GetCustomAttributes(typeof(GenerationParameterInfo), false)[0]); if (gpInfo.Type.Equals(typeof(UInt32))) { r.GenerationParameterValues.Add(gp, UInt32.Parse(reader.Value)); } else if (gpInfo.Type.Equals(typeof(Double))) { r.GenerationParameterValues.Add(gp, Double.Parse(reader.Value, CultureInfo.InvariantCulture)); } else if (gpInfo.Type.Equals(typeof(Boolean))) { r.GenerationParameterValues.Add(gp, Boolean.Parse(reader.Value)); } else if (gpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = reader.Value; r.GenerationParameterValues.Add(gp, mp); } else { Debug.Assert(false); //throw new InvalidGenerationParameters(); } } if (reader.Name == "Ensembles") { break; } } }
internal ResearchTopicInfo(ResearchProgress tech, ResearchResult investmentResult, IEnumerable <DevelopmentTopic> developmentTopics) { this.topic = tech.Topic; this.textVars = new Var(DevelopmentTopic.LevelKey, tech.NextLevel).Get; this.Cost = tech.Topic.Cost.Evaluate(textVars); this.InvestedPoints = tech.InvestedPoints; this.Investment = investmentResult.InvestedPoints; this.Level = tech.Level; this.NextLevel = investmentResult.CompletedCount > 1 ? tech.Level + (int)investmentResult.CompletedCount : tech.NextLevel; this.Unlocks = tech.Topic.Unlocks[tech.NextLevel].Select(id => new DevelopmentTopicInfo(new DevelopmentProgress( developmentTopics.First(x => x.IdCode == id), tech.Owner) )).ToArray(); }
public override void Save(ResearchResult result) { string dirName = GetFileName(result.ResearchID, result.ResearchName); Directory.CreateDirectory(dirName); SaveGeneralInfo(dirName, result.ResearchID, result.ResearchName, result.ResearchType, result.ModelType, result.RealizationCount, result.Size, result.Edges, result.ResearchParameterValues, result.GenerationParameterValues); for (int i = 0; i < result.EnsembleResults.Count; ++i) { SaveEnsembleResult(dirName, result.ResearchName, result.EnsembleResults[i], i); } }
private void LoadEnsembleResults(Workbook book, ResearchResult r) { EnsembleResult e = new EnsembleResult(r.Size); //e.NetworkSize = r.Size; e.EdgesCount = r.Edges; e.Result = new Dictionary <AnalyzeOption, Object>(); Array existingOptions = Enum.GetValues(typeof(AnalyzeOption)); foreach (AnalyzeOption opt in existingOptions) { AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]); switch (optInfo.OptionType) { case OptionType.Global: Double v = FindValueInGlobals(book, optInfo.FullName); if (v != -1) { e.Result.Add(opt, v); } break; case OptionType.ValueList: Object vl = LoadValueList(book, optInfo); if (vl != null) { e.Result.Add(opt, vl); } break; case OptionType.Distribution: case OptionType.Trajectory: Object vd = LoadDistribution(book, optInfo); if (vd != null) { e.Result.Add(opt, vd); } break; default: break; } } r.EnsembleResults.Add(e); }
private void LoadResearchParameters(ResearchResult r) { while (reader.Read()) { if (reader.Name == "ResearchParameter") { reader.MoveToAttribute("name"); ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), reader.ReadContentAsString()); reader.MoveToAttribute("value"); ResearchParameterInfo rpInfo = (ResearchParameterInfo)(rp.GetType().GetField(rp.ToString()).GetCustomAttributes(typeof(ResearchParameterInfo), false)[0]); if (rpInfo.Type.Equals(typeof(UInt32))) { r.ResearchParameterValues.Add(rp, UInt32.Parse(reader.Value)); } else if (rpInfo.Type.Equals(typeof(Double))) { r.ResearchParameterValues.Add(rp, Double.Parse(reader.Value, CultureInfo.InvariantCulture)); } else if (rpInfo.Type.Equals(typeof(Boolean))) { r.ResearchParameterValues.Add(rp, Boolean.Parse(reader.Value)); } else if (rpInfo.Type.Equals(typeof(ResearchType))) { r.ResearchParameterValues.Add(rp, reader.Value); } else if (rpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = reader.Value; r.ResearchParameterValues.Add(rp, mp); } else { Debug.Assert(false); //throw new InvalidResearchParameters(); } } else if (reader.Name == "GenerationParameterValues") { break; } } }
public override List <ResearchResult> LoadAllResearchInfo() { existingFolderNames = new SortedDictionary <Guid, string>(); List <ResearchResult> researchInfos = new List <ResearchResult>(); ResearchResult researchInfo = null; foreach (string folderName in Directory.GetDirectories(storageStr, "*", SearchOption.TopDirectoryOnly)) { researchInfo = new ResearchResult(); LoadGeneralInfo(folderName, researchInfo); researchInfos.Add(researchInfo); existingFolderNames.Add(researchInfo.ResearchID, folderName); } return(researchInfos); }
public override ResearchResult Load(string name) { ResearchResult researchInfo = null; if (name != null) { foreach (string folderName in Directory.GetDirectories(storageStr, "*", SearchOption.TopDirectoryOnly)) { researchInfo = new ResearchResult(); LoadGeneralInfo(folderName, researchInfo); LoadEnsembleResults(folderName, researchInfo); existingFolderNames.Add(researchInfo.ResearchID, folderName); } } return(researchInfo); }
private void LoadEnsembleResults(ResearchResult r) { while (reader.Read()) { if (reader.Name == "Ensemble" && !reader.IsEmptyElement) { EnsembleResult e = new EnsembleResult(r.Size); //e.NetworkSize = r.Size; e.EdgesCount = r.Edges; e.Result = new Dictionary <AnalyzeOption, Object>(); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { AnalyzeOption opt = (AnalyzeOption)Enum.Parse(typeof(AnalyzeOption), reader.Name); AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]); switch (optInfo.OptionType) { case OptionType.Global: e.Result.Add(opt, reader.ReadElementContentAsDouble()); break; case OptionType.ValueList: case OptionType.Centrality: e.Result.Add(opt, LoadValueList()); reader.Read(); break; case OptionType.Distribution: case OptionType.Trajectory: e.Result.Add(opt, LoadDistribution()); reader.Read(); break; default: break; } } r.EnsembleResults.Add(e); } } }
/// <summary> /// Checks if specified results are compatible for statistic analyze. /// </summary> /// <param name="r1">First result.</param> /// <param name="r2">Second result</param> /// <returns>True, if results are compatible. False otherwise</returns> /// <note>Research result must have same researchType and modelType.</note> private static bool AreParametersCompatible(ResearchResult r1, ResearchResult r2) { foreach (GenerationParameter gp in r1.GenerationParameterValues.Keys) { if (r1.GenerationParameterValues[gp].ToString() != r2.GenerationParameterValues[gp].ToString()) { return(false); } } foreach (ResearchParameter rp in r1.ResearchParameterValues.Keys) { if (r1.ResearchParameterValues[rp].ToString() != r2.ResearchParameterValues[rp].ToString()) { return(false); } } return(true); }
public override List <ResearchResult> LoadAllResearchInfo() { existingFileNames = new SortedDictionary <Guid, string>(); List <ResearchResult> researchInfos = new List <ResearchResult>(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; ResearchResult DoubleResearchInfo = null; foreach (string fileName in Directory.GetFiles(storageStr, "*.xml", SearchOption.TopDirectoryOnly)) { DoubleResearchInfo = new ResearchResult(); using (reader = XmlReader.Create(fileName, settings)) { try { while (reader.Read() && (reader.NodeType != XmlNodeType.Element || reader.Name == "Research")) { } LoadResearchInfo(DoubleResearchInfo); LoadResearchParameters(DoubleResearchInfo); LoadGenerationParameters(DoubleResearchInfo); researchInfos.Add(DoubleResearchInfo); existingFileNames.Add(DoubleResearchInfo.ResearchID, fileName); } catch (SystemException ex) { continue; } } } return(researchInfos); }
/// <summary> /// Calculates the average value of specified global analyze option. /// </summary> /// <param name="opt">Analyze option.</param> public void CalculateGlobalOption(AnalyzeOption opt) { if (EnsembleResultsAvg.Count != 0 && EnsembleResultsAvg[0].Result.ContainsKey(opt)) { return; } ResearchResult tr = null; AnalyzeOptionInfo[] info = (AnalyzeOptionInfo[])opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false); Debug.Assert(info[0].OptionType == OptionType.Global); double avg = 0; foreach (Guid id in researches) { tr = StatSessionManager.GetResearchResult(id); Debug.Assert(tr.EnsembleResults.Count == 1); // TODO fix it if (!tr.EnsembleResults[0].Result.ContainsKey(opt)) { continue; } Debug.Assert(tr.EnsembleResults[0].Result[opt] != null); avg += Convert.ToDouble(tr.EnsembleResults[0].Result[opt]) * tr.RealizationCount; } avg /= RealizationCountSum; EnsembleResult er = null; if (EnsembleResultsAvg.Count == 0) { er = new EnsembleResult(0); EnsembleResultsAvg.Add(er); } else { er = EnsembleResultsAvg[0]; } er.Result.Add(opt, Math.Round(avg, 4)); }
public List <ResearchResult> GetResearchResults() { List <ResearchResult> list = new List <ResearchResult>(); try { sqlConnection = GetSqlConnection(); SqlCommand sql = new SqlCommand("SELECT * from ResearchResult", sqlConnection); sqlConnection.Close(); sqlConnection.Open(); SqlDataReader sDR = sql.ExecuteReader(); if (sDR.HasRows) { while (sDR.Read()) { ResearchResult result = new ResearchResult(); result.id = sDR.GetInt32(0); result.id_detail = sDR.GetInt32(1); result.name = sDR.GetString(2); result.parameter = sDR.GetString(3); result.iteration = sDR.GetInt32(4); result.stress = sDR.GetFloat(5); result.displacement = sDR.GetFloat(6); list.Add(result); } } sqlConnection.Close(); } catch (System.Exception ex) { //DialogManager.showDialogError("Возможна ошибка базы данных! Проверьте!", "Внимание!"); Console.WriteLine(ex); } return(list); }
/// <summary> /// The entry point of the processing routine. /// </summary> /// <returns>The list of all research results</returns> public List <ResearchResult> ProcessMaster() { List <ResearchResult> researchResults = new List <ResearchResult>(); foreach (Entity nation in Master.MasterEntityList) { ResearchResult turn = new ResearchResult() { Parent = nation, EntityId = nation.Name }; // We only want live assignments, on the off-chance that a team has not been given an assignment, it does not need to be processed. foreach (KeyValuePair <TechTeam, ResearchFrame> allocation in nation.Assignments.Where(x => x.Value != null)) { ManageAllocation(nation, turn, allocation.Key, allocation.Value); } researchResults.Add(turn); } return(researchResults); }
public override ResearchResult Load(string name) { ResearchResult r = null; if (name != null) { InitializeExcelApplication(); Workbook book = null; Worksheet sheet = null; r = new ResearchResult(); book = excelApp.Workbooks.Open(name); sheet = (Worksheet)book.Worksheets[1]; LoadResearchInfo(sheet, r); LoadResearchAndGenerationParameters(sheet, r); LoadEnsembleResults(book, r); book.Close(); Marshal.ReleaseComObject(book); DestroyExcelApplication(); } return(r); }
public unsafe override ResearchResult GetResult(float _a, float _b, double p1, double p2, double p3) { property1 = p1; property2 = p2; property3 = p3; UInt64 a, b, n; { double limit = (double)_a; a = *(UInt64*)(&limit); limit = (double)_b; b = *(UInt64*)(&limit); n = b - a; } UInt64 space; if (count < n) space = (n / (count)); else { space = 1; count = n; } ResearchResult result = new ResearchResult { Y = new double[count], X = new double[count], AbsoluteError = new double[count], RelativeError = new double[count], Name = "InvSqrtDouble" }; var i = 0; double x; UInt64 k = 0; double dx; double basicSqrt; double invSqrt; UInt64 temp = *(UInt64*)&a; while (i < (int)count) { x = *(double*)&temp; basicSqrt = 1f / Math.Sqrt(x); { double xhalf = 0.5 * x; UInt64 j = *(UInt64*)(&x); j = 0x5fe6eb50c7b537a9 - (j >> 1); x = *(double*)&j; if (property1 != 0) { double c = xhalf * x * x; x = x * (property1 - c * (2.5 - 1.5 * c)); } if (property2 != 0) x = x * (property2 - xhalf * x * x); if (property3 != 0) x = x * (property3 - xhalf * x * x); invSqrt = x; } dx = invSqrt - basicSqrt; if (dx / basicSqrt > result.max) { result.max = dx / basicSqrt; result.xmax = *(double*)&temp; } if (dx / basicSqrt < result.min) { result.min = dx / basicSqrt; result.xmin = *(double*)&temp; } if (k > space) { result.Y[i] = invSqrt; result.AbsoluteError[i] = dx; result.RelativeError[i] = dx / basicSqrt; result.X[i] = *(double*)&temp; i++; ready = i; k = 1; } k = k + 1000000000; temp = temp + 1000000000; } UInt64 step = 1000000000; UInt64 steplimith = step; UInt64 LimithA; UInt64 LimithB; while (step > 1) { { double convMax = result.xmax; LimithA = *(UInt64*)&convMax - steplimith; LimithB = *(UInt64*)&convMax + steplimith; } //Step 2 refinement of MAX+ step /= 10; temp = LimithA; while (temp < LimithB) { x = *(double*)&temp; basicSqrt = 1f / Math.Sqrt(x); { double xhalf = 0.5 * x; UInt64 j = *(UInt64*)(&x); j = 0x5fe6eb50c7b537a9 - (j >> 1); x = *(double*)&j; if (property1 != 0) { double c = xhalf * x * x; x = x * (property1 - c * (2.5 - 1.5 * c)); } if (property2 != 0) x = x * (property2 - xhalf * x * x); if (property3 != 0) x = x * (property3 - xhalf * x * x); invSqrt = x; } dx = invSqrt - basicSqrt; if (dx / basicSqrt > result.max) { result.max = dx / basicSqrt; result.xmax = *(double*)&temp; steplimith = step; } k = k + step; temp = temp + step; } } step = 1000000000; while (step > 1) { { double convMin = result.xmin; LimithA = *(UInt64*)&convMin - steplimith; LimithB = *(UInt64*)&convMin + steplimith; } //Step 2 refinement of MAX- step /= 10; temp = LimithA; while (temp < LimithB) { x = *(double*)&temp; basicSqrt = 1f / Math.Sqrt(x); { double xhalf = 0.5 * x; UInt64 j = *(UInt64*)(&x); j = 0x5fe6eb50c7b537a9 - (j >> 1); x = *(double*)&j; if (property1 != 0) { double c = xhalf * x * x; x = x * (property1 - c * (2.5 - 1.5 * c)); } if (property2 != 0) x = x * (property2 - xhalf * x * x); if (property3 != 0) x = x * (property3 - xhalf * x * x); invSqrt = x; } dx = invSqrt - basicSqrt; if (dx / basicSqrt < result.min) { result.min = dx / basicSqrt; result.xmin = *(double*)&temp; steplimith = step; } k = k + step; temp = temp + step; } } return result; }
public unsafe override ResearchResult GetResult(float _a, float _b, double p1, double p2, double p3 = 0) { property1 = p1; property2 = p2; int a = *(int*)(&_a); int b = *(int*)(&_b); UInt64 n = (UInt64)(b - a); ResearchResult result = new ResearchResult { Y = new double[count], X = new double[count], AbsoluteError = new double[count], RelativeError = new double[count], Name = "InvSqrtFloatFixed" }; int space; if (count < n) space = (int)(n / count); else { space = 1; count = n; } var i = 0; var temp = a; int k = 0; float x; double dx; double basicSqrt; double invSqrt; while (i < (int)count) { x = *(float*)&temp; basicSqrt = 1f / Math.Sqrt(x); { int mx = temp % 8388608; float xx; if ((temp >> 23) % 2 == 1) { xx = 0.25f + *(float*)&mx; } else { double xt = 0.5 + 3627654D / 8388608D; if (xt > *(float*)&mx) xx = 0.5f + (*(float*)&mx) / 2; else xx = 0.125f + (*(float*)&mx) / 8; } float xhalf = 0.5f * xx; if (property1 != 0) { float r1 = (Single)property1 - xhalf * x * x; x = x * (1f + r1); } if (property2 != 0) { float r2 = (Single)property2 - xhalf * x * x; x = x * (1f + r2); } int rez = (temp / 8388608 + (*(int*)&x) % 8388608); invSqrt = *(float*)&rez; } dx = invSqrt - basicSqrt; if (dx / basicSqrt > result.max) { result.max = dx / basicSqrt; result.xmax = *(float*)&temp; } if (dx / basicSqrt < result.min) { result.min = dx / basicSqrt; result.xmin = *(float*)&temp; } if (k > space) { result.Y[i] = invSqrt; result.AbsoluteError[i] = dx; result.RelativeError[i] = dx / basicSqrt; result.X[i] = *(float*)&temp; i++; k = 1; } k++; temp++; ready = i; } return result; }
public unsafe override ResearchResult GetResult(float _a, float _b, double p1, double p2, double p3 = 0 ) { property1 = p1; property2 = p2; int a = *(int*)(&_a); int b = *(int*)(&_b); UInt64 n = (UInt64)(b - a); ResearchResult result = new ResearchResult { Y = new double[count], X = new double[count], AbsoluteError = new double[count], RelativeError = new double[count], Name = "InvSqrtFloat" }; int space; if (count < n) space = (int)(n / count); else { space = 1; count = n; } var i = 0; var temp = a; int k = 0; float x; double dx; double basicDiv; double invDiv; while (i < (int)count) { x = *(float*)&temp; float y = x; basicDiv = 1f / x; { int j = *(int*)(&x); j = 0x7ef311c3 - j; y = *(float*)&j; if (property1 != 0) y = y * ((Single)property1 - y * x); if (property2 != 0) y = (Single)(y * (property2 - y * x)); invDiv = y; } dx = invDiv - basicDiv; if (dx / basicDiv > result.max) { result.max = dx / basicDiv; result.xmax = *(float*)&temp; } if (dx / basicDiv < result.min) { result.min = dx / basicDiv; result.xmin = *(float*)&temp; } if (k > space) { result.Y[i] = invDiv; result.AbsoluteError[i] = dx; result.RelativeError[i] = dx / basicDiv; result.X[i] = *(float*)&temp; i++; k = 1; } k++; temp++; ready = i; } return result; }
public unsafe override ResearchResult GetResult(float _a, float _b, double p1, double p2, double p3 = 0) { property1 = p1; property2 = p2; int a = *(int*)(&_a); int b = *(int*)(&_b); UInt64 n = (UInt64)(b - a); ResearchResult result = new ResearchResult { Y = new double[count], X = new double[count], AbsoluteError = new double[count], RelativeError = new double[count], Name = "InvSqrtFloatUp" }; int space; if (count < n) space = (int)(n / count); else { space = 1; count = n; } var i = 0; var temp = a; int k = 0; float x; double dx; double basicSqrt; double invSqrt; while (i < (int)count) { x = *(float*)&temp; basicSqrt = 1f / Math.Sqrt(x); { float xhalf = 0.5f * x; int j = *(int*)(&x); j = 0x5f375a86 - (j >> 1); x = *(float*)&j; if (property1 != 0) { float c = xhalf * x * x; x = x * (1.875f - c * (2.5f - 1.5f * c)); } if (property2 != 0) x = x * (1.5f - xhalf * x * x); invSqrt = x; } dx = invSqrt - basicSqrt; if (dx / basicSqrt > result.max) { result.max = dx / basicSqrt; result.xmax = *(float*)&temp; } if (dx / basicSqrt < result.min) { result.min = dx / basicSqrt; result.xmin = *(float*)&temp; } if (k > space) { result.Y[i] = invSqrt; result.AbsoluteError[i] = dx; result.RelativeError[i] = dx / basicSqrt; result.X[i] = *(float*)&temp; i++; k = 1; } k++; temp++; ready = i; } return result; }