APISynthesisResourcesTutorial4: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 53: Line 53:
   
   
   Result1 = AModel.Reliability(100)
   Result1 = AModel.Reliability(100)
   Result2 = AModel.MeanTime()
   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.
3. Let's add confidence bounds calculations to the results. Use the <code>SetConfidenceLevel</code> method to specify 90% two-sided confidence bounds.
Line 70: Line 70:
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}  
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}  
   {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
   {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
   {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime()
   {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
    
    
  {{APIComment|'Display the output.}}
  {{APIComment|'Display the output.}}
Line 93: Line 93:
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}  
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}  
   BResult1 = AModel.Bounds_Reliability(100)
   BResult1 = AModel.Bounds_Reliability(100)
   BResult2 = AModel.Bounds_MeanTime()
   BResult2 = AModel.Bounds_MeanTime
    
    
  {{APIComment|'Display the output.}}
  {{APIComment|'Display the output.}}
Line 123: Line 123:
   
   
   Result1 = AModel.Reliability(100)
   Result1 = AModel.Reliability(100)
   Result2 = AModel.MeanTime()
   Result2 = AModel.MeanTime
    
    
  {{APIComment|'Set the confidence level to 90% two-sided bounds.}}
  {{APIComment|'Set the confidence level to 90% two-sided bounds.}}
Line 136: Line 136:
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
   {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
   {{APIPrefix|Set}} BResult1 = AModel.Bounds_Reliability(100)
   {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime()
   {{APIPrefix|Set}} BResult2 = AModel.Bounds_MeanTime
    
    
  {{APIComment|'Display the output.}}
  {{APIComment|'Display the output.}}
Line 165: Line 165:
   
   
   Result1 = AModel.Reliability(100)
   Result1 = AModel.Reliability(100)
   Result2 = AModel.MeanTime()
   Result2 = AModel.MeanTime
   
   
  {{APIComment|'Set the confidence level to 90% two-sided bounds.}}
  {{APIComment|'Set the confidence level to 90% two-sided bounds.}}
Line 178: Line 178:
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  {{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
   BResult1 = AModel.Bounds_Reliability(100)
   BResult1 = AModel.Bounds_Reliability(100)
   BResult2 = AModel.Bounds_MeanTime()
   BResult2 = AModel.Bounds_MeanTime
   
   
  {{APIComment|'Display the output.}}
  {{APIComment|'Display the output.}}

Revision as of 17:34, 23 October 2015

Template:InProgress

APIWiki.png


<< Back to Quick Start Guide

Synthesis Resources Tutorial

  1. Connect to a Synthesis Repository and Project
  2. Create a New Synthesis Resource
  3. Update an Existing Resource
  4. Calculate Results from a Model

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

 'Connect to the Synthesis repository and retrieve model ID#21. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

  Dim AModel As cModel
  Set AModel = MyRepository.Model.GetModel(21)
VB.NET

 'Connect to the Synthesis repository and retrieve model ID#21. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

  Dim AModel As cModel
  AModel = MyRepository.Model.GetModel(21)

2. Use the Reliability method to calculate for the reliability at 100 hrs and the MeanTime method to return the mean time to failure.

VBA|VB.NET

 'Calculate the model's reliability at time = 100 hrs and mean time. 
  Dim Result1 As Double
  Dim Result2 As Double

  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime

3. Let's add confidence bounds calculations to the results. Use the SetConfidenceLevel method to specify 90% two-sided confidence bounds.

VBA

 'Set the confidence level to 90% two-sided bounds. 
 'Declare a string variable for any errors found during this method. 
  Dim ErrorMsg As String
  Call AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)

 'Initiate new instances of the BoundsValues class. 
  Dim BResult1 As BoundsValues
  Dim BResult2 As BoundsValues

 'Calculate bounds for the reliability at 100 hrs and the mean time.  
  Set BResult1 = AModel.Bounds_Reliability(100)
  Set BResult2 = AModel.Bounds_MeanTime
 
 'Display the output. 
  MsgBox ("Reliability = " & Result1 & vbNewLine & _
          "Upper Bound = " & BResult1.upper & vbNewLine & _
          "Lower Bound = " & BResult1.lower & vbNewLine)
  MsgBox ("Mean Time = " & Result2 & vbNewLine & _
          "Upper Bound = " & BResult2.upper & vbNewLine & _
          "Lower Bound = " & BResult2.lower & vbNewLine)
VB.NET

 'Set the confidence level to 90% two-sided bounds. 
 'Declare a string variable for any errors found during this method. 
  Dim ErrorMsg As String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)

 'Initiate new instances of the BoundsValues class. 
  Dim BResult1 As BoundsValues
  Dim BResult2 As BoundsValues

 'Calculate bounds for the reliability at 100 hrs and the mean time.  
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime
 
 'Display the output. 
  MsgBox ("Reliability = " & Result1 & vbNewLine & _
          "Upper Bound = " & BResult1.upper & vbNewLine & _
          "Lower Bound = " & BResult1.lower & vbNewLine)
  MsgBox ("Mean Time = " & Result2 & vbNewLine & _
          "Upper Bound = " & BResult2.upper & vbNewLine & _
          "Lower Bound = " & 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()
  
 'Connect to the Synthesis repository and retrieve model ID#21. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

  Dim AModel As cModel
  Set AModel = MyRepository.Model.GetModel(21)
  
 'Calculate the model's reliability at time = 100 hrs and mean time. 
  Dim Result1 As Double
  Dim Result2 As Double

  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime
 
 'Set the confidence level to 90% two-sided bounds. 
 'Declare a string variable for any errors found during this method. 
  Dim ErrorMsg As String
  Call AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)

 'Initiate new instances of the BoundsValues class. 
  Dim BResult1 As BoundsValues
  Dim BResult2 As BoundsValues

 'Calculate bounds for the reliability at 100 hrs and the mean time. 
  Set BResult1 = AModel.Bounds_Reliability(100)
  Set BResult2 = AModel.Bounds_MeanTime
 
 'Display the output. 
  MsgBox ("Reliability = " & Result1 & vbNewLine & _
          "Upper Bound = " & BResult1.upper & vbNewLine & _
          "Lower Bound = " & BResult1.lower & vbNewLine)
  MsgBox ("Mean Time = " & Result2 & vbNewLine & _
          "Upper Bound = " & BResult2.upper & vbNewLine & _
          "Lower Bound = " & BResult2.lower & vbNewLine)

End Sub
VB.NET

Sub Main()
  
 'Connect to the Synthesis repository and retrieve model ID#21. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

  Dim AModel As cModel
  AModel = MyRepository.Model.GetModel(21)
  
 'Calculate the model's reliability at time = 100 hrs and mean time. 
  Dim Result1 As Double
  Dim Result2 As Double

  Result1 = AModel.Reliability(100)
  Result2 = AModel.MeanTime

 'Set the confidence level to 90% two-sided bounds. 
 'Declare a string variable for any errors found during this method. 
  Dim ErrorMsg As String
  AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)

 'Initiate new instances of the BoundsValues class. 
  Dim BResult1 As BoundsValues
  Dim BResult2 As BoundsValues

 'Calculate bounds for the reliability at 100 hrs and the mean time. 
  BResult1 = AModel.Bounds_Reliability(100)
  BResult2 = AModel.Bounds_MeanTime

 'Display the output. 
  MsgBox ("Reliability = " & Result1 & vbNewLine & _
          "Upper Bound = " & BResult1.upper & vbNewLine & _
          "Lower Bound = " & BResult1.lower & vbNewLine)
  MsgBox ("Mean Time = " & Result2 & vbNewLine & _
          "Upper Bound = " & BResult2.upper & vbNewLine & _
          "Lower Bound = " & BResult2.lower & vbNewLine)

End Sub

References

To learn more, see the reference documentation for the class and methods discussed in this section: