{"action":"created","issue":{"url":"https://api.github.com/repos/dirkschumacher/ompr/issues/229","repository_url":"https://api.github.com/repos/dirkschumacher/ompr","labels_url":"https://api.github.com/repos/dirkschumacher/ompr/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/dirkschumacher/ompr/issues/229/comments","events_url":"https://api.github.com/repos/dirkschumacher/ompr/issues/229/events","html_url":"https://github.com/dirkschumacher/ompr/issues/229","id":362398216,"node_id":"MDU6SXNzdWUzNjIzOTgyMTY=","number":229,"title":"Error message in MILPModel","user":{"login":"Krut11","id":43456105,"node_id":"MDQ6VXNlcjQzNDU2MTA1","avatar_url":"https://avatars0.githubusercontent.com/u/43456105?v=4","gravatar_id":"","url":"https://api.github.com/users/Krut11","html_url":"https://github.com/Krut11","followers_url":"https://api.github.com/users/Krut11/followers","following_url":"https://api.github.com/users/Krut11/following{/other_user}","gists_url":"https://api.github.com/users/Krut11/gists{/gist_id}","starred_url":"https://api.github.com/users/Krut11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Krut11/subscriptions","organizations_url":"https://api.github.com/users/Krut11/orgs","repos_url":"https://api.github.com/users/Krut11/repos","events_url":"https://api.github.com/users/Krut11/events{/privacy}","received_events_url":"https://api.github.com/users/Krut11/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-20T23:01:16Z","updated_at":"2018-09-21T15:06:56Z","closed_at":null,"author_association":"NONE","body":"Hi Dirk,\r\n\r\nThank you for a great package. Been most useful.\r\n\r\nI'm experiencing some trouble, when using the MILPModel instead of MIP.\r\n\r\nThe following model works fine with MIP, but in the MILP version an error message on the objective function:\r\n\"Error in DistanceMatrix[p, j] * h[p, j, v, t] : non-numeric argument to binary operator\"\r\n\r\nPart of code:\r\n`Model <- MILPModel() %>%`\r\n  \r\n```\r\n# we create a variable that is 1 if we travel from station p to j with v in t\r\nadd_variable(h[p, j, v, t], p = 1:P, j = 1:P, v = 1:V, t = 1:T, type = \"integer\", lb = 0, ub = 1) %>%\r\n```\r\n  \r\n```\r\n# minimize travel distance (Object function)\r\nset_objective(sum_expr(DistanceMatrix[p, j] * h[p, j, v, t], p = 1:P, j = 1:P, v = 1:V,  t = 1:T), \"min\")\r\n```\r\n\r\nDistanceMatrix is numeric and there are no issues, when running the above in a MIPModel. I have tried using the colwise() function, but this did not correct the error. Do you have any suggestions?\r\n\r\nThanks in advance..\r\n/Kristian\r\n"},"comment":{"url":"https://api.github.com/repos/dirkschumacher/ompr/issues/comments/423565616","html_url":"https://github.com/dirkschumacher/ompr/issues/229#issuecomment-423565616","issue_url":"https://api.github.com/repos/dirkschumacher/ompr/issues/229","id":423565616,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzU2NTYxNg==","user":{"login":"hugolarzabal","id":40272209,"node_id":"MDQ6VXNlcjQwMjcyMjA5","avatar_url":"https://avatars2.githubusercontent.com/u/40272209?v=4","gravatar_id":"","url":"https://api.github.com/users/hugolarzabal","html_url":"https://github.com/hugolarzabal","followers_url":"https://api.github.com/users/hugolarzabal/followers","following_url":"https://api.github.com/users/hugolarzabal/following{/other_user}","gists_url":"https://api.github.com/users/hugolarzabal/gists{/gist_id}","starred_url":"https://api.github.com/users/hugolarzabal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugolarzabal/subscriptions","organizations_url":"https://api.github.com/users/hugolarzabal/orgs","repos_url":"https://api.github.com/users/hugolarzabal/repos","events_url":"https://api.github.com/users/hugolarzabal/events{/privacy}","received_events_url":"https://api.github.com/users/hugolarzabal/received_events","type":"User","site_admin":false},"created_at":"2018-09-21T15:06:56Z","updated_at":"2018-09-21T15:06:56Z","author_association":"CONTRIBUTOR","body":"I think that something like that should work:\r\n```\r\nmatrix_fun <- function(i,j){\r\n  \r\n  result <- c()\r\n  for (i1 in i){\r\n    for (j1 in j)\r\n      result <- c(result, DistanceMatrix[i1,j1])\r\n  }\r\n  return(result)\r\n  \r\n}\r\n\r\ndistance_fun <- function(p, j, v, t) {\r\n  \r\n  df_Distance <- expand.grid(p=p,j=j,v=v,t=t)\r\n  \r\n  colwise(matrix_fun(df_Distance$p,df_Distance$j))\r\n  \r\n}\r\n```\r\nThen you should write your objective like that:\r\n`set_objective(sum_expr(distance_fun(1:P, 1:P, 1:V, 1:T) * h[p, j, v, t], p = 1:P, j = 1:P, v = 1:V,  t = 1:T), \"min\")`\r\n"}}
{"actor":{"display_login":"hugolarzabal"}}