How to linearize the sum of a product of two decision variables in LP?

2024/9/21 1:53:38

Being new to Linear Programming and Gurobi, I am dealing with an Integer Linear program where I have two binary decision variables defined as B[u_v, x_y] and A[u_x], I am trying to implement this constraint in Gurobi via Python but I am stuck on how to translate the sum of the product of the two decision variables defined in this loop :

for each edge(u,v) in Set_of_edges:for each vertex x in Set_of_vertices:Sum_over(y) (B[u_v,x_y]) * A[u_x] == 1

From this book, it has to be linearized but I am not able to do it. Anyone could shed some light and provide me with some insights ?

Thanks

Answer

If you got two binary-variables x and y, you can add a new auxiliary binary variable z = x*y by these constraints:

  • z <= x
  • z <= y
  • z >= x + y - 1

As i can't follow your task (incomplete pseudo-code) you will have to do the rest yourself, using the newly introduced variable z.

https://en.xdnf.cn/q/119261.html

Related Q&A

Basic calculator program in python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Why am I receiving ERROR 404 - when attempting to use Python Flask

I have been following this tutorial: https://kb.objectrocket.com/postgresql/scrape-a-website-to-postgres-with-python-938 My app.py file looks like this (taken from the above tutorial): from flask impor…

Merge the dataframes dynamically

I am extracting data from APIs to generate a report. But the number of APIs are dynamic for each report. It can be 1,2,3,5 etc. Once we get the data , we need to store the data as dataframe, to generat…

Read an xml element using python

I have an xml file. I want to search for a specific word in the file, and if i find it- i want to copy all of the xml element the word was in it.for example:<Actions><ActionGroup enabled="…

Using .rsplit() not giving desired results

I want to manipulate a string using .rsplit() so that anything after the last comma in a string of data is split using commas. As an example:,000...should be changed to:,0,0,0,In order to this I am usi…

Concatenate numbers in binary [duplicate]

This question already has answers here:Convert int to binary string in Python(36 answers)Closed 7 years ago.When converting a number in binary in Python what you get is the following:b = bin(77) print(…

AttributeError: DataFrame object has no attribute path

Im trying incrementally to build a financial statement database. The first steps center around collecting 10-Ks from the SECs EDGAR database. I have code for pulling the relevant 8-Ks, 10-Ks, and 10-Qs…

two DataFrame plot in a single plot matplotlip

I want to plot two DataFrame in a single plot.Though, I have seen similar post but none seems to work out. First 5 rows of my dataframe looks like this: df1name type start stop stran…

Automate `lxc-attach` through ssh with Python

Question: How do I automate this process, and include all of the password prompts? Machine 1> ssh user2@machine2password: Machine 2> lxc-attach -n 0x1000 Container> ssh user3@machine3password…

Value of a key in a Python dictinary is not updating [duplicate]

This question already has answers here:Appending a dictionary to a list - I see a pointer like behavior(3 answers)Python The appended element in the list changes as its original variable changes(1 answ…