How to define the objective function in a memory allocation optimization problem?

66 views
Skip to first unread message

Hans den Boer

unread,
Mar 19, 2013, 12:41:12 PM3/19/13
to or-tools...@googlegroups.com
I am working on a memory allocation optimization problem, i.e., allocation of a number of sized buffers in an amount of memory that is not enough to accommodate all buffers concurrently. The swapping in and out of buffers has an associated cost, so obviously, swapping needs to be minimized.

To model the cost function as an objective function, I need to establish whether two buffers are overlapping. If they do, the cost value returned may be something like a fixed value, let's say 28. If they don't the cost is 0.

I thought to model this in Python as follows:

cost = solver.ConditionalValue(x1 >= x0 + size0 or x0 >= x1 + size1, 0, 28)
objective = solver.Minimize(cost, 1) 

Of course this doesn't work as the ConditionalValue member function does not exist.

What is good practice to address a problem like this?

Laurent Perron

unread,
Mar 19, 2013, 2:31:05 PM3/19/13
to or-tools-discuss
cost = solver.IsBetweenVar(x1 - x0, size0, -size1) * 28;  
using very fresh code from svn.

Please verify size0 and -size1.

--Laurent


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--Laurent

Laurent Perron

unread,
Mar 19, 2013, 4:13:23 PM3/19/13
to or-tools-discuss
or perhaps more accurately

isBetweenVar(x1 - x0, 1 -size1, size0 - 1)

Please double check.


--
--Laurent

Hans den Boer

unread,
Mar 22, 2013, 5:35:54 AM3/22/13
to or-tools...@googlegroups.com
Yes, that helps. And indeed, isBetweenVar(x1 - x0, 1 -size1, size0 - 1) is the accurate translation of the C equivalent (x1 >= x0 + size0 || x0 >= x1 + size1 ? 1 : 0).
I updated to the last SVN revision, rebuilt (make all), regenerated the python package (make python_archive), and installed the python egg (sudo python setup.py install). Then I was able to use the new API.
Nice.

Laurent Perron

unread,
Mar 22, 2013, 5:37:25 AM3/22/13
to or-tools-discuss
Fantastic!

Thanks


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--Laurent

Reply all
Reply to author
Forward
0 new messages