def should_initialize_and_reconstuct(): with open('simplexTests/dict1') as inp, open('simplexTests/dict1.initialized') as out: dictionary, basic_vars, non_basic_vars = initialize_and_reconstruct(*pivot.make_dictionary(inp)) expected_dict, expected_basic, expected_non_basic = pivot.make_dictionary(out) assert set(basic_vars) == set(expected_basic) assert set(non_basic_vars) == set(expected_non_basic) assert all(abs(dictionary[:, 0] - expected_dict[:, 0]) < 0.0001) print(dictionary, non_basic_vars) print(expected_dict, expected_non_basic) for v in non_basic_vars: col = dictionary[:, np.r_[False, non_basic_vars == v]] expected_col = expected_dict[:, np.r_[False, expected_non_basic == v]] for bv in basic_vars: print (col[bv == basic_vars], expected_col[bv == expected_basic]) assert all(abs(col[bv == basic_vars] - expected_col[bv == expected_basic]) < 0.0001) assert all(abs(col[len(basic_vars)] - expected_col[len(basic_vars)]) < 0.0001)
def optimize_input(file_path): return optimize(*pivot.make_dictionary(file_path))
def simplex_input(file_path): return simplex_optimal_values(*make_dictionary(file_path))
def solve_ilp_input(file_path): return solve_ilp(*make_dictionary(file_path))
def solve_ilp_input_and_print(file_path): dictionary, basic_vars, non_basic_vars = make_dictionary(file_path) print(collect_result(*solve_ilp(dictionary, basic_vars, non_basic_vars), original_non_basic = non_basic_vars))
def initialize_input(file_path): dictionary, basic_vars, non_basic_vars = pivot.make_dictionary(file_path) return initialize(dictionary, basic_vars, non_basic_vars)