示例#1
0
    def run_model(self, case):
        
        for key, value in self.policy.items():
            vensim.set_value(key, value)
        
        switches = case.pop("preference switches")

        case["SWITCH preference for MIC"] = switches[0]
        case["SWITCH preference for expected cost per MWe"]= switches[1]
        case["SWITCH preference against unknown"]= switches[2]
        case["SWITCH preference for expected progress"]= switches[3]
        case["SWITCH preference against specific CO2 emissions"]= switches[4]
            
        for key, value in case.items():
            vensim.set_value(key, value)
        ema_logging.debug("model parameters set successfully")
        
        ema_logging.debug("run simulation, results stored in " + self.workingDirectory+self.resultFile)
        try:
            vensim.run_simulation(self.workingDirectory+self.resultFile)
        except VensimError:
            raise

        results = {}
        error = False
        for output in self.outcomes:
            ema_logging.debug("getting data for %s" %output.name)
            result = vensim.get_data(self.workingDirectory+self.resultFile, 
                              output.name 
                              )
            ema_logging.debug("successfully retrieved data for %s" %output.name)
            if not result == []:
                if result.shape[0] != self.runLength:
                    a = np.zeros((self.runLength))
                    a[0:result.shape[0]] = result
                    result = a
                    error = True
            
            else:
                result = result[0::self.step]
            try:
                results[output.name] = result
            except ValueError:
                print "what"

        a = results.keys()
        for output in self.activation:
            value = results[output.name]
            time = results["TIME"]
            activationTimeStep = time[value>0]
            if activationTimeStep.shape[0] > 0:
                activationTimeStep = activationTimeStep[0]
            else:
                activationTimeStep = np.array([0])
            results[output.name] = activationTimeStep
            
        
        self.output = results   
        if error:
            raise CaseError("run not completed", case) 
示例#2
0
    def run_model(self, case):
            
        for key, value in case.items():
            vensim.set_value(key, value)
        ema_logging.debug("model parameters set successfully")
        
        ema_logging.debug("run simulation, results stored in " + self.workingDirectory+self.resultFile)
        try:
            vensim.run_simulation(self.workingDirectory+self.resultFile)
        except VensimError:
            raise

        results = {}
        error = False
        for output in self.outcomes:
            ema_logging.debug("getting data for %s" %output.name)
            result = vensim.get_data(self.workingDirectory+self.resultFile, 
                              output.name 
                              )
            ema_logging.debug("successfully retrieved data for %s" %output.name)
            if not result == []:
                if result.shape[0] != self.runLength:
                    a = np.zeros((self.runLength))
                    a[0:result.shape[0]] = result
                    result = a
                    error = True
            
            else:
                result = result[0::self.step]
            try:
                results[output.name] = result
            except ValueError:
                print "what"
    
        self.output = results   
        if error:
            raise CaseError("run not completed", case) 
示例#3
0
class EnergyTrans(VensimModelStructureInterface):
    def __init__(self, workingDirectory, name):
        """interface to the model"""
        super(EnergyTrans, self).__init__(workingDirectory, name)

        self.modelFile = r'\CESUN_optimized_new.vpm'

        #outcomes
        self.outcomes.append(
            Outcome('total fraction new technologies', time=True))
        self.outcomes.append(Outcome('total capacity installed', time=True))

        #Initial values
        self.uncertainties.append(
            ParameterUncertainty((14000, 16000), "ini cap T1"))  #
        self.uncertainties.append(ParameterUncertainty((1, 2),
                                                       "ini cap T2"))  #
        self.uncertainties.append(ParameterUncertainty((1, 2),
                                                       "ini cap T3"))  #
        self.uncertainties.append(ParameterUncertainty((1, 2),
                                                       "ini cap T4"))  #
        self.uncertainties.append(
            ParameterUncertainty((500000, 1500000), "ini cost T1"))  #1000000
        self.uncertainties.append(
            ParameterUncertainty((5000000, 10000000), "ini cost T2"))  #8000000
        self.uncertainties.append(
            ParameterUncertainty((5000000, 10000000), "ini cost T3"))  #8000000
        self.uncertainties.append(
            ParameterUncertainty((5000000, 10000000), "ini cost T4"))  #8000000
        self.uncertainties.append(
            ParameterUncertainty((5000000, 10000000), "ini cum decom cap T1"))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "ini cum decom cap T2"))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "ini cum decom cap T3"))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "ini cum decom cap T4"))
        self.uncertainties.append(
            ParameterUncertainty(
                (1, 5), "average planning and construction period T1"))
        self.uncertainties.append(
            ParameterUncertainty(
                (1, 5), "average planning and construction period T2"))
        self.uncertainties.append(
            ParameterUncertainty(
                (1, 5), "average planning and construction period T3"))
        self.uncertainties.append(
            ParameterUncertainty(
                (1, 5), "average planning and construction period T4"))
        self.uncertainties.append(
            ParameterUncertainty((0.85, 0.95), "ini PR T1"))
        self.uncertainties.append(
            ParameterUncertainty((0.7, 0.95), "ini PR T2"))
        self.uncertainties.append(
            ParameterUncertainty((0.7, 0.95), "ini PR T3"))
        self.uncertainties.append(
            ParameterUncertainty((0.7, 0.95), "ini PR T4"))

        #Plain Parametric Uncertainties
        self.uncertainties.append(ParameterUncertainty((30, 50),
                                                       "lifetime T1"))
        self.uncertainties.append(ParameterUncertainty((15, 20),
                                                       "lifetime T2"))
        self.uncertainties.append(ParameterUncertainty((15, 20),
                                                       "lifetime T3"))
        self.uncertainties.append(ParameterUncertainty((15, 20),
                                                       "lifetime T4"))
        #
        #        #One uncertain development over time -- smoothed afterwards
        self.uncertainties.append(
            ParameterUncertainty((0.03, 0.035), "ec gr t1"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t2"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t3"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t4"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t5"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t6"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t7"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t8"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t9"))  #0.03
        self.uncertainties.append(
            ParameterUncertainty((-0.01, 0.03), "ec gr t10"))  #0.03

        #Uncertainties in Random Functions
        self.uncertainties.append(
            ParameterUncertainty((0.9, 1), "random PR min"))
        self.uncertainties.append(
            ParameterUncertainty((1, 1.1), "random PR max"))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "seed PR T1", integer=True))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "seed PR T2", integer=True))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "seed PR T3", integer=True))
        self.uncertainties.append(
            ParameterUncertainty((1, 100), "seed PR T4", integer=True))

        #Uncertainties in Preference Functions
        self.uncertainties.append(
            ParameterUncertainty((2, 5), "absolute preference for MIC"))
        self.uncertainties.append(
            ParameterUncertainty(
                (1, 3), "absolute preference for expected cost per MWe"))
        self.uncertainties.append(
            ParameterUncertainty((2, 5),
                                 "absolute preference against unknown"))
        self.uncertainties.append(
            ParameterUncertainty((1, 3),
                                 "absolute preference for expected progress"))
        self.uncertainties.append(
            ParameterUncertainty(
                (2, 5), "absolute preference against specific CO2 emissions"))
        #TOEVOEGEN SWITCHES ZODAT BOVENSTAANDE CRITERIA WEL OF NIET GEBRUIKT WORDEN...
        self.uncertainties.append(
            CategoricalUncertainty((0, 1),
                                   "SWITCH preference for MIC",
                                   default=1))
        self.uncertainties.append(
            CategoricalUncertainty(
                (0, 1),
                "SWITCH preference for expected cost per MWe",
                default=0))
        self.uncertainties.append(
            CategoricalUncertainty((0, 1),
                                   "SWITCH preference against unknown",
                                   default=0))
        self.uncertainties.append(
            CategoricalUncertainty((0, 1),
                                   "SWITCH preference for expected progress",
                                   default=0))
        self.uncertainties.append(
            CategoricalUncertainty(
                (0, 1),
                "SWITCH preference against specific CO2 emissions",
                default=0))
        #Uncertainties DIE NOG AANGEPAST MOETEN WORDEN
        self.uncertainties.append(
            ParameterUncertainty((1, 2),
                                 "performance expected cost per MWe T1"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5),
                                 "performance expected cost per MWe T2"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5),
                                 "performance expected cost per MWe T3"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5),
                                 "performance expected cost per MWe T4"))
        self.uncertainties.append(
            ParameterUncertainty((4, 5), "performance CO2 avoidance T1"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5), "performance CO2 avoidance T2"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5), "performance CO2 avoidance T3"))
        self.uncertainties.append(
            ParameterUncertainty((1, 5), "performance CO2 avoidance T4"))

        #        #Switches op technologies
        self.uncertainties.append(
            CategoricalUncertainty((0, 1), "SWITCH T3", default=1))
        self.uncertainties.append(
            CategoricalUncertainty((0, 1), "SWITCH T4", default=1))
        self.uncertainties.append(
            CategoricalUncertainty(([(0, 0, 0, 0, 1), (0, 0, 0, 1, 0),
                                     (0, 0, 0, 1, 1), (0, 0, 1, 0, 0),
                                     (0, 0, 1, 0, 1), (0, 0, 1, 1, 0),
                                     (0, 0, 1, 1, 1), (0, 1, 0, 0, 0),
                                     (0, 1, 0, 0, 1), (0, 1, 0, 1, 0),
                                     (0, 1, 0, 1, 1), (0, 1, 1, 0, 0),
                                     (0, 1, 1, 0, 1), (0, 1, 1, 1, 0),
                                     (0, 1, 1, 1, 1), (1, 0, 0, 0, 0),
                                     (1, 0, 0, 0, 1), (1, 0, 0, 1, 0),
                                     (1, 0, 0, 1, 1), (1, 0, 1, 0, 0),
                                     (1, 0, 1, 0, 1), (1, 0, 1, 1, 0),
                                     (1, 0, 1, 1, 1), (1, 1, 0, 0, 0),
                                     (1, 1, 0, 0, 1), (1, 1, 0, 1, 0),
                                     (1, 1, 0, 1, 1), (1, 1, 1, 0, 0),
                                     (1, 1, 1, 0, 1), (1, 1, 1, 1, 0),
                                     (1, 1, 1, 1, 1)]), "preference switches"))

        #switch for addfactor activation
#        self.uncertainties.append(CategoricalUncertainty((0,1), "switchaddfactorco2", default = 1))

    def model_init(self, policy, kwargs):
        try:
            self.modelFile = policy['file']
        except:
            logging.debug("no policy specified")
        super(EnergyTrans, self).model_init(policy, kwargs)

    def run_model(self, case):
        switches = case.pop("preference switches")

        case["SWITCH preference for MIC"] = switches[0]
        case["SWITCH preference for expected cost per MWe"] = switches[1]
        case["SWITCH preference against unknown"] = switches[2]
        case["SWITCH preference for expected progress"] = switches[3]
        case["SWITCH preference against specific CO2 emissions"] = switches[4]

        if np.sum(switches) == 0:
            print "sifir olan cikti haci!"

        for key, value in case.items():
            vensim.set_value(key, value)
        ema_logging.debug("model parameters set successfully")

        ema_logging.debug("run simulation, results stored in " +
                          self.workingDirectory + self.resultFile)
        try:
            vensim.run_simulation(self.workingDirectory + self.resultFile)
        except VensimError as e:
            raise

        results = {}
        error = False
        for output in self.outcomes:
            ema_logging.debug("getting data for %s" % output.name)
            result = vensim.get_data(self.workingDirectory + self.resultFile,
                                     output.name)
            ema_logging.debug("successfully retrieved data for %s" %
                              output.name)
            if not result == []:
                if result.shape[0] != self.runLength:
                    a = np.zeros((self.runLength))
                    a[0:result.shape[0]] = result
                    result = a
                    error = True

            else:
                result = result[0::self.step]
            try:
                results[output.name] = result
            except ValueError as e:
                print "what"


#        for output in self.activation:
#            value = results[output.name]
#            time = results["TIME"]
#            activationTimeStep = time[value>0]
#            if len(activationTimeStep) > 0:
#                activationTimeStep = activationTimeStep[0]
#            else:
#                activationTimeStep = np.array([0])
##            if activationTimeStep.shape[0] > 0:
##                activationTimeStep = activationTimeStep
##            else:
##                activationTimeStep = np.array([0])
#            results[output.name] = activationTimeStep

        self.output = results
        if error:
            raise CaseError("run not completed", case)