Suppose G is a matrix of (100 , 20 ) and h is vector of ( 100).
How do I randomly generate a vector x of size 100 that meets the condition G x <= h ?
Clearly, I can do something like the following. But, that is inefficient if I want to generate thousands of these points. Thanks.
import numpy as np
# Define G and h
G = np.random.rand(100, 20)
h = np.random.rand(100)
def is_feasible(x):
return np.all(np.dot(G, x) <= h)
while True:
# Generate random vector x
x = np.random.rand(20)
# Check if x is feasible
if is_feasible(x):
break
I believe you could try following. You have unequalities
G x <= h
xi < 1 for any i
xi >= 0 for any i
You find intersection convex polygon satisfying all above mentioned conditions. And from that polygon for each dimension you get
max xi and min xi, obviously those values being smaller than 1 and larger or equal to 0.
Then you sample your point in the hypercube defined by min/max value, and only then you apply matrix check
Pseudocode
while True:
for i in range(0,100):
xi = min xi + (max xi - min xi) U01
if G x <= h: break