private void CreateConnection(ConnectionTemplate ct, CrossReferencedDictionary <string, Module> modules) { if (ct.SourceIndex == -1) { if (ct.DestIndex == -1) { Connections.NewConnection(modules[ct.Source], modules[ct.Dest]); } else { Connections.NewConnection(modules[ct.Source], modules[ct.Dest], ct.DestIndex); } } else { if (ct.DestIndex == -1) { Connections.NewConnection(modules[ct.Source], ct.SourceIndex, modules[ct.Dest]); } else { Connections.NewConnection(modules[ct.Source], ct.SourceIndex, modules[ct.Dest], ct.DestIndex); } } }
/// <summary> /// Sets up the initial connections for a brand new Net /// </summary> protected void InitializeConnections() { ConnectionTemplate[] conTmpl = new ConnectionTemplate[Inputs * Outputs]; // create templates for all possible connections for (int i = 0, c = 0; i < Inputs; i++) { for (int o = 0; o < Outputs; o++) { conTmpl[c++] = new ConnectionTemplate(generator.Next, i, o); } } // mix them up SortUtils.Shuffle(conTmpl, _rng); // make up a number between the max possible connections and zero int connectionCount = (int)NumericsUtils.ProbabilisticRound(conTmpl.Length * 0.075, _rng); connectionCount = System.Math.Max(2, connectionCount); // create that many actual connections for (int i = 0; i < connectionCount; i++) { Node input = Neurons[i]; Node output = Neurons[i + Inputs]; Connection con = new Connection(_rng.NextUInt(), input, output, _rng.NextDouble() * 2.0 - 1.0, _rng.NextDouble() * -5.0) { Enabled = true }; Connections.Add(con); } }
/// <summary> /// Loads an Connection Template object from a XML file. /// </summary> /// <param name="xmlFileName">the path to the xml file</param> /// <returns>Connection Template</returns> public ConnectionTemplate LoadFromXmlFile(string xmlFileName) { // since xml contains dictionairies xmlSerializer doesn not work. // use DataContractSerializer instead.https://theburningmonk.com/2010/05/net-tips-xml-serialize-or-deserialize-dictionary-in-csharp/ // all unique operations should be referenced in list: CutBeamByBeamData , add if error DataContractSerializer serializer = new DataContractSerializer(typeof(ConnectionTemplate), new List <Type>() { typeof(CutBeamByBeamData) }); using (FileStream fileStream = new FileStream(xmlFileName, FileMode.Open)) { XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fileStream, new XmlDictionaryReaderQuotas()); this.connectionTemplate = (ConnectionTemplate)serializer.ReadObject(reader); reader.Close(); fileStream.Close(); } return(connectionTemplate); }
/// <summary> /// Map the weld IDs and operation Ids corresponding to ids used by Idea /// </summary> public void MapWeldsIdsAndOperationIds() { // no direct relation between weld ID and operation is present. // therefore we will derive this relation by specificating of unique sizes for welds // as adjustment of the template //steps: // 0 temporary store welds sizes // 1 Set unique welds sizes // 2 Analyse // 3 match weld and operation // 4 reset weld sizes // 0+1 temporary store welds sizes and set unique weld sizes //4.Modify template set unique weldsizes //4.1.in cornerjoints there are weldless workshop operations List <CutBeamByBeamData> cut = new List <CutBeamByBeamData>(); ConnectionTemplate connectionTemplate1 = this.connectionTemplateGenerator.connectionTemplate; foreach (var c in connectionTemplate1.Properties.Items) { if (c.Value.GetType() == typeof(CutBeamByBeamData)) { CutBeamByBeamData cutBeamByBeamData = (c.Value as CutBeamByBeamData); if (cutBeamByBeamData.FlangesWeld != null) { cut.Add(cutBeamByBeamData); } } } //4.2 double flangesize = 0.001; //flange odd double websize = 0.002; //web even List <ConnectingMember> conlist2 = joint.attachedMembers.OfType <ConnectingMember>().ToList(); foreach (ConnectingMember con in conlist2) { foreach (CutBeamByBeamData c in cut) { string modifiedObject = c.ModifiedObjectPath; string modifiedId = modifiedObject.Remove(0, 18).Remove(1, 1); int modId = Convert.ToInt32(modifiedId); if (con.ideaOperationID == modId) { if (con.flangeWeld.weldType == Weld.WeldType.Fillet) { c.FlangesWeld.WeldType = WeldTypeCode.Fillet; c.Weld.WeldType = WeldTypeCode.Fillet; } else { c.FlangesWeld.WeldType = WeldTypeCode.DoubleFillet; c.Weld.WeldType = WeldTypeCode.DoubleFillet; } c.FlangesWeld.Size = flangesize; //m con.flangeWeld.size = flangesize * 1000; //m to mm c.Weld.Size = websize; //m con.webWeld.size = websize * 1000; //m to mm } } flangesize = flangesize + 0.002; //flange odd websize = websize + 0.002; //web evem } // 2 run analysis this.RunAnalysis(); //8. get connection data IdeaRS.OpenModel.Connection.ConnectionData connectionData = this.GetConnectionData(); // 3 match weld and operaton: foreach (IdeaRS.OpenModel.Connection.WeldData weldData in connectionData.Welds) { foreach (ConnectingMember con in this.joint.attachedMembers.OfType <ConnectingMember>().ToList()) { if (weldData.Thickness == (con.flangeWeld.size) / 1000)//compare m with mm { con.flangeWeld.Ids.Add(weldData.Id); } else { if (weldData.Thickness == (con.webWeld.size) / 1000)//compare m with mm { con.webWeld.Ids.Add(weldData.Id); } } } } // 5 reset original weldsizes double startsize = this.joint.project.minthroat; foreach (ConnectingMember con in this.joint.attachedMembers.OfType <ConnectingMember>().ToList()) { con.flangeWeld.size = startsize; con.webWeld.size = startsize; } this.connectionTemplateGenerator.UpdateTemplate(joint); }
/// <summary> /// Calls method IdeaRS.ConnectionLink.ConnectionLink.OpenIdeaConnection to run Idea Connection /// </summary> /// <param name="iomFilePath">IOM filename - includes geometry of the connection (connected members)</param> /// <param name="templateFilePath">Idea connection template or connection project file name</param> /// <param name="isHiddenCalculation">Set true to run hidden calculation </param> private void OpenIOMInIdeaCon2(string iomFilePath, string templateFilePath, bool isHiddenCalculation, ConnectionTemplate connectionTemplate = null) { //reset weld update foreach (WeldMatch w in weldMathes) { w.increase = false; } FileStream fs = new FileStream(iomFilePath, FileMode.Open, FileAccess.Read); FileStream fsr = null; string filenameRes = iomFilePath + "R"; //nb: PGC should be referenced by an input parameter instead of name + R ... if (System.IO.File.Exists(filenameRes)) { fsr = new FileStream(filenameRes, FileMode.Open, FileAccess.Read); } FileStream connTemplateStream = null; FileStream connProjectStream = null; MemoryStream importSettingsStream = null; if (!string.IsNullOrEmpty(templateFilePath) && File.Exists(templateFilePath)) { string fileExt = System.IO.Path.GetExtension(templateFilePath); bool isConProject = fileExt.Equals(".ideacon", StringComparison.InvariantCultureIgnoreCase); if (isConProject) { connProjectStream = new FileStream(templateFilePath, FileMode.Open, FileAccess.Read); } else { connTemplateStream = new FileStream(templateFilePath, FileMode.Open, FileAccess.Read); } } if (dynLinkLazy.Value != null) { //PGC: TEST importsettings and hiddenanalysis //IMPORT SETTINGS IdeaConImportSettings ideaConImportSettings = new IdeaConImportSettings(); ideaConImportSettings.UseWizard = false; //show the wizard ideaConImportSettings.OnePageWizard = true; //show one page or multipage wizard ideaConImportSettings.DefaultBoltAssembly = "M12 4.6"; //is also default ideaConImportSettings.DesignCode = "ECEN"; //this is also default ideaConImportSettings.StartIdeaStaticaApp = true; //this is also default ideaConImportSettings.WaitForExit = true; //this is also default //serialize importsettings to XML and memory stream importSettingsStream = new MemoryStream(); StreamWriter writer = new StreamWriter(importSettingsStream, new System.Text.UTF8Encoding()); XmlSerializer serializer = new XmlSerializer(typeof(IdeaConImportSettings)); serializer.Serialize(writer, ideaConImportSettings); importSettingsStream.Flush(); importSettingsStream.Seek(0, SeekOrigin.Begin); //Hidden analysis // dynLinkLazy.Value.OpenIdeaConnection(fs, fsr, connProjectStream, connTemplateStream, importSettingsStream, true); dynLinkLazy.Value.RunHiddenAnalysis(fs, fsr, connProjectStream, connTemplateStream, importSettingsStream, true); //retrieves the file name string filename = dynLinkLazy.Value.TempFileFullName; ////retrieves projectinfo as xml + deserialize xml back to ConProjectInfo object //String projectinfoXML = dynLinkLazy.Value.GetConnectionProjectInfo(filename); //ConProjectInfo conProjectInfo = new XmlSerializer(typeof(ConProjectInfo)).Deserialize(new StringReader(projectinfoXML)) as ConProjectInfo; ////select first connection //ConnectionInfo con = conProjectInfo.Connections.First(); ////retrieves connection data as xml + deserialize xml back to ConnectionData object //var connectiondataXML= dynLinkLazy.Value.GetConnectionDataXML(new Guid(con.Identifier)); ////ConnectionData connectionData= new XmlSerializer(typeof(ConnectionData)).Deserialize(new StringReader(connectiondataXML)) as ConnectionData; //IdeaRS.OpenModel.Connection.ConnectionData connectionData = new XmlSerializer(typeof(IdeaRS.OpenModel.Connection.ConnectionData)).Deserialize(new StringReader(connectiondataXML)) as IdeaRS.OpenModel.Connection.ConnectionData; //List<int> weldIds = connectionData.Welds.Select(a => a.Id).ToList(); ////In eerste instantie heeft elke las een unieke dikte gekregen. Deze diktes zijn terug te vinden in "conncetionTemplate". ////De lasdiktes in het project worden uit "connectionData" gehaald. Deze worden gematcht met de unieke lasdikten. ////Hieruit wordt bepaald of het een web-las of flens-las is. Daarna wordt het toegevoegd aan de lijst weldmatches. ////match weld thickness with corresponding operation: //bool templatechanged = false; //if (tel == 0) //{ // foreach (IdeaRS.OpenModel.Connection.WeldData weldData in connectionData.Welds) // { // foreach (CutBeamByBeamData c in connectionTemplate.Properties.Items.Values) // { // if (c.FlangesWeld.Size == weldData.Thickness) // { // //het is flange // //het is dit element // WeldMatch w = new WeldMatch(weldData.Id, true, c.Name, c.FlangesWeld.Size); // weldMathes.Add(w); // } // else // { // if (c.Weld.Size == weldData.Thickness) // { // //het is het web // //het is dit element // WeldMatch w = new WeldMatch(weldData.Id, false, c.Name, c.Weld.Size); // weldMathes.Add(w); // } // } // } // } // templatechanged = true; // //set start lassen // foreach (var c in connectionTemplate.Properties.Items) // { // //check if type of operation is CutBeamByBeamData since all objects have other parameters // if (c.Value.GetType() == typeof(CutBeamByBeamData)) // { // //cast unknown object type to CutBeamByBeamData type // CutBeamByBeamData cutBeamByBeamData = (c.Value as CutBeamByBeamData); // cutBeamByBeamData.FlangesWeld.Size = 0.001; // cutBeamByBeamData.Weld.Size = 0.001; // } // } //} //else //{ // //retrieves connection analysis results (governing unity checks) as xml + deserialize xml back to ConnectionResultsData object // var resultsdataXML = dynLinkLazy.Value.GetResultsData(); // ConnectionResultsData connectionResultsData = new XmlSerializer(typeof(ConnectionResultsData)).Deserialize(new StringReader(resultsdataXML)) as ConnectionResultsData; // int i = 0; // foreach (int wId in weldIds) // { // //double maxuc = 0; // //foreach (CheckResWeld res in connectionResultsData.ConnectionCheckRes[0].CheckResWeld) // //{ // // if (res.Items.Contains(conid)) // // { // // maxuc = Math.Max(maxuc, res.UnityCheck); // // } // //} // double maxuc = connectionResultsData.ConnectionCheckRes[0].CheckResWeld.Where(a => a.Items.Contains(wId)).Max(a => a.UnityCheck); // //print maxuc to excel // //create header with weldnames // string weldname = weldMathes[i].operationName; // string location; // if (weldMathes[i].isFlange == true) // { // location = "Flange"; // } // else // { // location = "Web"; // } // excel.WritetoCellstring(0, i, "Utility, " + weldname + "," + location); // excel.WritetoCell(tel, i, maxuc); // i = i + 1; //column placing in excel // if (maxuc > 100.0) // { // WeldMatch wmatch = weldMathes.First(a => a.weldId == wId); // wmatch.increase = true; // } // } // //weldsizes to excel // int ic = i+1; //column placing in excel // int ib = 0; // int cutnumber = 1; //every cut consist out of a flangeweld and a webweld. // //the list of throatthickness is shorter than the lists of results. Because in the list of results both flanges are displayed in case of single bevelcut. // foreach (var c in connectionTemplate.Properties.Items) // { // //check if type of operation is CutBeamByBeamData since all objects have other parameters // if (c.Value.GetType() == typeof(CutBeamByBeamData)) // { // CutBeamByBeamData cutbeambybeamdata = c.Value as CutBeamByBeamData; // if (weldMathes.Where(a => a.operationName == cutbeambybeamdata.Name && a.isFlange == true ).Count() > 0) // { // string weldname = "CUT "+ cutnumber; // excel.WritetoCellstring(0, ic, "throat, " + weldname +", Flange"); // ib = ib + 1; // excel.WritetoCell(tel, ic,cutbeambybeamdata.FlangesWeld.Size); // ic = ic + 1; // } // if (weldMathes.Where(a => a.operationName == cutbeambybeamdata.Name && a.isFlange == false ).Count() > 0) // { // string weldname = "CUT " + cutnumber; // excel.WritetoCellstring(0, ic, "throat, " + weldname+ ", Web"); // ib = ib + 1; // excel.WritetoCell(tel, ic, cutbeambybeamdata.Weld.Size); // ic = ic + 1; // } // } // cutnumber = cutnumber + 1; // } // //increase welds that have increase ==true // foreach (var c in connectionTemplate.Properties.Items) // { // //check if type of operation is CutBeamByBeamData since all objects have other parameters // if (c.Value.GetType() == typeof(CutBeamByBeamData)) // { // CutBeamByBeamData cutbeambybeamdata = c.Value as CutBeamByBeamData; // if (weldMathes.Where(a => a.operationName == cutbeambybeamdata.Name && a.isFlange == true && a.increase == true).Count() > 0) // { // cutbeambybeamdata.FlangesWeld.Size = cutbeambybeamdata.FlangesWeld.Size + 0.001; // templatechanged = true; // } // if (weldMathes.Where(a => a.operationName == cutbeambybeamdata.Name && a.isFlange == false && a.increase == true).Count() > 0) // { // cutbeambybeamdata.Weld.Size = cutbeambybeamdata.Weld.Size + 0.001; // templatechanged = true; // } // } // } //} //if (templatechanged && tel<max_iteration) //{ // //create new contemp file // tel = tel + 1; // //RAZ: save file of IDEA_connection [.ideacon] // string filePath = @"C:\Data\\test_k_joint"+ tel +".ideaCon"; // using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) // { // dynLinkLazy.Value.WriteProjectData(fileStream); // fileStream.Close(); // } // string filename2 = @"C:\Data\template2.contemp"; // using (FileStream fs2 = File.Open(filename2, FileMode.Create)) // { // DataContractSerializer serializer2 = new DataContractSerializer(typeof(ConnectionTemplate), new List<Type>() { typeof(CutBeamByBeamData) }); // XmlDictionaryWriter writer2 = XmlDictionaryWriter.CreateTextWriter(fs2, Encoding.Unicode); // serializer2.WriteObject(writer2, connectionTemplate); // writer2.Flush(); // writer2.Close(); // fs2.Close(); // } // //MessageBox.Show("recalculate updated version"); // this.OpenIOMInIdeaCon(iomFilePath, filename2, false, connectionTemplate); //} //else //{ // //MessageBox.Show("finsihed"); // Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); // dlg.DefaultExt = ".xml"; // Default file extension // dlg.Filter = "Idea Connection Check results (.xml)|*.xml"; // Filter files by extension // dlg.CheckPathExists = true; // excel.SaveAs(@"C:\Data\WELDRESULTS2.xlsx"); // excel.Close(); // if (dlg.ShowDialog() != true) // { // return; // } // using (Stream outStream = dlg.OpenFile()) // { // this.dynLinkLazy.Value.WriteConCheckResults(outStream); // outStream.Close(); // } //} } }