โ Solutions & Responses
When you ask Qaekwy to solve a problem, it will give you a response. This response tells you if it found a solution, and if so, what it is.
The SolutionResponse
When you solve a model, you get a SolutionResponse
object. Here’s how to work with it:
# Ask the engine to solve the model
solution_response = engine.model(modeller)
# First, check if the request was successful
if solution_response and solution_response.is_status_ok():
# Get the list of solutions
solutions = solution_response.get_solutions()
if solutions:
# Loop through the solutions
for sol in solutions:
print(f"Hooray, I found a solution! ๐ฅณ {sol}")
else:
print("No solution found. ๐ข")
else:
# If something went wrong, print the error message
print(f"Oh no, something went wrong! ๐ฑ {solution_response.get_message()}")
The Solution
Object
Each solution is a Solution
object. It’s a dictionary-like object that holds the values of the variables in the solution. You can access the values of the variables as attributes of the object.
# Assuming 'sol' is a Solution object and your model has variables "x" and "y"
print(f"The value of x is {sol.x}")
print(f"The value of y is {sol.y}")
Other Response Types
Qaekwy has other types of responses for other situations, such as:
EchoResponse
: Forecho
requests.VersionResponse
: Forversion
requests.
All responses have the following methods:
get_status()
: Tells you the status of the response (e.g., “Ok”, “Error”).is_status_ok()
: ReturnsTrue
if everything went well.get_message()
: Gives you a message from the solver.get_content()
: The actual data of the response.