예제 #1
0
def random_encoded(variables, constraints):
    A = np.random.random((constraints, variables))
    alpha = np.random.random(variables + constraints)
    beta = np.zeros(variables + constraints)
    basis = np.random.choice(variables + constraints,
                             size=constraints,
                             replace=False)
    beta[basis] = 1
    return EncodedInstance(lhs=A, alpha=alpha, beta=beta)
예제 #2
0
def generate(seed):
    ''' Generating function taking a seed value and producing an instance
    using the constructor method. The decorators used for this function
    calculate and attach feature and performance data to each generated
    instance, write each instance to a .tar file so they can be loaded
    later to start a search, and write each instance to .mps format. '''

    # Seeded random number generator used in all processes.
    random_state = np.random.RandomState(seed)

    # Generation parameters to be passed to generating functions.
    size_params = dict(variables=random_state.randint(50, 100),
                       constraints=random_state.randint(50, 100))
    beta_params = dict(basis_split=random_state.uniform(low=0.0, high=1.0))
    alpha_params = dict(frac_violations=random_state.uniform(low=0.0,
                                                             high=1.0),
                        beta_param=random_state.lognormal(mean=-0.2,
                                                          sigma=1.8),
                        mean_primal=0,
                        std_primal=1,
                        mean_dual=0,
                        std_dual=1)
    lhs_params = dict(density=random_state.uniform(low=0.3, high=0.7),
                      pv=random_state.uniform(low=0.0, high=1.0),
                      pc=random_state.uniform(low=0.0, high=1.0),
                      coeff_loc=random_state.uniform(low=-2.0, high=2.0),
                      coeff_scale=random_state.uniform(low=0.1, high=1.0))

    # Run the generating functions to produce encoding components and
    # return the constructed instance.
    instance = EncodedInstance(lhs=generate_lhs(random_state=random_state,
                                                **size_params,
                                                **lhs_params).todense(),
                               alpha=generate_alpha(random_state=random_state,
                                                    **size_params,
                                                    **alpha_params),
                               beta=generate_beta(random_state=random_state,
                                                  **size_params,
                                                  **beta_params))
    instance.data = dict(seed=seed)
    return instance
예제 #3
0
def instance(request, lhs_matrix, alpha_vector, beta_vector, solution,
             rhs_vector, objective_vector):
    if request.param == 'encoded':
        return EncodedInstance(lhs=lhs_matrix,
                               alpha=alpha_vector,
                               beta=beta_vector)
    elif request.param == 'solved':
        return SolvedInstance(lhs=lhs_matrix, solution=solution)
    elif request.param == 'unsolved':
        return UnsolvedInstance(lhs=lhs_matrix,
                                rhs=rhs_vector,
                                objective=objective_vector)
예제 #4
0
def generate(seed):
    ''' Generator distributing uniformly across parameters with fixed size.
    Feature values are attached to each instance by the calculate_data
    decorator. Instances are written to compressed format using the
    write_instance decorator so they can be loaded later as start points
    for search algorithms. '''

    random_state = np.random.RandomState(seed)

    size_params = dict(variables=50, constraints=50)
    beta_params = dict(basis_split=random_state.uniform(low=0.0, high=1.0))
    alpha_params = dict(frac_violations=random_state.uniform(low=0.0,
                                                             high=1.0),
                        beta_param=random_state.lognormal(mean=-0.2,
                                                          sigma=1.8),
                        mean_primal=0,
                        std_primal=1,
                        mean_dual=0,
                        std_dual=1)
    lhs_params = dict(density=random_state.uniform(low=0.0, high=1.0),
                      pv=random_state.uniform(low=0.0, high=1.0),
                      pc=random_state.uniform(low=0.0, high=1.0),
                      coeff_loc=random_state.uniform(low=-2.0, high=2.0),
                      coeff_scale=random_state.uniform(low=0.1, high=1.0))

    instance = EncodedInstance(lhs=generate_lhs(random_state=random_state,
                                                **size_params,
                                                **lhs_params).todense(),
                               alpha=generate_alpha(random_state=random_state,
                                                    **size_params,
                                                    **alpha_params),
                               beta=generate_beta(random_state=random_state,
                                                  **size_params,
                                                  **beta_params))
    instance.data = dict(seed=seed,
                         params=dict(size_params=size_params,
                                     beta_params=beta_params,
                                     alpha_params=alpha_params,
                                     lhs_params=lhs_params))
    return instance
예제 #5
0
def construct_feasible_bounded(*, variable_types, lhs, alpha, beta):
    return EncodedInstance(variable_types=variable_types,
                           lhs=lhs,
                           alpha=alpha,
                           beta=beta)