Author Topic: Creating an OOBN model  (Read 16504 times)

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Creating an OOBN model
« on: July 21, 2010, 14:53:12 »
Here is an example that shows how to construct a simple OOBN model using the HUGIN ActiveX server API:
Code: [Select]
Sub oobn_example()

Dim ClassColl As ClassCollection
Dim hClass As Class, hMainClass As Class
Dim NodeA As Node, InputNode As Node, OutputNode As Node, NodeB As Node
Dim instanceNode As Node

On Error GoTo errorhandler
   
    ' Create class collection
    Set ClassColl = GetNewClassCollection

    ' Create class
    Set hClass = ClassColl.GetNewClass()
    hClass.name = "hClass"
   
    'Tell:
    MsgBox ("Class created!")
   
    'Create some nodes
    Set NodeA = hClass.GetNewNode(hCategoryChance, hKindDiscrete)
    NodeA.name = "NodeA"
   
    Set InputNode = hClass.GetNewNode(hCategoryChance, hKindDiscrete)
    InputNode.name = "Input"
    InputNode.AddToInputs
   
    Set OutputNode = hClass.GetNewNode(hCategoryChance, hKindDiscrete)
    OutputNode.name = "OutputNode"
    OutputNode.AddToOutputs
   
    'Tell:
    MsgBox ("Nodes created!")
   
    ' Adding Structure Input->A->Output
    Call NodeA.AddParent(InputNode)
    Call OutputNode.AddParent(NodeA)
   
    'Tell:
    MsgBox ("Structure created!")
   
    ' Creating main class
    Set hMainClass = ClassColl.GetNewClass()
    hMainClass.name = "main_class"
   
    ' create instance of hClass
    Set instanceNode = hMainClass.AddNewInstance(hClass)
   
    ' create node in hMainClass
     Set NodeB = hMainClass.GetNewNode(hCategoryChance, hKindDiscrete)
     NodeB.name = "NodeB"
   
    ' link NodeB to instanceNode.Input
    Call instanceNode.SetInput(InputNode, NodeB)
   
    'Tell:
    MsgBox ("Main class created!")
   
    ' save class collection
    ClassColl.SaveAsNet ("C:\oobn_example.oobn")
   
    Exit Sub
errorhandler:
    MsgBox ("Error: " & Err.Description)
    Exit Sub
End Sub
HUGIN EXPERT A/S