Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble reproducing the exact qubo equation #14

Open
gYunTian opened this issue Jul 14, 2021 · 1 comment
Open

Trouble reproducing the exact qubo equation #14

gYunTian opened this issue Jul 14, 2021 · 1 comment

Comments

@gYunTian
Copy link

gYunTian commented Jul 14, 2021

I refer to both the hard shift and soft nurse constraint.

In doing my algebra, I wasn't able to reproduce the exact equation found in the documentations for both constraints.
I think I may have gotten rusty at my high school math but please look at the following and enlighten me:

Mine: Expanding the following equation and removing the constant:

    lagrange_hard_shift * sum_d ( effort * sum_n q_i(n,d) - workforce ) ** 2

gives me the following:

    lagrange_hard_shift * effort ** 2 * sum_d sum_m sum_n q_i(n,d) q_j(m, d)   (Similar)
    - 2 * lagrange_hard_shift * sum_d sum_n q_i(n,d) * effort * workforce   (Different)

Documentation: Notice the (Different) parts - above vs the bottom one:

    lagrange_hard_shift * (effort ** 2 - 2 effort * workforce) * sum_d sum_n q_i(n,d)   (Different)
    + lagrange_hard_shift * effort ** 2 * sum_d sum_m sum_n q_i(n,d) q_j(m, d)    (Similar)

There is an additional effort **2 among other things. Can someone please kindly explain the differences?
Thanks

@hhtong
Copy link
Contributor

hhtong commented Jul 15, 2021

Hi @gYunTian,

Here's a response from @amahmudwave and @pierrelouisp:

When expanding:

lagrange_hard_shift * sum_d ( effort * sum_n q_i(n,d) - workforce ) ** 2

We get:

lagrange_hard_shift * effort ** 2 * sum_d sum_m sum_n q_i(n,d) q_j(m, d) - 2 * lagrange_hard_shift * sum_d sum_n q_i(n,d) * effort * workforce   (Your answer)
  +  lagrange_hard_shift * (effort ** 2 * sum_d sum_n q_i(n,d))

This is because

(sum_n q_i(n,d))** 2 == sum_n q_i(n,d)**2  + sum_m sum_n q_i(n,d) q_j(m, d) == sum_n q_i(n,d)  + sum_m sum_n q_i(n,d) q_j(m, d)

When we take the summation of binary variables and square them, we get the sum of the different variables multiplied with each other, plus the sum of the square of individual variables. ie. (a + b)**2 == (a**2 + b**2 + 2ab).

The sum of the square of individual variables is equal to the sum of the original binary variables, since 0 ** 2 = 0 and 1 ** 2 = 1.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants