<jupyter_start><jupyter_text><jupyter_code>costs = df_instance.values
num_trips = len(costs)
num_cars = len(costs[0])
num_trips
num_cars
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
%%time
# x[i, j] is an array of 0-1 variables, which will be 1
# if worker i is assigned to task j.
x = {}
for i in range(num_trips):
    for j in range(num_cars):
        x[i, j] = solver.IntVar(0, 1, '')

# Each worker is assigned to at most 1 task.
for i in range(num_trips):
    solver.Add(solver.Sum([x[i, j] for j in range(num_cars)]) <= 1)

# Each task is assigned to exactly one worker.
for j in range(num_cars):
    solver.Add(solver.Sum([x[i, j] for i in range(num_trips)]) == 1)

objective_terms = []
for i in range(num_trips):
    for j in range(num_cars):
        objective_terms.append(costs[i][j] * x[i, j])


solver.Minimize(solver.Sum(objective_terms))
status = solver.Solve()
if status == pywraplp.Solver.OPTIMAL or status == pywraplp.Solver.FEASIBLE:
    print('Total revenue = ', abs(solver.Objective().Value()), '\n')
    for i in range(num_trips):
        for j in range(num_cars):
            # Test if x[i,j] is 1 (with tolerance for floating point arithmetic).
            if x[i, j].solution_value() > 0.5:
                print('trip %d assigned to car %d.  revenue = %d' % (i, j, abs(costs[i][j])))<jupyter_output>Total revenue =  427.49415738392156 

trip 0 assigned to car 3.  revenue = 5
trip 1 assigned to car 0.  revenue = 360
trip 2 assigned to car 2.  revenue = 7
trip 3 assigned to car 1.  revenue = 8
trip 4 assigned to car 4.  revenue = 7
trip 6 assigned to car 6.  revenue = 6
trip 7 assigned to car 5.  revenue = 6
trip 8 assigned to car 8.  revenue = 8
trip 9 assigned to car 7.  revenue = 17
{'fraction_non_alphanumeric': 0.12251843448667045, 'fraction_numerical': 0.033465683494044246, 'mean_word_length': 3.3555555555555556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '529386', 'license': 'Apache-2.0', 'n_tokens_mistral': 715, 'n_tokens_neox': 650, 'n_words': 224, 'path': 'Bio Inspired Optimization Framework for Ride Matching Problem/Hungarian Method.ipynb', 'repo_name': 'abdelmageeda/Fall2020-Projects', 'size': '1763'}