Using an external function that takes in a float input as part of the problem objective #779
Unanswered
TheRealWushuMaster
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, everyone!
I'm creating an optimizer which will find the optimal combination of items to package together. Each item has its own weight.
The objective is to minimize the total cost of transporting said packages. The cost function (let's call it
cost_function
) depends on the total weight of the items in a package; it uses afloat
as the input (the weight of the package, in kg) and returns anotherfloat
(the cost of transporting, in USD).I have set up binary LpVariables that determine whether each item is included on each package, called
x_i_j
. These variables reflect whether the item i is included in the package j, and are equal to 1 if item i is in package j, or 0 otherwise.The objective function needs to call
cost_function
to calculate the cost to use in the minimization problem. However, it's not possible to callcost_function
right away, as the LpVariables are notfloat
numbers, so I get an error similar to the following:The previous error happens when the function tries to compare the weight input within a range.
Any ideas on how to fix this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions