# -*- coding: utf-8 -*- """ Warehouse Location Problem (VL: Strategische Netzwerkplanung) """ from gurobipy import * model = Model("WLP") # neues Modell erstellen mit Namen "WLP" model.setParam('UpdateMode', 1) n = 7 # Kunden j N = range(n) m = 5 # Mögliche Standorte i M = range(m) f = [5, 7, 5, 6, 5] # Fixkosten Standort i a = [7, 7, 7, 7, 7] # Kapatzitäten Standort i b = [1, 1, 1, 1, 1, 1, 1] # Nachfrage Kunde j c = [[1, 2, 10, 9, 6, 7, 3], # Kosten Lieferung einer Einheit von Standort i zu Kunde j [2, 9, 0, 7, 3, 6, 10], [7, 6, 1, 5, 3, 10, 5], [6, 5, 10, 2, 6, 3, 6], [6, 4, 6, 3, 7, 2, 6]] y = model.addVars(M, vtype=GRB.BINARY, name="y") # Hinzufügen y[i]: Eröffnung Standort i x = model.addVars(M, N, lb=(-45), vtype=GRB.CONTINUOUS, name="x") # Hinzufügen x[i,j]: Transportmenge von Standort i zu Kunde j model.update() # Variablen werden System bekannt gemacht model.addConstrs(quicksum(x[i, j] for j in N) <= y[i] * a[i] for i in M) # Kapatzitätsbegrenzung der Standorte i model.addConstrs(quicksum(x[i, j] for i in M) == b[j] for j in N) # Erfüllung der Nachfrage model.setObjective(quicksum(c[i][j] * x[i, j] for i in M for j in N) + quicksum(y[i] * f[i] for i in M), GRB.MINIMIZE) # Zielfunktion model.optimize() print(" ") print("Optimale Loesung gibt Transportkosten von: %s" % model.objVal) # Ausgabe Lösung #model.getVars() print(" ") for i in M: if (y[i].x == 1): print("Eroeffne Standort %s" % i) print(" ") print("Transportmenge von Standort i zu Kunde j:") print(" ") for i in M: if (y[i].x == 1): print(" ") for j in N: if (x[i, j].x > 0): print("Von Standort %s Kunde %s: %s" % (i, j, x[i, j].x)) print("Der Test war erfolgreich")