Ejemplo n.º 1
0
def perform_loop_knockout():    
    unique_edges = [['In Goods', 'lost'],
                    ['loss unprofitable extraction capacity', 'decommissioning extraction capacity'],
                    ['production', 'In Goods'],
                    ['production', 'lost'],
                    ['production', 'Supply'],
                    ['Real Annual Demand', 'substitution losses'],
                    ['Real Annual Demand', 'price elasticity of demand losses'],
                    ['Real Annual Demand', 'desired extraction capacity'],
                    ['Real Annual Demand', 'economic demand growth'],
                    ['average recycling cost', 'relative market price'],
                    ['recycling fraction', 'lost'],
                    ['commissioning recycling capacity', 'Recycling Capacity Under Construction'],
                    ['maximum amount recyclable', 'recycling fraction'],
                    ['profitability recycling', 'planned recycling capacity'],
                    ['relative market price', 'price elasticity of demand losses'],
                    ['constrained desired recycling capacity', 'gap between desired and constrained recycling capacity'],
                    ['profitability extraction', 'planned extraction capacity'],
                    ['commissioning extraction capacity', 'Extraction Capacity Under Construction'],
                    ['desired recycling', 'gap between desired and constrained recycling capacity'],
                    ['Installed Recycling Capacity', 'decommissioning recycling capacity'],
                    ['Installed Recycling Capacity', 'loss unprofitable recycling capacity'],
                    ['average extraction costs', 'profitability extraction'],
                    ['average extraction costs', 'relative attractiveness recycling']]
    
    unique_cons_edges = [['recycling', 'recycling'],
                           ['recycling', 'supply demand ratio'],
                           ['decommissioning recycling capacity', 'recycling fraction'],
                           ['returns to scale', 'relative attractiveness recycling'],
                           ['shortage price effect', 'relative price last year'],
                           ['shortage price effect', 'profitability extraction'],
                           ['loss unprofitable extraction capacity', 'loss unprofitable extraction capacity'],
                           ['production', 'recycling fraction'],
                           ['production', 'constrained desired recycling capacity'],
                           ['production', 'new cumulatively recycled'],
                           ['production', 'effective fraction recycled of supplied'],
                           ['loss unprofitable recycling capacity', 'recycling fraction'],
                           ['average recycling cost', 'loss unprofitable recycling capacity'],
                           ['recycling fraction', 'new cumulatively recycled'],
                           ['substitution losses', 'supply demand ratio'],
                           ['Installed Extraction Capacity', 'Extraction Capacity Under Construction'],
                           ['Installed Extraction Capacity', 'commissioning extraction capacity'],
                           ['Installed Recycling Capacity', 'Recycling Capacity Under Construction'],
                           ['Installed Recycling Capacity', 'commissioning recycling capacity'],
                           ['average extraction costs', 'profitability extraction']]
    
#    CONSTRUCTING THE ENSEMBLE AND SAVING THE RESULTS
    ema_logging.log_to_stderr(ema_logging.INFO)
    results = load_results(r'base.cPickle')

#    GETTING OUT THOSE BEHAVIOURS AND EXPERIMENT SETTINGS
#    Indices of a number of examples, these will be looked at.
    runs = [526,781,911,988,10,780,740,943,573,991]
    VOI = 'relative market price'
    
    results_of_interest = experiment_settings(results,runs,VOI)
    cases_of_interest = experiments_to_cases(results_of_interest[0])
    behaviour_int = results_of_interest[1][VOI]
    
#    CONSTRUCTING INTERVALS OF ATOMIC BEHAVIOUR PATTERNS
    ints = intervals(behaviour_int,False)

#    GETTING OUT ONLY THOSE OF MAXIMUM LENGTH PER BEHAVIOUR
    max_intervals = intervals_interest(ints)
    
#    THIS HAS TO DO WITH THE MODEL FORMULATION OF THE SWITCHES/VALUES
    double_list = [6,9,11,17,19]
    
    indCons = len(unique_edges)
#    for elem in unique_cons_edges:
#        unique_edges.append(elem)
    
    current = os.getcwd()

    for beh_no in range(0,10):
#        beh_no = 0 # Varies between 0 and 9, index style.
        interval = max_intervals[beh_no]
    
        rmp = behaviour_int[beh_no]
    #    rmp = rmp[interval[0]:interval[1]]
        x = range(0,len(rmp))
        fig = plt.figure()
        ax = fig.add_subplot(111)
    
        vensim.be_quiet()
    #    for loop_index in range(7,8):
        for loop_index in range(1,len(unique_edges)+1):
    
            if loop_index-indCons > 0:
                model_location = current + r'\Models\Consecutive\Metals EMA.vpm'
            elif loop_index == 0:
                model_location = current + r'\Models\Base\Metals EMA.vpm'
            else:
                model_location = current + r'\Models\Switches\Metals EMA.vpm'
        
            serie = run_interval(model_location,loop_index,
                                  interval,'relative market price',
                                  unique_edges,indCons,double_list,
                                  cases_of_interest[beh_no])
            
            if serie.shape != rmp.shape:
                ema_logging.info('Loop %s created a floating point error' % (loop_index))
                ema_logging.info('Caused by trying to switch %s' % (unique_edges[loop_index-1]))
                
            if serie.shape == rmp.shape:
                ax.plot(x,serie,'b')
                
    #        data = np.zeros(rmp.shape[0])
    #        data[0:serie.shape[0]] = serie
    #        ax.plot(x,data,'b')
      
        ax.plot(x,rmp,'r')
        ax.axvspan(interval[0]-1,interval[1], facecolor='lightgrey', alpha=0.5)
        f_name = 'switched unique edges only'+str(beh_no)
        plt.savefig(f_name)
Ejemplo n.º 2
0
def run_interval(model, loop_index, interval, VOI, edges, ind_cons, double_list, uncertain_names, uncertain_values):

    # Load the model.
    vensim.load_model(model)

    # We don't want any screens.
    vensim.be_quiet()

    # We run the model in game mode.
    step = vensim.get_val(r"TIME STEP")
    start_interval = str(interval[0] * step)
    venDLL.command("GAME>GAMEINTERVAL|" + start_interval)

    # Initiate the model to be run in game mode.
    venDLL.command("MENU>GAME")

    while True:
        if vensim.get_val(r"TIME") == 2000:

            # Initiate the experiment of interest.
            # In other words set the uncertainties to the same value as in
            # those experiments.
            for i, value in enumerate(uncertain_values):
                name = uncertain_names[i]
                value = uncertain_values[i]
                vensim.set_value(name, value)

        print vensim.get_val(r"TIME")

        try:
            # Run the model for the length specified in game on-interval.
            venDLL.command("GAME>GAMEON")

            step = vensim.get_val(r"TIME STEP")
            if vensim.get_val(r"TIME") == (2000 + step * interval[0]):

                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])
                        vensim.set_value("value loop " + str(loop_index), constant_value)
                        vensim.set_value("switch loop " + str(loop_index), 0)

                    # Else it is based on unique consecutive edges.
                    else:
                        constant_value = vensim.get_val(edges[int(loop_index - 1)][0])
                        print constant_value

                        # Name of constant value used does not fit loop index minus 'start of cons'-index.
                        if loop_index - ind_cons in double_list:
                            vensim.set_value("value cons loop " + str(loop_index - ind_cons - 1), constant_value)
                            vensim.set_value("switch cons loop " + str(loop_index - ind_cons - 1), 0)
                        else:
                            vensim.set_value("value cons loop " + str(loop_index - ind_cons), constant_value)
                            vensim.set_value("switch cons loop " + str(loop_index - ind_cons), 0)

        except venDLL.VensimWarning:
            # The game on command will continue to the end of the simulation and
            # than raise a warning.
            print "The end of simulation."
            break

    venDLL.finish_simulation()
    interval_series = vensim.get_data("Base.vdf", VOI)
    interval_series = interval_series[interval[0] : interval[1]]

    return interval_series
Ejemplo n.º 3
0
def perform_loop_knockout():
    unique_edges = [['In Goods', 'lost'],
                    ['loss unprofitable extraction capacity', 'decommissioning extraction capacity'],
                    ['production', 'In Goods'],
                    ['production', 'lost'],
                    ['production', 'Supply'],
                    ['Real Annual Demand', 'substitution losses'],
                    ['Real Annual Demand', 'price elasticity of demand losses'],
                    ['Real Annual Demand', 'desired extraction capacity'],
                    ['Real Annual Demand', 'economic demand growth'],
                    ['average recycling cost', 'relative market price'],
                    ['recycling fraction', 'lost'],
                    ['commissioning recycling capacity', 'Recycling Capacity Under Construction'],
                    ['maximum amount recyclable', 'recycling fraction'],
                    ['profitability recycling', 'planned recycling capacity'],
                    ['relative market price', 'price elasticity of demand losses'],
                    ['constrained desired recycling capacity', 'gap between desired and constrained recycling capacity'],
                    ['profitability extraction', 'planned extraction capacity'],
                    ['commissioning extraction capacity', 'Extraction Capacity Under Construction'],
                    ['desired recycling', 'gap between desired and constrained recycling capacity'],
                    ['Installed Recycling Capacity', 'decommissioning recycling capacity'],
                    ['Installed Recycling Capacity', 'loss unprofitable recycling capacity'],
                    ['average extraction costs', 'profitability extraction'],
                    ['average extraction costs', 'relative attractiveness recycling']]

    unique_cons_edges = [['recycling', 'recycling'],
                           ['recycling', 'supply demand ratio'],
                           ['decommissioning recycling capacity', 'recycling fraction'],
                           ['returns to scale', 'relative attractiveness recycling'],
                           ['shortage price effect', 'relative price last year'],
                           ['shortage price effect', 'profitability extraction'],
                           ['loss unprofitable extraction capacity', 'loss unprofitable extraction capacity'],
                           ['production', 'recycling fraction'],
                           ['production', 'constrained desired recycling capacity'],
                           ['production', 'new cumulatively recycled'],
                           ['production', 'effective fraction recycled of supplied'],
                           ['loss unprofitable recycling capacity', 'recycling fraction'],
                           ['average recycling cost', 'loss unprofitable recycling capacity'],
                           ['recycling fraction', 'new cumulatively recycled'],
                           ['substitution losses', 'supply demand ratio'],
                           ['Installed Extraction Capacity', 'Extraction Capacity Under Construction'],
                           ['Installed Extraction Capacity', 'commissioning extraction capacity'],
                           ['Installed Recycling Capacity', 'Recycling Capacity Under Construction'],
                           ['Installed Recycling Capacity', 'commissioning recycling capacity'],
                           ['average extraction costs', 'profitability extraction']]

#    CONSTRUCTING THE ENSEMBLE AND SAVING THE RESULTS
    EMAlogging.log_to_stderr(EMAlogging.INFO)
    results = load_results(r'base.cPickle')

#    GETTING OUT THOSE BEHAVIOURS AND EXPERIMENT SETTINGS
#    Indices of a number of examples, these will be looked at.
    runs = [526,781,911,988,10,780,740,943,573,991]
    VOI = 'relative market price'

    results_of_interest = experiment_settings(results,runs,VOI)
    cases_of_interest = experiments_to_cases(results_of_interest[0])
    behaviour_int = results_of_interest[1][VOI]

#    CONSTRUCTING INTERVALS OF ATOMIC BEHAVIOUR PATTERNS
    ints = intervals(behaviour_int,False)

#    GETTING OUT ONLY THOSE OF MAXIMUM LENGTH PER BEHAVIOUR
    max_intervals = intervals_interest(ints)

#    THIS HAS TO DO WITH THE MODEL FORMULATION OF THE SWITCHES/VALUES
    double_list = [6,9,11,17,19]

    indCons = len(unique_edges)
#    for elem in unique_cons_edges:
#        unique_edges.append(elem)

    current = os.getcwd()

    for beh_no in range(0,10):
#        beh_no = 0 # Varies between 0 and 9, index style.
        interval = max_intervals[beh_no]

        rmp = behaviour_int[beh_no]
    #    rmp = rmp[interval[0]:interval[1]]
        x = range(0,len(rmp))
        fig = plt.figure()
        ax = fig.add_subplot(111)

        vensim.be_quiet()
    #    for loop_index in range(7,8):
        for loop_index in range(1,len(unique_edges)+1):

            if loop_index-indCons > 0:
                model_location = current + r'\Models\Consecutive\Metals EMA.vpm'
            elif loop_index == 0:
                model_location = current + r'\Models\Base\Metals EMA.vpm'
            else:
                model_location = current + r'\Models\Switches\Metals EMA.vpm'

            serie = run_interval(model_location,loop_index,
                                  interval,'relative market price',
                                  unique_edges,indCons,double_list,
                                  cases_of_interest[beh_no])

            if serie.shape != rmp.shape:
                EMAlogging.info('Loop %s created a floating point error' % (loop_index))
                EMAlogging.info('Caused by trying to switch %s' % (unique_edges[loop_index-1]))

            if serie.shape == rmp.shape:
                ax.plot(x,serie,'b')

    #        data = np.zeros(rmp.shape[0])
    #        data[0:serie.shape[0]] = serie
    #        ax.plot(x,data,'b')

        ax.plot(x,rmp,'r')
        ax.axvspan(interval[0]-1,interval[1], facecolor='lightgrey', alpha=0.5)
        f_name = 'switched unique edges only'+str(beh_no)
        plt.savefig(f_name)
Ejemplo n.º 4
0
def run_interval(model, loop_index, interval, VOI, edges, ind_cons,
                 double_list, uncertain_names, uncertain_values):

    # Load the model.
    vensim.load_model(model)

    # We don't want any screens.
    vensim.be_quiet()

    # We run the model in game mode.
    step = vensim.get_val(r'TIME STEP')
    start_interval = str(interval[0] * step)
    venDLL.command('GAME>GAMEINTERVAL|' + start_interval)

    # Initiate the model to be run in game mode.
    venDLL.command("MENU>GAME")

    while True:
        if vensim.get_val(r'TIME') == 2000:

            # Initiate the experiment of interest.
            # In other words set the uncertainties to the same value as in
            # those experiments.
            for i, value in enumerate(uncertain_values):
                name = uncertain_names[i]
                value = uncertain_values[i]
                vensim.set_value(name, value)

        print vensim.get_val(r'TIME')

        try:
            # Run the model for the length specified in game on-interval.
            venDLL.command('GAME>GAMEON')

            step = vensim.get_val(r'TIME STEP')
            if vensim.get_val(r'TIME') == (2000 + step * interval[0]):

                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])
                        vensim.set_value('value loop ' + str(loop_index),
                                         constant_value)
                        vensim.set_value('switch loop ' + str(loop_index), 0)

                    # Else it is based on unique consecutive edges.
                    else:
                        constant_value = vensim.get_val(edges[int(loop_index -
                                                                  1)][0])
                        print constant_value

                        # Name of constant value used does not fit loop index minus 'start of cons'-index.
                        if loop_index - ind_cons in double_list:
                            vensim.set_value(
                                'value cons loop ' +
                                str(loop_index - ind_cons - 1), constant_value)
                            vensim.set_value(
                                'switch cons loop ' +
                                str(loop_index - ind_cons - 1), 0)
                        else:
                            vensim.set_value(
                                'value cons loop ' +
                                str(loop_index - ind_cons), constant_value)
                            vensim.set_value(
                                'switch cons loop ' +
                                str(loop_index - ind_cons), 0)

        except venDLL.VensimWarning:
            # The game on command will continue to the end of the simulation and
            # than raise a warning.
            print "The end of simulation."
            break

    venDLL.finish_simulation()
    interval_series = vensim.get_data('Base.vdf', VOI)
    interval_series = interval_series[interval[0]:interval[1]]

    return interval_series
'''
Created on Jun 26, 2012

@author: localadmin
'''
from expWorkbench import vensim
from expWorkbench import vensimDLLwrapper as venDLL


#load model
vensim.load_model(r'C:\workspace\EMA-workbench\src\sandbox\sils\MODEL.vpm')

# we don't want any screens
vensim.be_quiet()

# we run the model in game mode, with 10 timesteps at a time
# the interval can be modified even during the game, thus allowing for dynamic
# interaction
venDLL.command('GAME>GAMEINTERVAL|10')

# initiate the model to be run in game mode
venDLL.command("MENU>GAME")

while True:
    print vensim.get_val(r'FRAC EP FOR TRAINING')
    print vensim.get_val(r'TIME')
    try:
        #run the model for the length specified via the game interval command
        venDLL.command('GAME>GAMEON')
    except venDLL.VensimWarning:
        # the game on command will continue to the end of the simulation and
Ejemplo n.º 6
0
'''
Created on Jun 26, 2012

@author: localadmin
'''
from expWorkbench import vensim
from expWorkbench import vensimDLLwrapper as venDLL


#load model
vensim.load_model(r'C:\workspace\EMA-workbench\src\sandbox\sils\MODEL.vpm')

# we don't want any screens
vensim.be_quiet()

# we run the model in game mode, with 10 timesteps at a time
# the interval can be modified even during the game, thus allowing for dynamic
# interaction
venDLL.command('GAME>GAMEINTERVAL|10')

# initiate the model to be run in game mode
venDLL.command("MENU>GAME")

while True:
    print vensim.get_val(r'FRAC EP FOR TRAINING')
    print vensim.get_val(r'TIME')
    try:
        #run the model for the length specified via the game interval command
        venDLL.command('GAME>GAMEON')
    except venDLL.VensimWarning:
        # the game on command will continue to the end of the simulation and