APISynthesisResourcesTutorial4
Synthesis Resources Tutorial
- Connect to a Synthesis Repository and Project
- Create a New Synthesis Resource
- Update an Existing Resource
- 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 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 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 End Class
References
To learn more, see the reference documentation for the class and methods discussed in this section: