Originally posted by: SystemAdmin
Yes, it must be explicitly added. Be careful here! The two statements
x[1] = y[2]
x[1] == y[2]
have very different semantics. The first statement assigns the IloNumVar object at slot 2 in array y to slot 1 in array x. Thereby it overwrites the IloNumVar object stored there. The statement manipulates the arrays in which you store the IloNumVar instances. It does not create any constraint.
The second statement uses the overloaded operator== to create an equality constraint that requires IloNumVar x[1] to be the same as IloNumVar x[2] in any feasible solution. This is what you need. You need to do
cplex.add(x[1] == y[2]);
#CPLEXOptimizers#DecisionOptimization