﻿ Integer Programs - How to force the solution to be in multiples of an integer?

# Integer Programs - How to force the solution to be in multiples of an integer?

So I'm trying to create this IP that has an optimal solution where all the variables are integers, and are all in multiples of a number, like 3. ( so the variables in the solution would have to be either 0,3,6,9,12,etc.)

I code in R, and it's pretty easy to set the constraint that the solution must be in integers (all.int = TRUE), but I am unsure of how to have it in a multiple of a number. What changes do I have to make within the Ax <= b formulation? Your help would be greatly appreciated! As of right now, I am fairly lost on how to actually do that

To do this, you can define some integer variable x and then define y = 3*x. Now y is integer and a multiple of 3.

For instance, consider a trivial IP that finds the maximum multiple of 3 that is less than or equal to 10 (of course, the main motivation here is to embed this within a more complicated integer program). You could do this with:

library(lpSolve)
mod <- lp(direction = "max",
objective.in = c(0, 1),  # (x, y)
const.mat = rbind(c(3, -1),  # 3x - y = 0
c(0, 1)),  # y <= 10
const.dir = c("=", "<="),
const.rhs = c(0, 10),
all.int = TRUE)
mod\$solution[2]
# [1] 9

As I understand it, your criterion is that the mod 3 of the answer is 0. If so, what about mod(intResult,3) == 0?

Since I don't write in your language, the above may not be valid R, but I think you will get the idea, since the above is valid C, assuming that mod is the name of a function that returns intResult modulo 3.