Conditional mathematical optimization in R

你离开我真会死。 提交于 2019-12-13 06:08:47

问题


I have the following data frames:

Required <- data.table( Country=c("AT Iron", "AT Energy", "BE Iron", "BE Energy", "BG Iron", "BG Energy"),Prod1=c(5,10,0,5,0,5),Prod2=c(25,5,10,0,0,5))
Supplied <- data.table( Country=c("AT Iron", "AT Energy", "BE Iron", "BE Energy", "BG Iron", "BG Energy"),Prod1=c(10,5,5,10,5,10),Prod2=c(20,20,20,0,15,10))


> Required
     Country Prod1 Prod2
1:   AT Iron     5    25
2: AT Energy    10     5
3:   BE Iron     0    10
4: BE Energy     5     0
5:   BG Iron     0     0
6: BG Energy     5     5

> Supplied
     Country Prod1 Prod2
1:   AT Iron    10    20
2: AT Energy     5    20
3:   BE Iron     5    20
4: BE Energy    10     0
5:   BG Iron     5    15
6: BG Energy    10    10

"Required" shows the initial material and energy requirements to manufacture two products, and the materials and energy are supplied by three different countries. For example, product 1 would require, for Energy, 10 units from AT, 5 units from BE and 5 units from BG. "Supplied" shows the actual supply capacity of the countries. Following the example, AT cannot supply 10 units of energy but 5 units, so another country must supply the remaining units. I assume that the country with the most net supply capacity (that is, once discounted the initial requirement) will provide the remaining units. In this case, both BE and BG have 5 units of net supply capacity, so both will provide with equal units, 2.5.

I seek an optimization algorithm that creates a new "Required" table, "RequiredNew", considering supply constrains and the above mentioned assumption. The resulting table should look like:

> RequiredNew
     Country Prod1 Prod2
1:   AT Iron     5    20
2: AT Energy    10     5
3:   BE Iron     0    10
4: BE Energy   7.5     0
5:   BG Iron     0     5
6: BG Energy   7.5     5

In the link below I posted a similar question which was solved by user digEmAll, so a similar approach would be suitable. However, I rephrased the question so that it becomes clearer and resembles more to my actual data.

Mathematical optimization in R

I apologise by the multiple posts. Thank you in advance.

来源:https://stackoverflow.com/questions/31938512/conditional-mathematical-optimization-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!