<jupyter_start><jupyter_text>Decision Variable:\begin{equation}\begin{array}{11}\ Y_{i,k} & \forall i \in R, k \in WD\end{array}\end{equation}\begin{equation}\begin{array}{11}\ X_{i,j,k} & \forall i \in R, j \in S, k \in WD\end{array}\end{equation}Objective Function:\begin{equation}\begin{array}{ll}\text{minimise} &  \sum_{i \in R}  \sum_{k \in W} Y_{i,k}  c_{i,k}\\\end{array}\end{equation}Subject to:\Respecting Demand Constraints\begin{equation}\begin{array}{11}\sum_{i \in R} \sum_{k \in W}  X_{i,j,k} m_{i,j} = d_j & \forall j \in S\end{array}\end{equation}\Respecting Delivery Acceptance Constraints\begin{equation}\begin{array}{11}\sum_{i \in R} X_{i,j,k} m_{i,j} \le a_j & \forall j \in S, k \in W\end{array}\end{equation}\Respecting Truck Constraints\begin{equation}\begin{array}{11}\sum_{j \in S} X_{i,j,k}m_{i,j} \le C_iY_{i,k} & \forall i \in R, k \in W\end{array}\end{equation}\General Representations\Sets* R: Set of routes* S: Set of stores* W: Set of days in a week\Parameters\$\begin{equation} \begin{array}{11}d_j & \text{: Weekly demand of store j,} & j \in S  \end{array}\end{equation}$$\begin{equation} \begin{array}{11}a_j & \text{: Delivery acceptance limits for store j,} & j \in S  \end{array}\end{equation}$$\begin{equation} \begin{array}{11}m_{i,j} & \text{: Dummy variable to indicate 1 if store j is along route i and 0 otherwise,} & i \in R, j \in S  \end{array}\end{equation}$$\begin{equation} \begin{array}{11}c_{i,k} & \text{: Cost of  truck on each route i on day k } \end{array}\end{equation}$$\begin{equation} \begin{array}{11}C_{i} & \text{: Full capacity of truck on route i on each day  } \end{array}\end{equation}$\Variables$\begin{equation} \begin{array}{11}X_{i,j,k} & \text{: Units on each route i to be delivered to a store j on day k} \\Y_{i,k} & \text{: If route i is used on day k}\end{array}\end{equation}$\Entities* i: Route in R* j: Store in S* k: Day in W<jupyter_code>#Importing Packages

from gurobipy import *
from math import sqrt
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import xlrd
#Importing Data

routes = pd.read_excel("routes.xlsx").to_numpy()
print(routes)

demand = pd.read_excel("data-demands-deliveyconstraint.xlsx").to_numpy()
print(demand)

#Demand
d = demand[:,1]

#Delivery constraints
dc = demand[:,2]

#Route matrix
#Store names 
snames = demand[:,0]

count = 1
mat = np.zeros(24)
for i in snames:
    routestore1 = (routes[:,1] == str(i)) * 1
    routestore2 = (routes[:,2] == str(i)) * 1
    mainroutestore = routestore1 + routestore2
    mat = np.row_stack((mat, mainroutestore))
    #mat = np.concatenate((mat, mainroutestore),axis=1)
    
mat = np.array(mat, dtype='int16')[1:,:].transpose((1,0))

print(mat)

#Shipping costs
c = np.full((24, 18), 100)
c

#Supply constraints (truck capacity)
t = np.full((24,7), 24)
t
#Transportation Problem
m4 = Model('transportation')

#Variables
#Variables are in proportion
var = m4.addVars(24,18,7)
yvar = m4.addVars(24,7,vtype = GRB.BINARY)

#Objective
m4.setObjective(sum(yvar[i,k] for i in range(24) for k in range(7)), GRB.MINIMIZE)

#Weekly Demand
for j in range(18):
    m4.addConstr(sum(var[i,j,k]*mat[i,j] for i in range(24) for k in range(7)) == d[j])
    
#Delivery Constraints
for j in range(18):
    for k in range(7):
        m4.addConstr(sum(var[i,j,k]*mat[i,j] for i in range(24)) <= 0.6*dc[j])

#Supply constraint
for i in range(24):
    for k in range(7):
        m4.addConstr(sum(var[i,j,k]*mat[i,j] for j in range(18)) <= t[i,k]*yvar[i,k])
        
#Solving the optimization problem
m4.optimize()

#Printing the optimal solutions obtained
print("Optimal Solutions:")
for i, val in var.items():
    if val.getAttr("x") != 0:
        print("Number of units from route %g to store %g on day %g:\t %g " %(i[0]+1, i[1]+1, i[2]+1, val.getAttr("x")))
        
        
#Printing y
for i, val in yvar.items():
    print("Run route %g on day %g:\t %g " %(i[0]+1, i[1]+1, val.getAttr("x")))
    
print(yvar)
 

for i in range(24):
    for k in range(7):
        print(yvar[i,k].getAttr("x"))<jupyter_output>0.0
0.0
0.0
0.0
0.0
0.0
0.0
-0.0
1.0
-0.0
1.0
1.0
-0.0
1.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
1.0
1.0
1.0
1.0
1.0
1.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0
1.0
-0.0
1.0
-0.0
1.0
1.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
-0.0
1.0
1.0
1.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
-0.0
1.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0
0.0
0.0
1.0
0.0
0.0
0.0
0.0
1.0
-0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0
0.0
0.0
1.0
1.0
1.0
1.0
-0.0
1.0
-0.0
-0.0
-0.0
1.0
1.0
1.0
0.0
1.0
1.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
-0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0.0
0.0
0.0
0.0
{'fraction_non_alphanumeric': 0.1970391993327773, 'fraction_numerical': 0.09216013344453712, 'mean_word_length': 3.2042068361086766, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '510568', 'license': 'Apache-2.0', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2320, 'n_words': 596, 'path': 'IRP Formulation/Algo2-4.ipynb', 'repo_name': 'Ellusionists/Thesis', 'size': '4796'}