APISynthesisResourcesTutorial4: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
(Redirected page to API Tutorials)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:API}}
#REDIRECT [[API_Tutorials]]
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[APIQuickStartGuide|Back to Quick Start Guide]]
 
'''Synthesis Resources Tutorial'''
#[[APISynthesisResourcesTutorial|Connect to a Synthesis Repository and Project]]
#[[APISynthesisResourcesTutorial2|Create a New Synthesis Resource]]
#[[APISynthesisResourcesTutorial3|Update an Existing Resource]]
#Calculate Results from a Model
</div>
 
Models are used by other Synthesis resources to represent the reliability of a task, the duration of a task, the expected cost of a repair, and many other characteristics. In this section, we'll learn how to obtain calculated results from models.
 
 
 
 
 
 
 
 
 
==Part 4: Calculate Results from a Model==
1. Create a new module, and then add code to retrieve the model that we've been working on in the previous sections (recall that the model's name is now "MyNewModel_Update"). The following code example assumes that the model's ID number is 21.
 
'''VBA'''
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
'''VB.NET'''
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  AModel = MyRepository.Model.GetModel(21)
 
2. Use the <code>Reliability</code> method to calculate for the reliability at 100 hrs and the <code>MeanTime</code> method to return the mean time to failure.
 
'''VBA|VB.NET'''
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
3. Let's add confidence bounds calculations to the results. Use the <code>SetConfidenceLevel</code> method to specify 90% two-sided confidence bounds.
 
'''VBA'''
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  {{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
  {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
 
'''VB.NET'''
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
 
===Test the Code===
Below are the VBA and VB.NET code lists for this example. You can experiment with the code by retrieving ''published'' models from the repository and then comparing the results obtained by the API with results obtained by the Quick Calculation Pad (QCP).
 
'''VBA'''
Sub Main()
 
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  {{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
  {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
 
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
End Sub
 
'''VB.NET'''
Sub Main()
 
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  AModel = MyRepository.Model.GetModel(21)
 
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
{{APIComment|'Set the confidence level to 90% two-sided bounds.}}
{{APIComment|'Declare a string variable for any errors found during this method.}}
  {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
{{APIComment|'Initiate new instances of the BoundsValues class.}}
  {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues
  {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime
{{APIComment|'Display the output.}}
  MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & vbNewLine)
  MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _
          {{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
End Sub
 
===References===
To learn more, see the reference documentation for the class and methods discussed in this section:
 
*[[CModel.Reliability|cModel.Reliability Method]]
*[[CModel.MeanTime|cModel.MeanTime Method]]
*[[CModel.SetConfidenceLevel|cModel.SetConfidenceLevel Method]]
*[[CModel.Bounds_Reliability|cModel.Bounds_Reliability Method]]
*[[CModel.Bounds_MeanTime|cModel.Bounds_MeanTime Method]]
*[[BoundsValues Class]]

Latest revision as of 23:48, 9 February 2016

Redirect to: