<jupyter_start><jupyter_text>Document for the problem  The Warehouse Location ProblemWe use the warehouse location problem throughout this chapter, which considersthe optimal locations to build warehouses to meet delivery demands. Let `N` be aset of candidate warehouse locations, and let `M` be a set of customer locations. Foreach warehouse `n`, the cost of delivering product to customer `m` is given by $ d_{n,m} $.We wish to determine the optimal warehouse locations that will minimize the totalcost of product delivery. The binary variables $y_n$ are used to define whether or not awarehouse should be built, where $y_n$ is 1 if warehouse `n` is selected and 0 otherwise.The variable $x_{n,m}$ indicates the fraction of demand for customer m that is served bywarehouse `n`. The variables `x` and `y` are determined by the optimizer, and all other quantities areknown inputs or parameters in the problem. This problem is a particular descriptionof the p-median problem, and it has the interesting property that the `x` variables willconverge to {0, 1} even though they are not specified as binary variables.The complete problem formulation is:Objective:$$min \sum_{n \in N}{\sum_{m \in M}{d_{n,m}x_{n,m}}}$$s.t.:$$\sum_{n \in N}{x_{n,m}} = 1, \forall m \in M$$$$x_{n,m} \leq y_n, \forall n \in N, m \in M$$$$\sum_{n \in N}{y_n} \leq P$$$$0 \leq x \leq 1$$$$y \in {0, 1}$$ Here, the objective is to minimize the total cost associated with delivering products to all the customers. Equation WL.2 ensures that each customer’sdemand is fully met, and equation WL.3 ensures that a warehouse can deliver product to customers only if that warehouse is selected to be built. Finally, with equation WL.4 the number of warehouses that can be built is limited to `P`.For our example, we will assume that $P = 2$, with the following data for warehouse and customer locations,For our example, we will assume that $P = 2$, with the following data for warehouse and customer locations,```Customer locations            M = {‘NYC’, ‘LA’, ‘Chicago’, ‘Houston’}Candidate warehouse locations N = {‘Harlingen’, ‘Memphis’, ‘Ashland’}```with the costs $d_{n,m}$ as given in the following table:|           | NYC  | LA   | Chicago | Houston || --------- | ---- | ---- | ------- | ------- || Harlingen | 1956 | 1606 | 1410    | 330     || Memphis   | 1096 | 1792 | 531     | 567     || Ashland   | 485  | 2322 | 324     | 1236    |<jupyter_code>import os
import pandas as pd
# import ipymaterialui as mui
import ipywidgets as widgets
from IPython.display import display

# import ipyvuetify as v<jupyter_output><empty_output><jupyter_text>Read the data from csv using pandas---<jupyter_code>data_select = widgets.RadioButtons(
    options=['Upload', 'Select'],
    value='Select'
)
data_source = widgets.Dropdown(description='Data file:')
uploader = widgets.FileUpload(
        accept='.csv',  # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'
        multiple=False  # True to accept multiple files upload else False
)
def create_data_file_dd(data_source):
    data_file_list = list()

    cwd = os.getcwd()
    for item in os.listdir(cwd):
        if os.path.isfile(os.path.join(cwd, item)) and item.lower().endswith(".csv"):
            data_file_list.append(item)

    default_value = data_file_list[0] if data_file_list else None
    
    data_source.options = data_file_list
    data_source.value = default_value

    display(data_source)
out = widgets.Output()

@out.capture(clear_output=True, wait=True)
def display_data_source(*args):
    if data_select.value == "Select":
        create_data_file_dd(data_source)
    else:
        display(uploader)

display_data_source()
data_select.observe(display_data_source, 'value')
display(widgets.HBox([data_select, out]))
import io

def load_data(csv_file_path) -> pd.DataFrame:
    if data_select.value == 'Upload':
        df = pd.read_csv(io.BytesIO(uploader.get_state()['data'][0]), index_col=0)
    else:
        df = pd.read_csv(csv_file_path, index_col=0)
    return df<jupyter_output><empty_output><jupyter_text>Show the data<jupyter_code>sd_button = widgets.Button(description='Show the data')
out_data = widgets.Output()

display(sd_button, out_data)

data = None

def on_button_click(b):
    global data
    with out_data:
        data = load_data(data_source.value)
        print(data)

sd_button.on_click(on_button_click)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1120162932790224, 'fraction_numerical': 0.013804028060647205, 'mean_word_length': 4.10392609699769, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '481744', 'license': 'MIT', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1335, 'n_words': 480, 'path': 'test.ipynb', 'repo_name': 'ZS-Gao/binder_test', 'size': '4419'}