Talk:Calculate Results from a Model/Notes: Difference between revisions
Kate Racaza (talk | contribs) (Created page with '{{Template:API}}{{Template:BacktoPrevPage|<< Back to Tutorials Main Page}} In Synthesis applications, models can represent probabilities, durations or costs, e…') |
Kate Racaza (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{Template:API}}{{Template:BacktoPrevPage|[[API Tutorials|<< Back to Tutorials Main Page]]}} | {{Template:API}}{{Template:BacktoPrevPage|[[API Tutorials|<< Back to Tutorials Main Page]]}} | ||
In Synthesis applications, models can | In Synthesis applications, models can represent the reliability of a component, the duration of a task, the expected cost of a repair and many other characteristics. In this tutorial, you'll learn how to calculate a variety of useful metrics from models. | ||
In this tutorial, you'll learn how to | |||
==Prerequisites== | ==Prerequisites== | ||
Before you begin: | Before you begin: | ||
*Create a test repository, | *Create a test repository (can use [http://weibull.reliasoft.com/ Weibull++], [http://alta.reliasoft.com/ ALTA], [http://blocksim.reliasoft.com/ BlockSim] or [http://rga.reliasoft.com/ RGA]). Perform a simple analysis and then publish a model of the analysis. You'll want to use a published model with this tutorial so you can compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP). | ||
*Note the published model's object ID number. | *Note the published model's object ID number. You will use the ID# to retrieve the model from the database. (To display the object IDs, choose '''File > Application Setup''', then click '''Other''' under the Synthesis Settings heading in the navigation panel. Select the '''Display Object IDs''' check box. The object ID of the model is displayed in the Resource Manager.) | ||
Line 47: | Line 45: | ||
AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) | AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) | ||
{{APIComment|' | {{APIComment|'Declare new BoundsValues objects to store the confidence bounds results.}} | ||
{{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | ||
{{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | ||
Line 65: | Line 63: | ||
{{APIPrefix|End Sub}} | {{APIPrefix|End Sub}} | ||
{{APIPrefix|End Module}} | {{APIPrefix|End Module}} | ||
==Discussion== | ==Discussion== | ||
Begin by connecting to a Synthesis repository and project (for details, see [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].) | Begin by connecting to a Synthesis repository and project (for details, see [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].) If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository. | ||
{{APIComment|'Connect to a Synthesis repository and project.}} | {{APIComment|'Connect to a Synthesis repository and project.}} | ||
Line 74: | Line 73: | ||
MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}} | ||
Once you are connected to the repository, use the [[Repository.Model.GetModel|Model.GetModel]] method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21. | |||
{{APIComment|'Retrieve a model from the repository.}} | |||
{{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel | |||
AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}} | |||
We can now obtain some metrics from the model. The [[CModel Class|cModel Class]] reference doc lists all available methods for performing calculations on models, but for this example, we'll limit it to the [[CModel.Reliability|Reliability]] and [[CModel.MeanTime|MeanTime]] methods. | |||
{{APIComment|'Declare some variables to store the results.}} | |||
{{APIComment|' | |||
{{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double | {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double | ||
{{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double | {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double | ||
{{APIComment|'Calculate the model's reliability at time = 100 hrs and mean time.}} | {{APIComment|'Calculate the model's reliability at time = 100 hrs and mean time.}} | ||
Result1 = AModel.Reliability(100) | Result1 = AModel.Reliability(100) | ||
Result2 = AModel.MeanTime | Result2 = AModel.MeanTime | ||
To calculate the confidence bounds, use the [[CModel.SetConfidenceLevel|SetConfidenceLevel]] method to specify 90% two-sided confidence bounds. | |||
{{APIComment|'Set the confidence level to 90% two-sided bounds.}} | {{APIComment|'Set the confidence level to 90% two-sided bounds.}} | ||
{{APIComment|'Declare a string variable for any errors found during this method.}} | {{APIComment|'Declare a string variable for any errors found during this method.}} | ||
{{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String | {{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String | ||
AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) | |||
And then use any of the bounds calculation methods in the class to perform the commands. Here, we limit the example to the [[CModel.Bounds_Reliability|Bounds_Reliability]] and [[CModel.Bounds_MeanTime|Bounds_MeanTime]] methods. | |||
{{APIComment|'Declare new BoundsValues objects to store the confidence bounds results.}} | |||
{{APIComment|' | |||
{{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | {{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | ||
{{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | {{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | ||
{{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 | ||
The last section of code creates simple message boxes to display the outputs, allowing you to compare the results returned by the API with the results obtained from the software's Quick Calculation Pad (QCP). | |||
{{APIComment|'Display the output.}} | {{APIComment|'Display the output.}} | ||
MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & vbNewLine & _ | 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 & _ | MsgBox ({{APIString|"Mean Time <nowiki>=</nowiki> "}} & Result2 & vbNewLine & _ | ||
{{APIString|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _ | |||
{{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine) | |||
===References=== | ===References=== | ||
*[[CModel Class]] | |||
*[[CModel.Reliability|cModel.Reliability Method]] | *[[CModel.Reliability|cModel.Reliability Method]] | ||
*[[CModel.MeanTime|cModel.MeanTime Method]] | *[[CModel.MeanTime|cModel.MeanTime Method]] |
Revision as of 16:21, 28 April 2016
In Synthesis applications, models can represent the reliability of a component, the duration of a task, the expected cost of a repair and many other characteristics. In this tutorial, you'll learn how to calculate a variety of useful metrics from models.
Prerequisites
Before you begin:
- Create a test repository (can use Weibull++, ALTA, BlockSim or RGA). Perform a simple analysis and then publish a model of the analysis. You'll want to use a published model with this tutorial so you can compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).
- Note the published model's object ID number. You will use the ID# to retrieve the model from the database. (To display the object IDs, choose File > Application Setup, then click Other under the Synthesis Settings heading in the navigation panel. Select the Display Object IDs check box. The object ID of the model is displayed in the Resource Manager.)
Tutorial: Calculate Results from a Model
The following example demonstrates how to obtain calculated results from a model resource. A discussion of the example follows.
A VBA version of the code sample is available here.
VB.NET Imports SynthesisAPI Module Module1 Sub Main() 'Connect to a Synthesis repository and project. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Replace with name and path to test repository. MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 'Retrieve a model from the repository. Dim AModel As cModel AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 'Declare some variables to store the results. 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) 'Declare new BoundsValues objects to store the confidence bounds results. 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 Module
Discussion
Begin by connecting to a Synthesis repository and project (for details, see this tutorial.) If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository.
'Connect to a Synthesis repository and project. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Replace with name and path to test repository. MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project.
Once you are connected to the repository, use the Model.GetModel method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21.
'Retrieve a model from the repository. Dim AModel As cModel AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model.
We can now obtain some metrics from the model. The cModel Class reference doc lists all available methods for performing calculations on models, but for this example, we'll limit it to the Reliability and MeanTime methods.
'Declare some variables to store the results. 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
To calculate the confidence bounds, use the SetConfidenceLevel method to specify 90% two-sided confidence bounds.
'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)
And then use any of the bounds calculation methods in the class to perform the commands. Here, we limit the example to the Bounds_Reliability and Bounds_MeanTime methods.
'Declare new BoundsValues objects to store the confidence bounds results. 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
The last section of code creates simple message boxes to display the outputs, allowing you to compare the results returned by the API with the results obtained from the software's Quick Calculation Pad (QCP).
'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)