# How to model an ''affinity constraint'' in assignment problem

Working on an optimization problem formulated using the well known assignment problem. My decision variable is defined as follows :

$$\alpha _{x}^{r,u} = 1\begin{cases} & \text{ 1 if } \mathbf{VM}\: \mathbf{u}\; of\; request \: \boldsymbol{r}\; is\; assigned\; to\; server\; \mathbf{x}\\ & \text{ 0 } otherwise \end{cases} \\\\$$ $$V_{r}\; is\; the\; of\; VMs,\; V_{p}\; is\; the\; of\; servers, R\;is\;the\;set\;of\;requests$$

The complete model is defined as wit the relevant constraints : $$Min \sum_{r}\sum_{x}\sum_{u} Cost(u,x)\ast \alpha _{x}^{r,u}$$ $Subjet\;to$ $$\sum_{x}\alpha _{x}^{r,u} = 1\; \; \; \; \; \; \; \; \; \; \; \; \; \forall u\in V_{r},\forall r\in R \;\;\;\;\;\;\;\;\;\;(1)$$ $$\alpha _{x}^{r,u} \in [0,1]\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;(2)$$

A request r is composed of a set of VMs and for some reasons (security, performance, reliability) some VMs of a request r has to be put together within the same server if the resources are available, I define this as affinity constraint. Mathematically, I defined it as : $$\sum_{u}\alpha _{x}^{r,u} = Cardinality(\varphi^{r})\; \; \; \; \; \; \; \; \; \; \; \; \; \forall x\in V_{p},\forall r\in V_{r},\forall u\in \varphi^{r} , \varphi^{r}\subseteq V_{r}$$ I implemented the constraint within my model using Gurobi but the model is infeasible and I am wondering why it does not work wether it is related to the way I formulated it or other reason I am not aware of.

Another way to define the affinity constraint might be using the form of if A then B in the following way : If a given VM $u$ belonging to the affinity set say AffinitySet={VM1, VM2, VM3} then all the VMs within that set has to be put within the server x. However, I am not sure how to model this constraint mathematically.

Will appreciate any help, thanks.

• Please edit the question to make it self-contained, so we don't have to click on a link to understand what you've tried. You can edit the question to embed the image, or better yet, you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction.
– D.W.
Feb 7, 2018 at 19:09
• I suggest you try working through a small example by hand. Pick a small example of your problem with just one or two requests and one or two servers, where Gurobi says infeasible but you know a solution is possible. Try writing out the values of the decision variables corresponding to the known solution, and check each equation by hand to see whether it is satisfied. Probably that will be enough to enable you to find what's went wrong.
– D.W.
Feb 7, 2018 at 19:10
• "If A then B" can be expressed using the methods in cs.stackexchange.com/q/12102/755
– D.W.
Feb 7, 2018 at 19:11
• @D.W. I edited the post as you suggested, thank you ! The thing is that Gurobi says that the model is infeasible and after computing the IIS it seems that the constraint related to afiinity is conflicting with constraint (1), any clues ? Feb 16, 2018 at 16:02