Jungle Cemal
Jungle Cemal

Reputation: 1

Google OR Tools, "returned a result with an exception set" Error on my server

I am using ORTools for path optimization. When I try my code in localhost it returns the expected result. However, when I try it on my DigitalOcean App it gives an error message:" returned a result with an exception set". Can anyone help me to find a solution ?

Here is the TraceBack code from Postman if it is useful:

The above exception ('numpy.float64' object cannot be interpreted as an integer) was the direct cause of the following exception:

Local vars /workspace/.heroku/python/lib/python3.10/site-packages/ortools/constraint_solver/pywrapcp.py, line 5730, in GetArcCostForVehicle

    return _pywrapcp.RoutingModel_CostVar(self)
def GetArcCostForVehicle(self, from_index: "int64_t", to_index: "int64_t", vehicle: "int64_t") -> "int64_t":
    r"""
    Returns the cost of the transit arc between two nodes for a given vehicle.
    Input are variable indices of node. This returns 0 if vehicle < 0.
    """
    return _pywrapcp.RoutingModel_GetArcCostForVehicle(self, from_index, to_index, vehicle) …

Upvotes: 0

Views: 823

Answers (1)

Mizux
Mizux

Reputation: 9301

Please check that all your transit callbacks are returning an int type.

In your code you must have registered a transit callback:

# Create and register a transit callback.
def distance_callback(from_index, to_index):
    """Returns the distance between the two nodes."""
    # Convert from routing variable Index to distance matrix NodeIndex.
    from_node = manager.IndexToNode(from_index)
    to_node = manager.IndexToNode(to_index)
    return data['distance_matrix'][from_node][to_node]

transit_callback_index = routing.RegisterTransitCallback(distance_callback)

then you have passed this transit_callback_index to setup the arc cost evaluator function.

# Define cost of each arc.
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)

The point is, the function distance_callback() will be call internally by the C++ library (python is just a wrapper on top of the C++ library). The C++ expect a C++ int64_t returned by the distance_callback() wrapper function (i.e. the python-C++ bridge need an int from the python method to be able to convert it to a C++ int64_t).

If your method return a numpy.float64 (e.g. because you r distance matrix data are an numpy array full of floating point values) then everything blow up thus the error message...

Upvotes: 1

Related Questions