0

I have a dataframe that consist of ids and an output column. Based on a given constraint I would like to find the optimum solution that maximizes output values. I believe this could be found using lpsolve?

library(dplyr)

df<-structure(list(Machine_Machine_Id = c(1, 2, 3, 4,5,6,7,8), Output = c(6,4,5,5,8,5,7,4),Group = c("Red","Blue","Blue","Purple","Green","Red",
   "Green","Purple")),row.names = c(NA, 8L), class = "data.frame")

###This is not the optimium solution but an example
df2<-df%>%
  arrange(desc(Output))%>%
  mutate(Start_Month=ceiling(row_number()/2))%>%
  ungroup()%>%
  group_by(Start_Month)%>%
  #Add Group Multiplier if Start_Month machines contain same Group Color
  mutate(Group_Multiplier=ifelse(max(dense_rank(Group))==1,1.1,.85))%>%
  ungroup()%>%
  mutate(Final_Output= Output*Group_Multiplier)

sum(df2$Final_Output)  

The Group Multipler column penalizes periods when there are two different machine colors in the same Start_Month and rewards by a factor of 1.1 when machines of the same color are in the same Start_Month. I'll have more penalization/reward columns but this is a basic example.

bretauv
  • 7,756
  • 2
  • 20
  • 57
jsimpsno
  • 448
  • 4
  • 19
  • 1
    You may want to write the mathematical model first. From your example description, I would say just pick the best one by running through the table once. Obviously, I am missing things here. – Erwin Kalvelagen Mar 01 '23 at 21:30

0 Answers0