0

I have a Matlab program that outputs some binary variables based on some constraints.

As an example with three n=3 bits, {x_1 x_2 x_3, x_4 x_5 x_6, x_7 x_8 x_9} my program will output all these bits based on the constraints.

At this point, I have no objective function.

However, the goal of the objective function is to minimize the total Hamming distance (HD) between some of the n bits pairs.

Say I want to minimize HD (x_1 x_2 x_3 vs x_4 x_5 x_6) + (x_1 x_2 x_3 vs x_7 x_8 x_9)

Needless to say, n can vary as can the number of pairs compared for HD.

How do I perform this with intlinprog? I am not finding this helpful. A little bit of direction would do. Do I need to change my A,b,Aeq,etc?

1 Answers1

0

There may be better implementations for this type of objective, but I like to go back to basics to understand what is going on. A simple approach is to think about what the Hamming distance means for a pair of binary variables. The Hamming distance will be zero if the variables have the same value (0 and 0, or 1 and 1), and the Hamming distance will be 1 if the variables don't have the same value.

Assume you have two binary variables v1 and v2. Create another variable Z and add constraints:

Z >= V1 - V2 
Z >= V2 - V1

Now Z must be greater than or equal to the Hamming distance between V1 and V2. So if we minimise Z we will minimise the Hamming distance. The generalisation to multiple pairs of variables is obvious - create a variable like Z for all pairs of variables like V1 and V2, and then minimise the sum of those Z variables.

TimChippingtonDerrick
  • 2,042
  • 1
  • 12
  • 13
  • Thank you. Do you think this could be possible without adding any more variables? –  Nov 06 '20 at 16:21