def _rand_with_constraints(x_bounds, x_types): outputs = None x_bounds_withconstraints = [x_bounds[i] for i in CONSTRAINT_PARAMS_IDX] x_types_withconstraints = [x_types[i] for i in CONSTRAINT_PARAMS_IDX] x_val_withconstraints = lib_constraint_summation.rand(x_bounds_withconstraints,\ x_types_withconstraints, CONSTRAINT_LOWERBOUND, CONSTRAINT_UPPERBOUND) if not x_val_withconstraints: outputs = [None] * len(x_bounds) for i, _ in enumerate(CONSTRAINT_PARAMS_IDX): outputs[CONSTRAINT_PARAMS_IDX[i]] = x_val_withconstraints[i] for i, output in enumerate(outputs): if not output: outputs[i] = random.randint(x_bounds[i][0], x_bounds[i][1]) return outputs
def _rand_with_constraints(x_bounds, x_types): ''' Random generate the variable with constraints ''' outputs = None x_bounds_withconstraints = [x_bounds[i] for i in CONSTRAINT_PARAMS_IDX] x_types_withconstraints = [x_types[i] for i in CONSTRAINT_PARAMS_IDX] x_val_withconstraints = lib_constraint_summation.rand( x_bounds_withconstraints, x_types_withconstraints, CONSTRAINT_LOWERBOUND, CONSTRAINT_UPPERBOUND) if x_val_withconstraints is not None: outputs = [None] * len(x_bounds) for i, _ in enumerate(CONSTRAINT_PARAMS_IDX): outputs[CONSTRAINT_PARAMS_IDX[i]] = x_val_withconstraints[i] for i, _ in enumerate(outputs): if outputs[i] is None: outputs[i] = random.randint(x_bounds[i][0], x_bounds[i][1]) return outputs