Maximize profit with dynamic programming

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have 3 tables…



$$beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 200 \
2 & 200 & 450 \
3 & 300 & 700 \
4 & 400 & 1000
endarray
qquad
beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 220 \
2 & 200 & 480 \
3 & 300 & 800 \
endarray
qquad
(cdots)$$



All equal structure but with different values and different number of rows.



I want to write a recursive function describing the optimal choices of quantities in order to maximize my profit.



I have a given amount to spend and the total expenses can't exceed this.



Besides, I use the notation that $p_nj$ should the profit in table $n$ and quantity $j$ and $c_nj$ should express the cost of choosing quantity $j$ in table $n$.



I think it's something like



$$
f_n(A) = textmax left[p_nj + f_n+1left(A-c_njright)right]
$$
where $A$ is the amount I can invest.



My intuition is that I'm adding the profit $p_nj$ for each iteration and subtracting the cost from the total available amount ($A-c_nj$).



I don't think it's correct but I guess it's something like that. How can I iterate through all the three different tables with recursion?










share|cite|improve this question























  • This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
    – AlexR
    Mar 27 '15 at 13:18










  • I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
    – Jamgreen
    Mar 28 '15 at 14:19














up vote
0
down vote

favorite












I have 3 tables…



$$beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 200 \
2 & 200 & 450 \
3 & 300 & 700 \
4 & 400 & 1000
endarray
qquad
beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 220 \
2 & 200 & 480 \
3 & 300 & 800 \
endarray
qquad
(cdots)$$



All equal structure but with different values and different number of rows.



I want to write a recursive function describing the optimal choices of quantities in order to maximize my profit.



I have a given amount to spend and the total expenses can't exceed this.



Besides, I use the notation that $p_nj$ should the profit in table $n$ and quantity $j$ and $c_nj$ should express the cost of choosing quantity $j$ in table $n$.



I think it's something like



$$
f_n(A) = textmax left[p_nj + f_n+1left(A-c_njright)right]
$$
where $A$ is the amount I can invest.



My intuition is that I'm adding the profit $p_nj$ for each iteration and subtracting the cost from the total available amount ($A-c_nj$).



I don't think it's correct but I guess it's something like that. How can I iterate through all the three different tables with recursion?










share|cite|improve this question























  • This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
    – AlexR
    Mar 27 '15 at 13:18










  • I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
    – Jamgreen
    Mar 28 '15 at 14:19












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have 3 tables…



$$beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 200 \
2 & 200 & 450 \
3 & 300 & 700 \
4 & 400 & 1000
endarray
qquad
beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 220 \
2 & 200 & 480 \
3 & 300 & 800 \
endarray
qquad
(cdots)$$



All equal structure but with different values and different number of rows.



I want to write a recursive function describing the optimal choices of quantities in order to maximize my profit.



I have a given amount to spend and the total expenses can't exceed this.



Besides, I use the notation that $p_nj$ should the profit in table $n$ and quantity $j$ and $c_nj$ should express the cost of choosing quantity $j$ in table $n$.



I think it's something like



$$
f_n(A) = textmax left[p_nj + f_n+1left(A-c_njright)right]
$$
where $A$ is the amount I can invest.



My intuition is that I'm adding the profit $p_nj$ for each iteration and subtracting the cost from the total available amount ($A-c_nj$).



I don't think it's correct but I guess it's something like that. How can I iterate through all the three different tables with recursion?










share|cite|improve this question















I have 3 tables…



$$beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 200 \
2 & 200 & 450 \
3 & 300 & 700 \
4 & 400 & 1000
endarray
qquad
beginarrayrrr
textquantity & textexpense & textprofit\
hline
0 & 0 & 0 \
1 & 100 & 220 \
2 & 200 & 480 \
3 & 300 & 800 \
endarray
qquad
(cdots)$$



All equal structure but with different values and different number of rows.



I want to write a recursive function describing the optimal choices of quantities in order to maximize my profit.



I have a given amount to spend and the total expenses can't exceed this.



Besides, I use the notation that $p_nj$ should the profit in table $n$ and quantity $j$ and $c_nj$ should express the cost of choosing quantity $j$ in table $n$.



I think it's something like



$$
f_n(A) = textmax left[p_nj + f_n+1left(A-c_njright)right]
$$
where $A$ is the amount I can invest.



My intuition is that I'm adding the profit $p_nj$ for each iteration and subtracting the cost from the total available amount ($A-c_nj$).



I don't think it's correct but I guess it's something like that. How can I iterate through all the three different tables with recursion?







optimization recursive-algorithms recursion dynamic-programming






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Mar 29 '15 at 9:58

























asked Mar 27 '15 at 13:00









Jamgreen

4141310




4141310











  • This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
    – AlexR
    Mar 27 '15 at 13:18










  • I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
    – Jamgreen
    Mar 28 '15 at 14:19
















  • This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
    – AlexR
    Mar 27 '15 at 13:18










  • I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
    – Jamgreen
    Mar 28 '15 at 14:19















This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
– AlexR
Mar 27 '15 at 13:18




This is a simplified version of portfolio optimization. The model you describe doesn't use the tables themselves, so you can put everything into one single table.
– AlexR
Mar 27 '15 at 13:18












I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
– Jamgreen
Mar 28 '15 at 14:19




I've read about portfolio optimization but I'm still unsure if my recursive formula is correct
– Jamgreen
Mar 28 '15 at 14:19










1 Answer
1






active

oldest

votes

















up vote
0
down vote













If $f_n(A)$ gives the maximum profit from taking at most $n$ objects and at most $A$ cost, the maximum profit for at most $n+1$ objects costing at most $A$ must be
$$f_n+1(A) = max_j p_j + f_n(A-c_j) mid c_j le A cup 0$$
Note that we



  • Maximize over all objects that we could chose. If we can't chose any object within budget, the maximum profit is obtained by chosing nothing ($0$).

  • Constrain the objects we try to add to only those objects still within budget.

  • $f_n+1(A)$ depends on $f_n(A)$, not the other way around.

  • $f_0(A) = 0$ for any $A$, since no objects equals no profit.





share|cite|improve this answer




















  • Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
    – Jamgreen
    Mar 28 '15 at 15:34











  • I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
    – Jamgreen
    Mar 29 '15 at 7:17










  • @Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
    – AlexR
    Mar 29 '15 at 9:53










  • Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
    – Jamgreen
    Mar 29 '15 at 9:56










  • @Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
    – AlexR
    Mar 29 '15 at 10:22










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1208906%2fmaximize-profit-with-dynamic-programming%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













If $f_n(A)$ gives the maximum profit from taking at most $n$ objects and at most $A$ cost, the maximum profit for at most $n+1$ objects costing at most $A$ must be
$$f_n+1(A) = max_j p_j + f_n(A-c_j) mid c_j le A cup 0$$
Note that we



  • Maximize over all objects that we could chose. If we can't chose any object within budget, the maximum profit is obtained by chosing nothing ($0$).

  • Constrain the objects we try to add to only those objects still within budget.

  • $f_n+1(A)$ depends on $f_n(A)$, not the other way around.

  • $f_0(A) = 0$ for any $A$, since no objects equals no profit.





share|cite|improve this answer




















  • Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
    – Jamgreen
    Mar 28 '15 at 15:34











  • I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
    – Jamgreen
    Mar 29 '15 at 7:17










  • @Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
    – AlexR
    Mar 29 '15 at 9:53










  • Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
    – Jamgreen
    Mar 29 '15 at 9:56










  • @Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
    – AlexR
    Mar 29 '15 at 10:22














up vote
0
down vote













If $f_n(A)$ gives the maximum profit from taking at most $n$ objects and at most $A$ cost, the maximum profit for at most $n+1$ objects costing at most $A$ must be
$$f_n+1(A) = max_j p_j + f_n(A-c_j) mid c_j le A cup 0$$
Note that we



  • Maximize over all objects that we could chose. If we can't chose any object within budget, the maximum profit is obtained by chosing nothing ($0$).

  • Constrain the objects we try to add to only those objects still within budget.

  • $f_n+1(A)$ depends on $f_n(A)$, not the other way around.

  • $f_0(A) = 0$ for any $A$, since no objects equals no profit.





share|cite|improve this answer




















  • Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
    – Jamgreen
    Mar 28 '15 at 15:34











  • I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
    – Jamgreen
    Mar 29 '15 at 7:17










  • @Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
    – AlexR
    Mar 29 '15 at 9:53










  • Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
    – Jamgreen
    Mar 29 '15 at 9:56










  • @Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
    – AlexR
    Mar 29 '15 at 10:22












up vote
0
down vote










up vote
0
down vote









If $f_n(A)$ gives the maximum profit from taking at most $n$ objects and at most $A$ cost, the maximum profit for at most $n+1$ objects costing at most $A$ must be
$$f_n+1(A) = max_j p_j + f_n(A-c_j) mid c_j le A cup 0$$
Note that we



  • Maximize over all objects that we could chose. If we can't chose any object within budget, the maximum profit is obtained by chosing nothing ($0$).

  • Constrain the objects we try to add to only those objects still within budget.

  • $f_n+1(A)$ depends on $f_n(A)$, not the other way around.

  • $f_0(A) = 0$ for any $A$, since no objects equals no profit.





share|cite|improve this answer












If $f_n(A)$ gives the maximum profit from taking at most $n$ objects and at most $A$ cost, the maximum profit for at most $n+1$ objects costing at most $A$ must be
$$f_n+1(A) = max_j p_j + f_n(A-c_j) mid c_j le A cup 0$$
Note that we



  • Maximize over all objects that we could chose. If we can't chose any object within budget, the maximum profit is obtained by chosing nothing ($0$).

  • Constrain the objects we try to add to only those objects still within budget.

  • $f_n+1(A)$ depends on $f_n(A)$, not the other way around.

  • $f_0(A) = 0$ for any $A$, since no objects equals no profit.






share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Mar 28 '15 at 14:51









AlexR

22.5k12348




22.5k12348











  • Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
    – Jamgreen
    Mar 28 '15 at 15:34











  • I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
    – Jamgreen
    Mar 29 '15 at 7:17










  • @Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
    – AlexR
    Mar 29 '15 at 9:53










  • Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
    – Jamgreen
    Mar 29 '15 at 9:56










  • @Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
    – AlexR
    Mar 29 '15 at 10:22
















  • Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
    – Jamgreen
    Mar 28 '15 at 15:34











  • I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
    – Jamgreen
    Mar 29 '15 at 7:17










  • @Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
    – AlexR
    Mar 29 '15 at 9:53










  • Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
    – Jamgreen
    Mar 29 '15 at 9:56










  • @Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
    – AlexR
    Mar 29 '15 at 10:22















Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
– Jamgreen
Mar 28 '15 at 15:34





Thank you! But will this work if I have three tables with different quantities (yielding different profits) for each type of investment and I want to find the best combination of quantities between those three different types of investment? Can I just change $p_j$ to $p_ij$ and $c_j$ to $c_ij$ where $i$ denotes the investment type? Besides, my homework says that it can be helpful if I let $T_i$ denote the set of possible quantities for each investment type (e.g. $T_2 = 0,1,2,3,4,5$) but I don't know how this is useful.
– Jamgreen
Mar 28 '15 at 15:34













I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
– Jamgreen
Mar 29 '15 at 7:17




I guess I will need a second term in the function $f_n+1(A)$. Maybe it's $f_n+1(A,i) = textmax p_ij + f_n(A-c_ij,i-1)$?
– Jamgreen
Mar 29 '15 at 7:17












@Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
– AlexR
Mar 29 '15 at 9:53




@Jamgreen As I noted, the optimization itself doesn't really care about the investment, so you can treat $p_ij$ as $p_hat j$ for a renumbered Table containing all three other tables. The set $T$ you mention is basically what the $max$ is computed over.
– AlexR
Mar 29 '15 at 9:53












Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
– Jamgreen
Mar 29 '15 at 9:56




Oh okay :-) But without denoting the investment type, how can I tell how many objects the firm should invest in each investment type?
– Jamgreen
Mar 29 '15 at 9:56












@Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
– AlexR
Mar 29 '15 at 10:22




@Jamgreen The index $hat j$ contains the same information as the pair $(i,j)$.
– AlexR
Mar 29 '15 at 10:22

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1208906%2fmaximize-profit-with-dynamic-programming%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards