Evaluating a custom function when a solution is proposed by OR-TOOLS

84 views
Skip to first unread message

Víctor Martínez

unread,
Apr 26, 2021, 3:53:36 AM4/26/21
to or-tools-discuss
Hi, 

I am pretty new to OR-TOOLS in Python. I have made several tutorial examples, but I am facing issues trying to model my problem.

Let's see we have a bin packing problem, in which I need to find the fewest bins that will hold all the items in function of their weight. In this typical problem we would want to minimize the number of bins used. But let's say we have an additional objective: to maximize the "quality" of the bin. Here's the problem: to evaluate the quality of that bin, we need to call a non-linear function (or a function of other library) that takes the items in that bin and returns a quality. I guess I cannot use a multi-objective approach with CP/SAT, so we could model it weighting both objectives.

The problem I am facing is thus the following:

I cannot set the 'quality' as variable because it depends on the current solution (the items associated to a bin)

How can I do that? assigning a callback? is it possible?

Priidik Vilumaa

unread,
Apr 26, 2021, 1:29:41 PM4/26/21
to or-tools-discuss
Hello,

I don't think callbacks can "modify the search". 

Imo the way to go is to approximate the quality as a linear/"manageable" function.

A non-scalable hack is to calculate the quality for each possible combination of items and add that to the coefficient of the corresponding combination variable. For example:
- Items x1, x3, x5 together have a quality of 8. 
- Define y1,3,5 as x1 AND x3 AND x5 -> y1,3,5.
- Add 8 * y1,3,5 to the objective

Best,
Priidik

Víctor Martínez

unread,
Apr 27, 2021, 10:34:38 AM4/27/21
to or-tools-discuss
Thank you for the response.

However, I am afraid I cannot calculate the ''quality'' of each possible combination :(

Priidik Vilumaa

unread,
Apr 27, 2021, 11:26:36 AM4/27/21
to or-tools...@googlegroups.com
If you provide an example quality function then perhaps someone will be able to linearize etc

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/e59ac9f5-4013-4972-8105-3d41739c2889n%40googlegroups.com.

Víctor Martínez

unread,
Apr 27, 2021, 11:35:55 AM4/27/21
to or-tools-discuss
I've tried to simplify the problem to know just if it was possible to use a callback.

I've just created another question stating the real problem, which is a combination of Bin packing + VRP here: https://groups.google.com/g/or-tools-discuss/c/UcxqaZNywJk

Thanks!

Laurent Perron

unread,
Apr 27, 2021, 1:04:29 PM4/27/21
to or-tools-discuss
Callbacks are not possible. The model  needs to be closed.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Reply all
Reply to author
Forward
0 new messages