I have an optimization problem as below.
For $g\in G$, let $\mathcal{N}_g$ be the nodes in group $g$, and let binary variable $u_g$ indicate whether group $g$ is used. The problem has this following constraint
\begin{align} \sum_{g\in G:\ i\in N_g} u_g &= 1 &&\text{for all $i$} \end{align}
How can Model this in Cplex?
For example, G=10;
$\mathcal{N}_1={1,2}$
$\mathcal{N}_2={1,3,4}$
$\mathcal{N}_3={1,3,5}$
$\mathcal{N}_4={1,4,5,6}$
...
$\mathcal{N}_{10}={1,6,7,8}$
The only constraint says that every node must be chosen just once.
Here is what I tried so far
IloEnv env;
try{
IloNum G=10;
IloNumVarArray Ug(env, G,0,1,ILOINT)
IloModel model(env)
In order to make it efficient for implementation I do a reformulation. I generate a binary matrix,$B$ of size $N_{node}\times G$, where $N_{node}$ is the number of nodes. If node $n, n\in{1,2,\cdots,N_{node}}$ is present in group $g, g\in{1,2,\cdots,G}$, then $B_{n,g}=1$, otherwise 0.
IloExpr constFun(env)
Note: In Matlab, this constraint now can be expressed as
for n=1:N
sum(Ug(find(B(n,:)==1)))==1;
end