Fixed places¶
Assign always the same place to the same pod in small system.
For this tutorial we need following modules
import prp.core.warehouse
import prp.utils as utils
import prp.recorder as recorder
import prp.xy as xy
from prp.solvers.simple import FixedPlaceSolver
import prp.solvers.optimal_fixed as optimal_fixed
If you want to switch on logging, add
import logging
and call later
logging.basicConfig(level=logging.INFO)
Parameters¶
We define paths to JSON files of a small warehouse system:
LAYOUT_FILE = "../data/10-layout.json"
INITIAL_STATE_FILE = "../data/10-initial-state.json"
COSTS_FILE = "../data/10-costs.json"
DEPARTURES_FILE = "../data/10-departures.json"
and store the solution and the optimal initial state to files:
SOLUTION_FILE = "../data/solutions/10-fixed-place-solution.json"
OPTIMAL_SOLUTION_FILE = "../data/solutions/10-fixed-place-opt-solution.json"
OPTIMAL_INITIAL_STATE_FILE = "../data/10-fixed-place-opt-initial-state.json"
Solve with fixed positions.¶
Load a warehouse model from JSON files.
def load_problem():
"""Load a test system with 10 places and 10 pods randomly distributed among them."""
layout = xy.Layout()
with open("../data/10-layout.json", 'r') as infile:
layout.load_from_json(infile)
warehouse = layout.get_empty_warehouse()
costs = layout.get_costs()
warehouse.set_costs(costs)
with open("../data/10-initial-state.json", 'r') as infile:
recorder.load_initial_state_from_json(infile, warehouse)
with open("../data/10-departures.json", 'r') as infile:
departures = recorder.load_departures_from_json(infile)
warehouse.set_departure_generator(departures)
return warehouse
warehouse = load_problem()
Send the pod to the same place as in the initial state. In the small system, that means, assign pod n to place n.
solver = FixedPlaceSolver(warehouse)
solution = []
while not warehouse.finished():
place_id = solver.decide_new_place()
solution.append(place_id)
warehouse.next(place_id)
Print results and save them to a JSON file.
print("Total costs: {} at time {}.".format(warehouse.total_costs, warehouse.t))
utils.create_missing_directories_of_file(SOLUTION_FILE)
with open(SOLUTION_FILE, 'w') as outfile:
Calculate optimal fixed positions¶
Find an optimal initial state and a mapping “pod->place”, such that the fixed-place solution is optimal.
Find optimal mapping “pod->place” and print it out.
print(optimal_positions)
Reload the problem.
warehouse = load_problem()
Calculate optimal mapping “pod->place” and print it.
optimal_positions = optimal_fixed.optimal_assignment(warehouse)
print(optimal_positions)
Reorder places by their optimal fixed positions before staring the system. And store this optimal initial state to a JSON file. It can differ from the original initial state.
utils.create_missing_directories_of_file(OPTIMAL_INITIAL_STATE_FILE)
with open(OPTIMAL_INITIAL_STATE_FILE, 'w') as outfile:
recorder.store_initial_state_to_json(warehouse, outfile)
Solve the system with fixed places staring with the optimal initial state.
solver = FixedPlaceSolver(warehouse)
solution = []
while not warehouse.finished():
place_id = solver.decide_new_place()
solution.append(place_id)
warehouse.next(place_id)
Print out the best solution and save it to a JSON file.
print("Total costs for optimal fixed solution and initial state: {} at time {}.".format(
warehouse.total_costs, warehouse.t))
# Save the results.
utils.create_missing_directories_of_file(OPTIMAL_SOLUTION_FILE)
with open(OPTIMAL_SOLUTION_FILE, 'w') as outfile:
recorder.store_solution_to_json(solution, outfile)