public TendonNeuralNetwork(AnalyticalBridge analyticalBridge) { foreach (PrestressingCaseResult result in analyticalBridge.PrestressingCaseResults) { if (result.DiscreteTendon.IsFullTendon()) { FullTendon fullTendon = result.DiscreteTendon.GetFullTendon(); double[] tendonOutputs = new double[result.MY.Count()]; foreach (double my in result.MY) { tendonOutputs[result.MY.IndexOf(my)] = my; } AddMember(new double[5] { fullTendon.PointA.Z, fullTendon.PointB.X, fullTendon.PointB.Z, fullTendon.PointC.Z, fullTendon.SupportRadius }, tendonOutputs); } else if (result.DiscreteTendon.IsPartialTendon()) { PartialTendon partialTendon = result.DiscreteTendon.GetPartialTendon(); double[] tendonOutputs = new double[result.MY.Count()]; foreach (double my in result.MY) { tendonOutputs[result.MY.IndexOf(my)] = my; } AddMember(new double[5] { partialTendon.PointA.Z, partialTendon.PointB.X, partialTendon.PointB.Z, partialTendon.PointC.Z, partialTendon.SupportRadius }, tendonOutputs); } } NumberOfHiddenUnits = int.Parse(analyticalBridge.PhysicalBridge.DataForm.DataFormHiddenUnits.Text); MaxNumberOfEpochs = int.Parse(analyticalBridge.PhysicalBridge.DataForm.DataFormMaxEpochs.Text); LearnRate = double.Parse(analyticalBridge.PhysicalBridge.DataForm.DataFormLearnRate.Text); double errorTreshold = double.Parse(analyticalBridge.PhysicalBridge.DataForm.DataFormErrorTreshold.Text); double error = errorTreshold + 1.000000; TimeElapsed = new Stopwatch(); TimeElapsed.Start(); Logs = analyticalBridge.PhysicalBridge.Directory + Globals.TextFiles.NeuralNetworkLogs; Initialize(int.Parse(analyticalBridge.PhysicalBridge.DataForm.DataFormTestSetSize.Text)); int epochs = 100; for (int epoch = 0; epoch < MaxNumberOfEpochs; epoch += epochs) { if (error <= errorTreshold) { break; } if (TotalEpochs >= MaxNumberOfEpochs) { break; } error = Train(epochs, errorTreshold); } PrintSummary(); }
public void Resolve(PhysicalBridge seed, string modelName, string modelDirectory) { DirectoryCopy(@seed.DataForm.DataFormSeedDir.Text, modelDirectory, true); Stopwatch caseStopWatch = new Stopwatch(); Stopwatch localStopWatch = new Stopwatch(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, false)) stopwatchSummary.WriteLine("Start:\t\t\t\t\t\t" + DateTime.Now.ToString()); caseStopWatch.Start(); localStopWatch.Start(); bool penalized = !RefreshSpan(seed); PhysicalBridge = new PhysicalBridge(seed.CommandData); PhysicalBridge.DataForm = seed.DataForm; PhysicalBridge.Name = modelName; PhysicalBridge.Directory = modelDirectory; PhysicalBridge.SpanLength.Add(double.Parse(PhysicalBridge.DataForm.DataFormSpanLength1.Text)); PhysicalBridge.SpanLength.Add(double.Parse(PhysicalBridge.DataForm.DataFormSpanLength2.Text)); PhysicalBridge.CriticalCrossSections = new List <double>(); PhysicalBridge.CriticalCrossSections.Add(0.4 * PhysicalBridge.SpanLength.First()); PhysicalBridge.CriticalCrossSections.Add(0.5 * PhysicalBridge.SpanLength.First()); PhysicalBridge.CriticalCrossSections.Add(1.0 * PhysicalBridge.SpanLength.First()); if (PhysicalBridge.SuperstructureCrossSection.Count == 0) { penalized = true; } #if SUMMGEOMETRY PhysicalBridge.PrintSummary(); #endif Document doc = PhysicalBridge.CommandData.Application.ActiveUIDocument.Document; if (!penalized) { QuantitiesAndSchedules = new QuantitiesAndSchedules(PhysicalBridge); QuantitiesAndSchedules.LoadSchedules(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Model refreshed:\t\t\t\t" + DateTime.Now.ToString() + "\t" + localStopWatch.Elapsed.ToString() + "\n"); stopwatchSummary.WriteLine("Analytical slab:"); } localStopWatch.Reset(); //Slab analysis: Stopwatch slabStopWatch = new Stopwatch(); slabStopWatch.Start(); AnalyticalSlab = new AnalyticalSlab(PhysicalBridge); slabStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Analytical slab, end time:\t\t\t" + DateTime.Now.ToString() + "\t" + slabStopWatch.Elapsed.ToString() + "\n"); stopwatchSummary.WriteLine("General model creation:"); } //Fine element method model, general loads: Stopwatch generalModelStopWatch = new Stopwatch(); generalModelStopWatch.Start(); AnalyticalBridge = new AnalyticalBridge(PhysicalBridge, int.Parse(PhysicalBridge.DataForm.DataFormSpanDivision.Text), false); generalModelStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("General model creation, end time:\t\t" + DateTime.Now.ToString() + "\t" + generalModelStopWatch.Elapsed.ToString() + "\n"); stopwatchSummary.WriteLine("Girder envelopes:"); } //General envelopes: Stopwatch envelopesStopWatch = new Stopwatch(); envelopesStopWatch.Start(); AnalyticalBridge.Envelopes = new Envelopes(PhysicalBridge, AnalyticalBridge.MobileCases.ToArray(), int.Parse(PhysicalBridge.DataForm.DataFormEnvelopeStep.Text)); envelopesStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Girder envelopes, end time:\t\t\t" + DateTime.Now.ToString() + "\t" + envelopesStopWatch.Elapsed.ToString() + "\n"); stopwatchSummary.WriteLine("Prestressed model creation:"); } //Fine element method model, prestressing loads: Stopwatch prestressingModelStopWatch = new Stopwatch(); prestressingModelStopWatch.Start(); AnalyticalPrestressedBridge = new AnalyticalBridge(PhysicalBridge, int.Parse(PhysicalBridge.DataForm.DataFormSpanDivision.Text), true); prestressingModelStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Prestressed model creation, end time:\t\t" + DateTime.Now.ToString() + "\t" + prestressingModelStopWatch.Elapsed.ToString() + "\n"); } //Tenonds, neural network, prediction of prestressing effects: Stopwatch tendonNetworkStopWatch = new Stopwatch(); tendonNetworkStopWatch.Start(); TendonNeuralNetwork = new TendonNeuralNetwork(AnalyticalPrestressedBridge); tendonNetworkStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Tendon neural network:\t\t\t\t" + DateTime.Now.ToString() + "\t" + tendonNetworkStopWatch.Elapsed.ToString()); } //Tenonds, genetic algorithm, optimization of tendons layout: Stopwatch tendonOptimizationStopWatch = new Stopwatch(); tendonOptimizationStopWatch.Start(); TendonOptimization = new TendonOptimization(PhysicalBridge, AnalyticalBridge.Envelopes, TendonNeuralNetwork); tendonOptimizationStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Tendon optimization:\t\t\t\t" + DateTime.Now.ToString() + "\t" + tendonOptimizationStopWatch.Elapsed.ToString()); } if (TendonOptimization.Result == null) { penalized = true; } if (!penalized) { //Bearing capacity check, reinforcement calculation: Stopwatch girderReinforcementStopWatch = new Stopwatch(); girderReinforcementStopWatch.Start(); AnalyticalGirders = new AnalyticalGirders(PhysicalBridge, TendonOptimization.Result.ToDiscreteTendons()); girderReinforcementStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Girders reinforcement:\t\t\t\t" + DateTime.Now.ToString() + "\t" + girderReinforcementStopWatch.Elapsed.ToString()); } localStopWatch.Start(); if (AnalyticalGirders.GirdersRebars == null) { penalized = true; } if (!penalized) { using (Transaction transaction = new Transaction(doc, "Pushing calculated data")) { transaction.Start(); if (penalized == false) { PhysicalBridge.Superstructure.LookupParameter("Masa zbrojenia").Set(AnalyticalGirders.GirdersRebars.Mass + AnalyticalSlab.SlabRebars.Mass); PhysicalBridge.Superstructure.LookupParameter("Masa sprężenia").Set(TendonOptimization.Result.Mass); PhysicalBridge.Superstructure.LookupParameter("Wskaźnik zbrojenia").Set((AnalyticalGirders.GirdersRebars.Mass + AnalyticalSlab.SlabRebars.Mass) / Converters.ToCubicMeters(PhysicalBridge.Superstructure.GetMaterialVolume(PhysicalBridge.Superstructure.GetMaterialIds(false).First()))); } else { PhysicalBridge.Superstructure.LookupParameter("Masa zbrojenia").Set(0.000); PhysicalBridge.Superstructure.LookupParameter("Masa sprężenia").Set(0.000); PhysicalBridge.Superstructure.LookupParameter("Wskaźnik zbrojenia").Set(0.000); } transaction.Commit(); } } else { using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) stopwatchSummary.WriteLine("\nModel penalized due to unresolved girders rebars arrangement."); } } else { using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) stopwatchSummary.WriteLine("\nModel penalized due to unresolved tendons layout."); } } else { using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) stopwatchSummary.WriteLine("\nModel penalized due to unresolved span geometry."); } double fitness = 0.0; if (penalized) { fitness = Math.Pow(10, 8); } else { QuantitiesAndSchedules.Calculate(true); } using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) stopwatchSummary.WriteLine("Model changes pushed:\t\t\t\t" + DateTime.Now.ToString() + "\t" + localStopWatch.Elapsed.ToString()); localStopWatch.Restart(); doc.SaveAs(Globals.RevitFiles.RevitPath(PhysicalBridge)); caseStopWatch.Stop(); localStopWatch.Stop(); using (StreamWriter stopwatchSummary = new StreamWriter(modelDirectory + Globals.TextFiles.StopwatchSummary, true)) { stopwatchSummary.WriteLine("Model saved:\t\t\t\t\t" + DateTime.Now.ToString() + "\t" + localStopWatch.Elapsed.ToString()); stopwatchSummary.WriteLine("\nTotal:\t\t\t\t\t\t\t\t\t" + caseStopWatch.Elapsed.ToString()); } }