Generate random points satisfying linear constraints

576 Views Asked by At

In my problem, I have a vector x of len N. Where each element xij is the price of the product i in the country j. Let's say that I have 100 products and 20 countries, so N=100x20=2000.

The solution of X is subject to a set of linear constraints. For instance, minimum/maximum price for each product and maximum difference allowed for the same product between countries. Therefore, I can define the constraints as a matrix Ax<=b

I guess the problem would be like sampling points from a space bounded by hyperplanes defined by the constraints.

Assuming that the problem has multiple feasible solutions. How can I generate random points (solutions of the vector x) that satisfy the constraints? There is any python library that could help me with that?

I tried with https://github.com/python-constraint/python-constraint, but it seems that because the number of solutions is very large, the algorithm gets stuck at some point or takes a long time to return the solution.

1

There are 1 best solutions below

0
On

As @user619894 suggested, I would also have tried it with rejection method. In your answer, you state that this process is slow, I think you mean it takes long until you have "enough" points, i.e. many generated points get rejected. You further state you have implemented Min-Max condition for the components of the vector. Do you "update" them? By this I mean, assume you have condition $1 \leq a \leq 10$ and $3 \leq b \leq 10$ (Min-Max price) and $|a-b| \leq 2$. Assume that you sampled $a=3$. Then you could update the condition for $b$ to $3\leq b \leq5$.

The problem with rejection is, you are essentially trying to hit a dartboard with a blind shot, and of course the probability of hitting gets smaller the bigger the room is.

The only way I see to higher the success rate is to modify the inequalities, trying to eliminate variables.

(Sorry, this would fit better as a comment, but I cannot comment, I do not have enough reputation.)