예제 #1
0
    # Initiate the model to be run in game mode.
    venDLL.command("MENU>GAME")
    if start_interval > 0:
        venDLL.command('GAME>GAMEON')

    loop_on = 1
    loop_off = 0

    loop_turned_off = False
    while True:

        # Initiate the experiment of interest.
        # In other words set the uncertainties to the same value as in
        # those experiments.
        time = vensim.get_val(r'TIME')
        EMAlogging.debug(time)

        if time ==(2000+step*interval[0]) and not loop_turned_off:
            loop_turned_off = True

            if loop_index != 0:

                # If loop elimination method is based on unique edge.
                if loop_index-1 < ind_cons:
                    constant_value = vensim.get_val(edges[int(loop_index-1)][0])

                    if loop_off==1:
                        constant_value = 0

                    vensim.set_value('value loop '+str(loop_index),
                                     constant_value)
예제 #2
0
 def model_init(self, policy, kwargs):
     try:
         self.modelFile = policy['file']
     except:
         EMAlogging.debug("no policy specified")
     super(EnergyTrans, self).model_init(policy, kwargs)
예제 #3
0
    def model_init(self, policy, kwargs):
        """
        Method to initialize the model, it is called just prior to running 
        the model its main use is to initialize aspects of the model that can 
        not be pickled. In this way it is possible to run a model in parallel 
        without having to worry about having only pickleable attributes 
        (for more details read up on the multiprocessing library
        
        """
        
        if not jpype.isJVMStarted():
            classpath = r'-Djava.class.path=C:\workspace\ElectTransEMA\bin;C:\workspace\Repast3.1\bin;C:\workspace\Repast3.1\lib\asm.jar;C:\workspace\Repast3.1\lib\beanbowl.jar;C:\workspace\Repast3.1\lib\colt.jar;C:\workspace\Repast3.1\lib\commons-collections.jar;C:\workspace\Repast3.1\lib\commons-logging.jar;C:\workspace\Repast3.1\lib\geotools_repast.jar;C:\workspace\Repast3.1\lib\ibis.jar;C:\workspace\Repast3.1\lib\jakarta-poi.jar;C:\workspace\Repast3.1\lib\jep-2.24.jar;C:\workspace\Repast3.1\lib\jgap.jar;C:\workspace\Repast3.1\lib\jh.jar;C:\workspace\Repast3.1\lib\jmf.jar;C:\workspace\Repast3.1\lib\jode-1.1.2-pre1.jar;C:\workspace\Repast3.1\lib\log4j-1.2.8.jar;C:\workspace\Repast3.1\lib\joone.jar;C:\workspace\Repast3.1\lib\JTS.jar;C:\workspace\Repast3.1\lib\junit.jar;C:\workspace\Repast3.1\lib\OpenForecast-0.4.0.jar;C:\workspace\Repast3.1\lib\openmap.jar;C:\workspace\Repast3.1\lib\plot.jar;C:\workspace\Repast3.1\lib\ProActive.jar;C:\workspace\Repast3.1\lib\trove.jar;C:\workspace\Repast3.1\lib\violinstrings-1.0.2.jar;C:\workspace\Repast3.1\repast.jar'
            jpype.startJVM(r'C:\Program Files (x86)\Java\jdk1.6.0_22\jre\bin\client\jvm.dll', classpath)
            logging.debug("jvm started")
        
        
        logging.debug("trying to find package")
        try:
            modelPackage = jpype.JPackage("org").electTransEma
#            testPkg = jpype.JPackage("org").test
        except RuntimeError as inst:
            logging.debug("exception " + repr(type(inst))+" " + str(inst))
        except TypeError as inst:
            logging.debug("TypeEror " +" " + str(inst))
        except Exception as inst:
            logging.debug("exception " + repr(type(inst))+" " + str(inst))
    
        else:
            logging.debug("modelPackage found")
            self.modelInterfaceClass = modelPackage.ElectTransInterface
#            testClass = testPkg.jPypeTestClass
            logging.debug("class found")
            
            try:
                directory = self.workingDirectory.replace("\\", "/")
                
                self.modelInterface = self.modelInterfaceClass(directory)
#                self.testObject = testClass()  
                logging.debug("class loaded succesfully")
            except TypeError as inst:
                logging.warning("failure to instantiate the model")
                raise inst