<jupyter_start><jupyter_text>Data Definitions<jupyter_code>n_warehouses = 2
n_customers = 4
cost_matrix = np.array([[1,3,0.5,4],[2.5,5,1.5,2.5]])
cust_demands = np.array([35000, 22000, 18000, 30000])
warehouse_supply = np.array([60000, 80000])<jupyter_output><empty_output><jupyter_text>Model Initialization<jupyter_code>model = LpProblem("Supply-Demand-Problem", LpMinimize)<jupyter_output><empty_output><jupyter_text>Variable Names define<jupyter_code>variable_names = [str(i)+str(j) for j in range(1, n_customers+1) for i in range(1,n_warehouses+1)]
variable_names.sort()
variable_names<jupyter_output><empty_output><jupyter_text>Decision Variables<jupyter_code>DV_variables = LpVariable.matrix("X", variable_names , cat = "Integer" , lowBound= 0 )
allocation = np.array(DV_variables).reshape(2,4)
allocation<jupyter_output><empty_output><jupyter_text>Objective Function<jupyter_code>lpSum(allocation*cost_matrix)
obj_func = lpSum(allocation*cost_matrix)
# Objective Function 
model +=  obj_func
model<jupyter_output><empty_output><jupyter_text>Constraints<jupyter_code># Warehouse Constraints
for i in range(n_warehouses):
    print(lpSum(allocation[i][j] for j in range(n_customers)) <= warehouse_supply[i])
    model += lpSum(allocation[i][j] for j in range(n_customers)) <= warehouse_supply[i] , "Supply Constraints " + str(i)
# Customer Constraints
for j in range(n_customers):
    print(lpSum(allocation[i][j] for i in range(n_warehouses)) >= cust_demands[j])
    model += lpSum(allocation[i][j] for i in range(n_warehouses)) >= cust_demands[j] , "Demand Constraints " + str(j)
model<jupyter_output><empty_output><jupyter_text>Save problem - Write it<jupyter_code>model.writeLP("Supply_demand_prob.lp")<jupyter_output><empty_output><jupyter_text>Solve Problem and check Status<jupyter_code>model.solve()
# solvers.PULP_CBC_CMD(fracGap=0)
status =  LpStatus[model.status]
print(status)<jupyter_output>Optimal<jupyter_text>Objective Function values and Decision Variable Values<jupyter_code>print("Total Cost:", model.objective.value())
# Decision Variables

for v in model.variables():
    try:
        print(v.name,"=", v.value())
    except:
        print("error couldnt find value")<jupyter_output>Total Cost: 200000.0
X_11 = 35000.0
X_12 = 22000.0
X_13 = 3000.0
X_14 = 0.0
X_21 = 0.0
X_22 = 0.0
X_23 = 15000.0
X_24 = 30000.0<jupyter_text>Further Analysis<jupyter_code># Warehouse 1 and Warehouse 2 required capacity
for i in range(n_warehouses):
    print("Warehouse ", str(i+1))
    print(lpSum(allocation[i][j].value() for j in range(n_customers)))<jupyter_output>Warehouse  1
60000.0
Warehouse  2
45000.0
{'fraction_non_alphanumeric': 0.13249331806032838, 'fraction_numerical': 0.048491790759831996, 'mean_word_length': 7.675496688741722, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '577698', 'license': 'MIT', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1006, 'n_words': 170, 'path': 'Optimization_Problem_Example.ipynb', 'repo_name': 'mnips/Linear-Programming-Python-1', 'size': '2619'}