Ex 3: Transportation Turns

Question:

Now you have fabricated all your voussoir. You have a cargo van which could carry 900 kg in maximum and you would use it to transport all your pieces from the factory to the site. How many turns would you need?

Here is the list containing the weight of 100 voussoirs.

voussoirs = [10.88, 24.71, 10.16, 18.85, 19.45, 24.24, 20.33, 17.52, 20.65, 18.72, 17.65, 13.99, 14.34, 22.85, 11.33, 13.53, 17.53, 13.22, 21.14, 12.96, 16.75, 12.87, 19.28, 13.49, 12.78, 20.07, 20.37, 24.32, 16.16, 14.45, 13.87, 10.9, 17.06, 15.04, 20.8, 20.19, 19.71, 12.46, 13.87, 19.87, 11.52, 13.67, 18.47, 14.43, 23.56, 23.28, 10.42, 24.41, 12.54, 24.27, 24.71, 12.36, 12.63, 19.32, 20.46, 18.24, 24.12, 12.17, 11.9, 24.88, 22.36, 21.76, 19.69, 17.84, 18.64, 14.5, 16.67, 11.13, 18.81, 22.36, 13.41, 19.1, 11.28, 10.66, 18.43, 20.32, 11.15, 12.09, 17.09, 20.91, 13.52, 23.54, 21.28, 10.97, 22.39, 10.57, 19.17, 19.18, 20.67, 24.76, 13.33, 19.91, 14.57, 14.92, 14.17, 21.26, 11.42, 19.58, 14.77, 13.81]

Answer:

1. Check the first turn

Let's think about the first turn. You want to put as many voussoirs on the truck as possible. Pick one voussoir. If the truck's load capacity is not filled, you could put it there. Keep doing this until the truck is full or you have checked all the voussoirs and no one fits the truck anymore.

# ==============================================================================
# Input
# ==============================================================================
# voussoir weight list
voussoirs = [10.88, 24.71, 10.16, 18.85, 19.45, 24.24, 20.33, 17.52, 20.65, 18.72, 17.65, 13.99, 14.34, 22.85, 11.33, 13.53, 17.53, 13.22, 21.14, 12.96, 16.75, 12.87, 19.28, 13.49, 12.78, 20.07, 20.37, 24.32, 16.16, 14.45, 13.87, 10.9, 17.06, 15.04, 20.8, 20.19, 19.71, 12.46, 13.87, 19.87, 11.52, 13.67, 18.47, 14.43, 23.56, 23.28, 10.42, 24.41, 12.54,
             24.27, 24.71, 12.36, 12.63, 19.32, 20.46, 18.24, 24.12, 12.17, 11.9, 24.88, 22.36, 21.76, 19.69, 17.84, 18.64, 14.5, 16.67, 11.13, 18.81, 22.36, 13.41, 19.1, 11.28, 10.66, 18.43, 20.32, 11.15, 12.09, 17.09, 20.91, 13.52, 23.54, 21.28, 10.97, 22.39, 10.57, 19.17, 19.18, 20.67, 24.76, 13.33, 19.91, 14.57, 14.92, 14.17, 21.26, 11.42, 19.58, 14.77, 13.81]
# index list to store the voussoirs on the truck
index = []
# remaining weight on the truck
remaining_weight = 900

# ==============================================================================
# Check voussoirs on the truck and the remainings
# ==============================================================================
for i, voussoir in enumerate(voussoirs):
    if voussoir <= remaining_weight:
        remaining_weight -= voussoir
        index.append(i)
print("Turn one would take voussoir", index)

voussoirs = [voussoir for i, voussoir in enumerate(voussoirs) if i not in index]

# ==============================================================================
# Output
# ==============================================================================
print("Remaining voussoirs", voussoirs)

2. Turn one turn into a function

After the first turn, we should update the voussoirs list, which contains the ones not on the truck. Then we could start the second turn, and repeat it until all our voussoirs are on the truck.

def check_left_voussoirs(voussoirs, max_load=900):
    """
    Given the voussoirs and max load of the truck,
    Check the remaining voussoirs after truck is fully loaded

    Parameters
    ----------
    voussoirs: list
        A list containing the weight of voussoirs
    max_load: int (optional)
        default: 900
        The maximum load capacity of the truck

    Returns
    -------
    voussoirs: list
        A list containing the weight of remaining voussoirs.

    """
    # index list to store the voussoirs on the truck
    index = []
    # initiate remaining weight on the truck with the max load capacity
    remaining = max_load

    # check voussoirs on the truck and the remainings
    for i, voussoir in enumerate(voussoirs):
        if voussoir <= remaining:
            remaining -= voussoir
            index.append(i)
    voussoirs = [voussoir for i, voussoir in enumerate(voussoirs) if i not in index]

    return voussoirs

3. Call the function

turns = 0
while voussoirs:
    turns += 1
    voussoirs = check_left_voussoirs(voussoirs, 900)

print("The truck needs", turns, "turns.")

The truck needs 2 turns.

4. Turn check turns into a function

We could also create another function check_turns that could tell us the turns. This function calls check_left_voussoirs inside it.

def check_turns(voussoirs, max_load=900, turns=0):
    """
    Check transportation turns of the truck

    Parameters
    ----------
    voussoirs: list
        A list containing the weight of voussoirs
    max_load: int (optional)
        default: 900
        The maximum load capacity of the truck
    turns: int (optional)
        default: 0
        The initial turns of the truck

    Returns
    -------
    turns: int
        The total turns of the truck to transport all the voussoirs

    """
    while voussoirs:
        turns += 1
        voussoirs = check_left_voussoirs(voussoirs, max_load=max_load)
    return turns
turns = check_turns(voussoirs, max_load=900)

Last updated