Using the DecisionAI Model#

This section demonstrates how to use the DecisionAI model, i.e., instantiate the model, and solve it.

Solving the Model#

We assume that we have implemented a decision_ai.PulpDecisionAIModel class and the input data class. As an example, we will use the decision_ai.examples.StaffSchedulingModel class from the Staff Scheduling.

The decision_ai.examples.StaffSchedulingModel class is responsible for setting up and solving the optimization problem. Before solving, you must formulate the problem using the decision_ai.PulpDecisionAIModel.formulate() method, which prepares the problem with the input data.

To solve the model, you need to create an instance of decision_ai.examples.StaffSchedulingModel, formulate the problem with the input data, and then call the solver.

from decision_ai.examples import StaffSchedulingModel, StaffSchedulingInput

# Load input data
input_data = StaffSchedulingInput.from_csvs("path/to/csvs")
# or for example purposes
# input_data = StaffSchedulingInput.load_example()

# Initialize the model
model = StaffSchedulingModel()

# Formulate the problem
variables, prob, _ = model.formulate(input_data)

# Solve the model
solution = model.solve(prob, variables, input_data)

Interpreting the Solution#

Once the model is solved, you can interpret the results using the decision_ai.examples.StaffSchedulingModel.solution_to_str() method. This method provides a human-readable summary of the solution, including the objective value, status, and assignments.

# Convert solution to a readable format
solution_str = model.solution_to_str(input_data, solution)

# Print the solution
print(solution_str)

The decision_ai.examples.StaffSchedulingModel.solution_to_str() method outputs the objective value, the status of the solution, and the assignments of employees to shifts. If the solution is infeasible, it will indicate this in the status.