def createActualModuleFromTemplate(self, template_module, isPredecessor = False):
        """
        Creates a normal ParametricModule out of a GenerationTemplateModule.
        If this is a predecessor module (isPredecessor is True), then the module is created with variables (e.g. x,y,z) as parameters.
        """
        module = ParametricModule(template_module.letter)

        #print("Gen module has n params: " + str(len(template_module.params)))

        if self.parameterized:
            param_index = 0
            for param in template_module.params:
                value = 1   # Default value
                if isPredecessor == True:
                    if param_index == 0: value = "x"
                    if param_index == 1: value = "y"
                    if param_index == 2: value = "z"
                elif self.constantsProbability > 0.0:
                    if self.rnd.random() < self.constantsProbability:
                        # Set a constant value as parameter
                        value = template_module.generateConstantParameterValue(self.rnd)
                elif self.definesProbability > 0.0:
                    if self.rnd.random() < self.definesProbability:
                        # Select an existing define, or add a new one
                        nCurrentDefines = len(self.generator.lsystem.globalDefines)
                        if nCurrentDefines > 0 and (self.rnd.random() > 0.5 or nCurrentDefines == ModulesTemplateLibrary.MAX_DEFINES):
                            defname = "d"+str(self.rnd.randint(0,len(self.generator.lsystem.globalDefines)-1))
                        else:
                            defname, defvalue = self.generator.generateRandomDefine()
                        value = defname
                module.appendParameter(value)
                param_index += 1
        #print("New Module: " + str(module))
        return module
예제 #2
0
 def copyFrom(other_pString):
     """
     Copies a ParametricString and returns the copy.
     """
     new_pString = ParametricString()
     new_pString.setGlobals(other_pString.globalDefines)
     new_pString.modulesList = []
     for m in other_pString.modulesList:
         new_pString.modulesList.append(ParametricModule.copyFrom(m))
     return new_pString
예제 #3
0
 def appendCloseBranch(self):
     self.modulesList.append(ParametricModule.fromTextString("]"))
예제 #4
0
 def appendOpenBranch(self):
     self.modulesList.append(ParametricModule.fromTextString("["))
 def __init__(self,letter,params=[]):
     ParametricModule.__init__(self, letter, params)
            v1 = op(v1,v2)
        return v1



if __name__ == "__main__":
    print("Start testing ParametricProduction")

    print("\nCreation")
    pp = ParametricProduction(verbose=True)
    pp.setGlobals({"p":1.0})    # TODO: Must this be before? Or not?
    pp.parseString('F:*->FF')    # TODO: add a ParametricProduction.fromTextString LIKE THE REST!
    #print(pp)

    print("\nChange predecessor: parametric")
    pm = ParametricModule.fromTextString("A(x)")
    pp.setPredecessorModule(pm)
    print(pp)
    print(pm.letter)

    print("\nChange condition: probability")
    pp.setConditionFromString("0.8")
    print(pp)

    print("\nChange condition: parametric")
    pp.setConditionFromString("x>0.9")
    print(pp)

    print("\nChange successor: parametric")
    ps = ParametricString.fromTextString('F(x)A(p)')
    pp.setSuccessorPstring(ps)
 def __str__(self):
     s = ParametricModule.__str__(self)
     s += "(W: " + str(self.weight) + ")"
     return s
 def __init__(self,letter,params=[],weight=1,scale_min=0,scale_max=1):
     ParametricModule.__init__(self, letter, params)
     self.weight = weight                # Must be [1,100]. The higher, the more likely this will appear in the generation
     self.scale_min = scale_min          # Determines the minimum random value that this module can have as a single parameter
     self.scale_max = scale_max          # Determines the maximum random value that this module can have as a single parameter