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…')
 
(Replaced content with '==DRAFT==')
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Template:API}}{{Template:BacktoPrevPage|[[API Tutorials|<< Back to Tutorials Main Page]]}}
==DRAFT==
 
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 this tutorial, you'll learn how to obtain calculated results from models.
 
==Prerequisites==
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)
 
*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.)
 
 
==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 [[Calculate_Results_from_a_Model/VBA|here]].
 
'''VB.NET'''
{{APIPrefix|Imports}} SynthesisAPI
  {{APIPrefix|Module}} Module1
    {{APIPrefix|Sub}} Main()
 
    {{APIComment|'Connect to a Synthesis repository and project.}}
      {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
      MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
      MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
    {{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.}}
 
    {{APIComment|'Declare some variables to store the results.}}
      {{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
      AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg)
    {{APIComment|'To store the confidence bounds results, declare new BoundsValues objects.}}
      {{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.}}
      BResult1 = AModel.Bounds_Reliability(100)
      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)
    {{APIPrefix|End Sub}}
{{APIPrefix|End Module}}
 
==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.
 
{{APIComment|'Connect to a Synthesis repository and project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
  MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
 
 
 
 
 
 
====================================
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}} 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
 
3. Let's add confidence bounds calculations to the results. Use the <code>SetConfidenceLevel</code> method to specify 90% two-sided confidence bounds.
 
'''VBA'''
{{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.}}
  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|'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}} BResult2 {{APIPrefix|As}} BoundsValues
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}}
  BResult1 = AModel.Bounds_Reliability(100)
  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===
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.}}
  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)
End Sub
 
===Notes===
See <code>[[CModel Class|cModel]]</code> 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:
 
*[[CModel.Reliability|cModel.Reliability Method]]
*[[CModel.MeanTime|cModel.MeanTime Method]]
*[[CModel.SetConfidenceLevel|cModel.SetConfidenceLevel Method]]
*[[CModel.Bounds_Reliability|cModel.Bounds_Reliability Method]]
*[[CModel.Bounds_MeanTime|cModel.Bounds_MeanTime Method]]
*[[BoundsValues Class]]

Latest revision as of 17:14, 28 April 2016

DRAFT