Skip to content

groff_heuristic.py

groff_heuristic

dict_in = {'planningPeriod': 8, 'fixedCost': 40, 'varCost': 1, 'roll': 4} module-attribute

demand = [40, 50, 10, 20, 30, 40, 20, 25] module-attribute

groff = GroffHeuristic() module-attribute

output = groff.run(dict_in, demand) module-attribute

GroffHeuristic

Source code in examples/lot_sizing/lot_optimizers/groff_heuristic.py
class GroffHeuristic:
    def __init__(self):
        pass

    def run(self, dict_in, demand):
        # Füllen der Variablen aus Start_Dictionary
        dem = demand
        kf = dict_in["fixedCost"]
        kv = dict_in["varCost"]
        pp = len(dem)
        orders = [0 for i in range(pp)]
        cost_v = 0
        j = 0
        p = 0
        criterion = (2 * kf) / kv

        # testen ob "Null-Perioden am Anfang vorliegen
        while dem[p] == 0:
            orders[p] = 0
            p = p + 1
            if p == pp:
                p = p - 1
                break
        i = p

        while p < pp:
            for i in range(p, pp):
                crit_met = False
                if dem[i] * j * ((i - p) + 1) <= criterion:
                    orders[p] += dem[i]
                    crit_met = True
                    cost = dem[i] * kv * (i - p)
                    j = j + 1
                    cost_v = cost + cost_v
                else:
                    break
            if (p == (pp - 1)) or (crit_met and i == (pp - 1)):
                break
            j = 0
            p += i - p
        x = orders.count(0)
        fix = (pp - x) * kf
        print(fix)
        total_c = cost_v + fix
        print("total cost: " + str(total_c))
        print(sum(orders))
        return np.array(orders)

__init__()

Source code in examples/lot_sizing/lot_optimizers/groff_heuristic.py
def __init__(self):
    pass

run(dict_in, demand)

Source code in examples/lot_sizing/lot_optimizers/groff_heuristic.py
def run(self, dict_in, demand):
    # Füllen der Variablen aus Start_Dictionary
    dem = demand
    kf = dict_in["fixedCost"]
    kv = dict_in["varCost"]
    pp = len(dem)
    orders = [0 for i in range(pp)]
    cost_v = 0
    j = 0
    p = 0
    criterion = (2 * kf) / kv

    # testen ob "Null-Perioden am Anfang vorliegen
    while dem[p] == 0:
        orders[p] = 0
        p = p + 1
        if p == pp:
            p = p - 1
            break
    i = p

    while p < pp:
        for i in range(p, pp):
            crit_met = False
            if dem[i] * j * ((i - p) + 1) <= criterion:
                orders[p] += dem[i]
                crit_met = True
                cost = dem[i] * kv * (i - p)
                j = j + 1
                cost_v = cost + cost_v
            else:
                break
        if (p == (pp - 1)) or (crit_met and i == (pp - 1)):
            break
        j = 0
        p += i - p
    x = orders.count(0)
    fix = (pp - x) * kf
    print(fix)
    total_c = cost_v + fix
    print("total cost: " + str(total_c))
    print(sum(orders))
    return np.array(orders)