예제 #1
0
def run_interval(model,loop_index,interval,VOI,edges,ind_cons,
                 double_list,case):
    
    # Load the model.
    vensim.load_model(model)
    
    case = copy.deepcopy(case)
    set_lookups(case)
    
    for key,value in case.items():
        vensim.set_value(key,repr(value))
#        print key, repr(value), vensim.get_val(key), value-vensim.get_val(key)

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

    # 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')
        ema_logging.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)
                    vensim.set_value('switch loop '+str(loop_index),
                                     loop_off)
        
                # Else it is based on unique consecutive edges.
                else:
                    constant_value = vensim.get_val(edges[int(loop_index-1)][0])
                    
                    if loop_off==1:
                        constant_value = 0
                    
                    # 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),
                                         loop_off)
                    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),
                                         loop_off)
                        
            venDLL.command('GAME>GAMEINTERVAL|'+str(end_interval-start_interval))
            
        elif time ==(2000+step*interval[1]) and loop_turned_off:
            loop_turned_off = False
            if loop_index != 0:
                # If loop elimination method is based on unique edge.
                if loop_index-1 < ind_cons:
                    constant_value = 0
                    vensim.set_value('value loop '+str(loop_index),
                                     constant_value)
                    vensim.set_value('switch loop '+str(loop_index),
                                     loop_on)
        
                # Else it is based on unique consecutive edges.
                else:
                    constant_value = 0
                    # 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),
                                         loop_on)
                    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),
                                         loop_on)
            
            finalT = vensim.get_val('FINAL TIME')
            currentT = vensim.get_val('TIME')
            venDLL.command('GAME>GAMEINTERVAL|'+str(finalT - currentT))
        
        else:
            break
        
        finalT = vensim.get_val('FINAL TIME')
        currentT = vensim.get_val('TIME')
        if finalT != currentT:
            venDLL.command('GAME>GAMEON')
    
    venDLL.command('GAME>ENDGAME')
    interval_series = vensim.get_data('Base.vdf',VOI)

    
    return interval_series
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
예제 #3
0
def run_interval(model,loop_index,interval,VOI,edges,ind_cons,
                 double_list,case):

    # Load the model.
    vensim.load_model(model)

    case = copy.deepcopy(case)
    set_lookups(case)

    for key,value in case.items():
        vensim.set_value(key,repr(value))
#        print key, repr(value), vensim.get_val(key), value-vensim.get_val(key)

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

    # 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:
예제 #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
#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
        # than raise a warning
        print "blaat"
        break       
    vensim.set_value(r'FRAC EP FOR TRAINING',0.04)



예제 #6
0
#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
        # than raise a warning
        print "blaat"
        break       
    vensim.set_value(r'FRAC EP FOR TRAINING',0.04)