def set_capacity(cell, capacity):
    """
        Set the sugar capacity of the cell.
    """    
    env = get_env(cell)
    if capacity < 0:
        raise Exception("The sugar capacity of a cell cannot be negative.")
    if capacity > e.get_max_capacity(env):
        print("Capa = ",capacity,"   max = ",e.get_max_capacity(env))
        raise Exception("The sugar capacity of a cell cannot exceed the maximum capacity for the environment.")
    __set_property(cell, SUGAR_CAPACITY_IDX, capacity)
Exemple #2
0
def set_capacity(cell, capacity):
    """
        Set the sugar capacity of the cell.
    """
    env = get_env(cell)
    if capacity < 0:
        raise Exception("The sugar capacity of a cell cannot be negative.")
    if capacity > e.get_max_capacity(env):
        print("Capa = ", capacity, "   max = ", e.get_max_capacity(env))
        raise Exception(
            "The sugar capacity of a cell cannot exceed the maximum capacity for the environment."
        )
    __set_property(cell, SUGAR_CAPACITY_IDX, capacity)
Exemple #3
0
def env_plot(env, showGrid=True):
    """
        Add a plot of the environment (possibly including a
        grid) to the current pylab plot. 
        To actually show the plot, the pylab.show() method
        still has to be invoked.
    """
    ax = plt.gca()
    ax.set_aspect('equal', 'box')
    ax.xaxis.set_major_locator(plt.NullLocator())
    ax.yaxis.set_major_locator(plt.NullLocator())
    sz = e.size(env)
    mat = []
    row = []
    col = []
    sugar = []
    size_factor = 3000.0/sz/e.get_max_capacity(env)
    # Plot sugar level of each cell
    for cell_ref in e.get_cell_refs(env):
        cell = e.get_cell(env, cell_ref)
        (y, x) = cell_ref
        row.append(y+0.5)
        col.append(x+0.5)
        sugar.append(size_factor*c.get_sugar_level(cell))
    plt.scatter(row, col, sugar, color='yellow', alpha=1)#, marker='s')
    # Plot the grid (or only an outer border)
    for k in range(sz+1):
        if showGrid or k == 0 or k == sz:
            plt.plot([k, k], [0, sz], color='black', alpha=0.1, ls='-')
            plt.plot([0, sz], [k, k], color='black', alpha=0.1, ls='-')
Exemple #4
0
def __compute_cell_color(cell):
    # Compute the color of the cell, depending on its sugar level
    sugar_level = c.get_sugar_level(cell)
    env = c.get_env(cell)
    max_capacity = e.get_max_capacity(env)
    ratio = sugar_level / max_capacity
    color_level = int(255 * (1 - ratio))
    # convert the color level to hexadecimal representation
    hex_color_level = hex(color_level)[2:].zfill(2)
    color_code = '#' + 'ff' + 'ff' + hex_color_level
    return color_code
Exemple #5
0
def __compute_cell_color(cell):
    # Compute the color of the cell, depending on its sugar level
    sugar_level = c.get_sugar_level(cell)
    env = c.get_env(cell)
    max_capacity = e.get_max_capacity(env)
    ratio = sugar_level / max_capacity
    color_level = int(255 * (1 - ratio))
    # convert the color level to hexadecimal representation
    hex_color_level = hex(color_level)[2:].zfill(2)
    color_code = '#' + 'ff' + 'ff' + hex_color_level
    return color_code
Exemple #6
0
def add_capacity(cell, capacity, mas):
    """
        Add capacity to a cell (in addition to the capacity)
        the cell already has.
        Usually, this function is only called by other capacity
        initialisation functions, e.g. "add_capacity_gaussian" 
        in the "mas_environment" module.
    """
    # Add the current capacity of the cell to the value of the
    # parameter "capacity".
    capacity += get_capacity(cell)
    # Limit it to the maximum capacity of the environment.
    env = m.get_env(mas)
    max_capacity = e.get_max_capacity(env)
    if capacity <= max_capacity:
        set_capacity(cell, capacity, mas)
    else:
        set_capacity(cell, max_capacity, mas)
def add_capacity(cell, capacity):
    """
        Add capacity to a cell (in addition to the capacity)
        the cell already has.
        Usually, this function is only called by other capacity
        initialisation functions, e.g. "add_capacity_gaussian" 
        in the "mas_environment" module.
    """
    # Add the current capacity of the cell to the value of the
    # parameter "capacity".
    capacity += get_capacity(cell)
    # Limit it to the maximum capacity of the environment.
    env = get_env(cell)
    max_capacity = e.get_max_capacity(env)
    if capacity <= max_capacity:
        set_capacity(cell, capacity)
    else:
        set_capacity(cell, max_capacity)