在JuMP / Gurobi中添加OR约束

时间:2020-07-22 22:01:45

标签: julia gurobi julia-jump

我正在尝试向模型添加约束,以将变量约束为集合中的值之一,即,将X约束为0或3或4。

当前代码如下:

@addConstraint(m, x==0 or x==3 or x==4)

但是我想做类似的事情:

# MY FLOW
monthly_qty_by_cat2 <- 
  sweep::bike_sales %>%
  mutate(order.month = yearmonth(order.date)) %>%
  group_by(category.secondary, order.month) %>%
  summarise(total.qty = sum(quantity), price.m = mean(price)) %>% 
  as_tsibble(index=order.month, key=category.secondary) # coerse in tsibble
# mean for the future
futuro <- monthly_qty_by_cat2 %>% 
  group_by(category.secondary) %>% 
  mutate(fut_x = mean(price.m)) %>% 
  do(price.m = head(.$fut_x,1))
# as.numeric
futuro$price.m <- as.numeric(futuro$price.m)
futuro
# make values in the future
future_x <- new_data(monthly_qty_by_cat2, 3) %>%
  left_join(futuro, by = "category.secondary")
future_x

# model and forecast
fc <- monthly_qty_by_cat2 %>% 
  group_by(category.secondary) %>% 
  model(ARIMA(total.qty ~ price.m))  %>%
  forecast(new_data=future_x)  %>% 
  hilo(level = 95) %>% 
  unpack_hilo("95%")
fc

# Tidy the forecast
fc_tibble <- fc %>%  as_tibble() %>% select(-total.qty)
fc_tibble
# the end

在朱莉娅这可能吗?使用JuMP作为求解器。

1 个答案:

答案 0 :(得分:2)

将帮助程序变量h3h4定义为二进制,然后设置约束:x = 3*h3 + 4*h4h3 + h4 <= 1

相关问题