示例#1
0
 def __init__(self, name, nvalue = 2):
     BVertex.__init__(self, name)
     self. discrete = True
     self.nvalue = nvalue
     self.cpt = None
示例#2
0
    def getVariablesXbn(self):
        self.variablesList = []
        
        node = self.xbn.childNodes
        if self.version == "1.0":
            bnmodel = node[0].childNodes
            statdynvar = bnmodel[1].childNodes
            variables = statdynvar[4].childNodes
        else:
            bnmodel = node[1].childNodes
            statdynvar = bnmodel[1].childNodes
            variables = statdynvar[5].childNodes

        for var in variables:
            if var.nodeType == Node.ELEMENT_NODE:
                v = Variables()
                v.stateName = []
                v.propertyNameValue = {}
                attrs = var.attributes

                for attrName in attrs.keys(): 
                    attrNode = attrs.get(attrName)
                    attrValue = attrNode.nodeValue

                    if attrName == "NAME":
                        v.name = attrValue
                    elif attrName == "TYPE":
                        v.type = attrValue
                    elif attrName == "XPOS":
                        v.xpos = attrValue
                    elif attrName == "YPOS":
                        v.ypos = attrValue

                for info in var.childNodes:                    
                    if info.nodeType == Node.ELEMENT_NODE:             
                        if (info.nodeName == "DESCRIPTION") or \
                           (info.nodeName == "FULLNAME"):
                            try:
                                v.description = info.childNodes[0].nodeValue
                            except:
                                v.description = ""
                            
                        elif info.nodeName == "STATENAME":
                            v.stateName.append(info.childNodes[0].nodeValue)
                            
                        elif (info.nodeName == "PROPERTY"):
                            attrsb = info.attributes
                            attrValueb = attrsb.get(attrsb.keys()[0]).nodeValue

                            if self.version == "1.0":
                                v.propertyNameValue[attrValueb] = info.childNodes[0].childNodes[0].nodeValue
                            else:
                                v.propertyNameValue[attrValueb] = info.childNodes[1].childNodes[0].nodeValue

                self.variablesList.append(v)
                
        # create the corresponding nodes into the BNet class
        for v in self.variablesList:
            #---TODO: Discrete or Continuous. Here True means always discrete
            bv = BVertex(v.name, True, len(v.stateName))
            bv.state_names = v.stateName
            self.G.add_vertex(bv)
            #---TODO: add the names of the states into the vertex
                
        return self.variablesList