How to write an optimization program in Matlab for this specific case?

70 Views Asked by At

I have a machine with following characteristics:

(1) Every time machine runs there is a fixed charge of $50

(2) Once machine runs it must run for 4 hours at least. Machine can hence have multiple starts and stops. Machine can run entire time in a given period if it is profitable to do so. The given period can be hours, days or months, etc.

(3) When the machine is running it is producing revenue as following for 24 hours period:[5, 10, -5, 10, -6, -20, 5, 7, 5, 10, -5, 10, -6, -20, 5, 7, 5, 10, -5, 10, -6, -20, 5, 7] . Negative means if machine runs it will loose $$

(4) Revenue for next day is same as above. Machine can start at 11 PM and run for 4 hours i.e. until 3 am next day or longer.

(5) It might be economical to run the machine at negative revenue until next start instead of stopping and paying the start charge

(6) I can do this using a for loop but I am looking to use some optimization algorithm available in Matlab.

Edit: Yes it is tricky because of that. I have done it using for loop. Why a downvote on this problem?

1

There are 1 best solutions below

2
On

The real question here is: for how long to run the machine before you restart it. There are only 22 possibilities (stopping after 4 hour, after 5 hours, ..., after 24 hours, or running continuously). The easiest way is to enumerate all possibilities.

When the time horizon is limited to $T$ hours, this becomes a knapsack problem where the size of the knapsack is the number of available hours, where each potential item $i$ ($i=4,...,T$) has size $s_i = i$ and value $v_i = \sum_{j=1}^i p_{(j \mod 24)} - 50$ (with $p_j$ the given profit vector), and where you can include each item more than once.