Talk:Calculate Results from a Model/Notes: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(Created page with '{{Template:API}}{{Template:BacktoPrevPage|<< Back to Tutorials Main Page}} In Synthesis applications, models can represent probabilities, durations or costs, e…')
 
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 represent probabilities, durations or costs, either fixed or time-dependent. They are used by other resources to represent the reliability of a component, the duration of a task, the expected cost of a repair and many other characteristics.  
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 obtain calculated results from models.


==Prerequisites==
==Prerequisites==
Before you begin:
Before you begin:


*Create a test repository, perform a simple analysis and then publish a model from 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)
*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. This will help you trace the response of the API. (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.)
*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|'To store the confidence bounds results, declare new BoundsValues objects.}}
     {{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]].) The section of code below demonstrates how to connect to a standard repository and open one of its projects. It assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive and that we're accessing project ID#1. If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository.  
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.}}
 
====================================
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.
 
  {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"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'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
'''VB.NET'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} 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.
{{APIComment|'Declare variables.}}
   {{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 &#61; 100 hrs and mean time.}}  
  {{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
   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.
To calculate the confidence bounds, use the [[CModel.SetConfidenceLevel|SetConfidenceLevel]] method to specify 90% two-sided confidence bounds.  


'''VBA'''
  {{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
   {{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg)
   AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
 
{{APIComment|'Initiate new instances of the BoundsValues class.}}
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.
  {{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|'Declare new BoundsValues objects to store the confidence bounds results.}}
  {{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}} 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
 
{{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===
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).
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()
 
{{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
{{APIComment|'Declare variables.}}
  {{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double
  {{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double
{{APIComment|'Calculate the model's reliability at time &#61; 100 hrs and mean time.}}
  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.}}
  {{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|"Upper Bound <nowiki>=</nowiki> "}} & BResult1.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult1.lower & 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|"Upper Bound <nowiki>=</nowiki> "}} & BResult2.upper & vbNewLine & _
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
          {{APIString|"Lower Bound <nowiki>=</nowiki> "}} & BResult2.lower & vbNewLine)
End Sub
 
===Notes===
See <code>[[CModel Class|cModel]]</code> class for a list of all available calculation methods for models.


===References===
===References===
To learn more, see the reference documentation for the class and methods discussed in this tutorial:
*[[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

APIWiki.png


<< Back to Tutorials Main Page

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)

References