Calculate Results from a Model

From ReliaWiki
Revision as of 16:33, 17 February 2016 by Kate Racaza (talk | contribs) (→‎Notes)
Jump to navigation Jump to search
APIWiki.png


<< Back to API Tutorials

Basics

  1. Connect or Disconnect from a Synthesis Repository
  2. Add New Synthesis Resources to a Repository
  3. Edit Existing Synthesis Resources
  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 tutorial, you'll learn how to obtain calculated results from models.

Before you begin, publish a model from the repository and note the model's object ID number (see Using Object IDs). You will use the object ID number to retrieve the model, so you can compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).




Calculate Results from a Model

1. Create a new module and begin by connecting to a Synthesis repository and project. The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.

 'Connect to the Synthesis repository and set project ID#1 as the current project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

2. Retrieve a model from the repository. The following code assumes that the repository contains a model with ID number 21.

VBA

 'Retrieve the model with ID# 21 from the repository. 
  Dim Amodel As New cModel
  Set AModel = MyRepository.Model.GetModel(21)
VB.NET

 'Retrieve the model with ID# 21 from the repository.  
  Dim Amodel As New 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.

 'Declare variables. 
  Dim Result1 As Double
  Dim Result2 As Double

 'Calculate the model's reliability at time = 100 hrs and mean time.  
  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 complete code lists for this example. To test them, run the application by clicking Start on the Debug menu. Compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).

VBA

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

 'Retrieve the model with ID# 21 from the repository. 
  Dim AModel As cModel
  Set AModel = MyRepository.Model.GetModel(21)
  
 'Declare variables. 
  Dim Result1 As Double
  Dim Result2 As Double

 'Calculate the model's reliability at time = 100 hrs and mean time. 
  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

Imports SynthesisAPI 

 Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  
    'Connect to the Synthesis repository and set project ID#1 as the current project. 
     Dim MyRepository As New Repository
     MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
     MyRepository.Project.SetCurrentProject(1)

    'Retrieve the model with ID# 21 from the repository.       
     Dim AModel As cModel
     AModel = MyRepository.Model.GetModel(21)
  
    'Declare variables. 
     Dim Result1 As Double
     Dim Result2 As Double

    'Calculate the model's reliability at time = 100 hrs and mean time. 
     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
End Class

Notes

See cModel class for a list of all available calculation methods for models.

References

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