def MindtPy_initialize_master(solve_data, config): """Initialize the decomposition algorithm. This includes generating the initial cuts require to build the master problem. """ # if single tree is activated, we need to add bounds for unbounded variables in nonlinear constraints to avoid unbounded master problem. if config.single_tree: var_bound_add(solve_data, config) m = solve_data.mip = solve_data.working_model.clone() MindtPy = m.MindtPy_utils m.dual.deactivate() if config.strategy == 'OA': calc_jacobians(solve_data, config) # preload jacobians MindtPy.MindtPy_linear_cuts.oa_cuts = ConstraintList( doc='Outer approximation cuts') # elif config.strategy == 'ECP': # calc_jacobians(solve_data, config) # preload jacobians # MindtPy.MindtPy_linear_cuts.ecp_cuts = ConstraintList( # doc='Extended Cutting Planes') # elif config.strategy == 'PSC': # detect_nonlinear_vars(solve_data, config) # MindtPy.MindtPy_linear_cuts.psc_cuts = ConstraintList( # doc='Partial surrogate cuts') # elif config.strategy == 'GBD': # MindtPy.MindtPy_linear_cuts.gbd_cuts = ConstraintList( # doc='Generalized Benders cuts') # Set default initialization_strategy if config.init_strategy is None: if config.strategy == 'OA': config.init_strategy = 'rNLP' else: config.init_strategy = 'max_binary' # Do the initialization elif config.init_strategy == 'rNLP': init_rNLP(solve_data, config) elif config.init_strategy == 'max_binary': init_max_binaries(solve_data, config) # if config.strategy == 'ECP': # add_ecp_cut(solve_data, config) # else: fixed_nlp, fixed_nlp_result = solve_NLP_subproblem(solve_data, config) if fixed_nlp_result.solver.termination_condition is tc.optimal or fixed_nlp_result.solver.termination_condition is tc.locallyOptimal: handle_NLP_subproblem_optimal(fixed_nlp, solve_data, config) elif fixed_nlp_result.solver.termination_condition is tc.infeasible: handle_NLP_subproblem_infeasible(fixed_nlp, solve_data, config) else: handle_NLP_subproblem_other_termination(fixed_nlp, fixed_nlp_result.solver.termination_condition, solve_data, config)
def MindtPy_initialize_master(solve_data, config): """Initialize the decomposition algorithm. This includes generating the initial cuts require to build the master problem. """ m = solve_data.mip = solve_data.working_model.clone() MindtPy = m.MindtPy_utils m.dual.activate() if config.strategy == 'OA': calc_jacobians(solve_data, config) # preload jacobians MindtPy.MindtPy_linear_cuts.oa_cuts = ConstraintList( doc='Outer approximation cuts') # elif config.strategy == 'ECP': # calc_jacobians(solve_data, config) # preload jacobians # MindtPy.MindtPy_linear_cuts.ecp_cuts = ConstraintList( # doc='Extended Cutting Planes') # elif config.strategy == 'PSC': # detect_nonlinear_vars(solve_data, config) # MindtPy.MindtPy_linear_cuts.psc_cuts = ConstraintList( # doc='Partial surrogate cuts') # elif config.strategy == 'GBD': # MindtPy.MindtPy_linear_cuts.gbd_cuts = ConstraintList( # doc='Generalized Benders cuts') # Set default initialization_strategy if config.init_strategy is None: if config.strategy == 'OA': config.init_strategy = 'rNLP' else: config.init_strategy = 'max_binary' # Do the initialization elif config.init_strategy == 'rNLP': init_rNLP(solve_data, config) elif config.init_strategy == 'max_binary': init_max_binaries(solve_data, config) # if config.strategy == 'ECP': # add_ecp_cut(solve_data, config) # else: solve_NLP_subproblem(solve_data, config)
def MindtPy_initialize_main(solve_data, config): """Initializes the decomposition algorithm and creates the main MIP/MILP problem. This function initializes the decomposition problem, which includes generating the initial cuts required to build the main MIP. Parameters ---------- solve_data : MindtPySolveData Data container that holds solve-instance data. config : ConfigBlock The specific configurations for MindtPy. """ # if single tree is activated, we need to add bounds for unbounded variables in nonlinear constraints to avoid unbounded main problem. if config.single_tree: add_var_bound(solve_data, config) m = solve_data.mip = solve_data.working_model.clone() next(solve_data.mip.component_data_objects(Objective, active=True)).deactivate() MindtPy = m.MindtPy_utils if config.calculate_dual: m.dual.deactivate() if config.init_strategy == 'FP': MindtPy.cuts.fp_orthogonality_cuts = ConstraintList( doc='Orthogonality cuts in feasibility pump') if config.fp_projcuts: solve_data.working_model.MindtPy_utils.cuts.fp_orthogonality_cuts = ConstraintList( doc='Orthogonality cuts in feasibility pump') if config.strategy == 'OA' or config.init_strategy == 'FP': calc_jacobians(solve_data, config) # preload jacobians MindtPy.cuts.oa_cuts = ConstraintList(doc='Outer approximation cuts') elif config.strategy == 'ECP': calc_jacobians(solve_data, config) # preload jacobians MindtPy.cuts.ecp_cuts = ConstraintList(doc='Extended Cutting Planes') elif config.strategy == 'GOA': MindtPy.cuts.aff_cuts = ConstraintList(doc='Affine cuts') # elif config.strategy == 'PSC': # detect_nonlinear_vars(solve_data, config) # MindtPy.cuts.psc_cuts = ConstraintList( # doc='Partial surrogate cuts') # elif config.strategy == 'GBD': # MindtPy.cuts.gbd_cuts = ConstraintList( # doc='Generalized Benders cuts') # Set default initialization_strategy if config.init_strategy is None: if config.strategy in {'OA', 'GOA'}: config.init_strategy = 'rNLP' else: config.init_strategy = 'max_binary' config.logger.info('{} is the initial strategy being used.' '\n'.format(config.init_strategy)) config.logger.info( ' =============================================================================================' ) config.logger.info( ' {:>9} | {:>15} | {:>15} | {:>11} | {:>11} | {:^7} | {:>7}\n'.format( 'Iteration', 'Subproblem Type', 'Objective Value', 'Lower Bound', 'Upper Bound', ' Gap ', 'Time(s)')) # Do the initialization if config.init_strategy == 'rNLP': init_rNLP(solve_data, config) elif config.init_strategy == 'max_binary': init_max_binaries(solve_data, config) elif config.init_strategy == 'initial_binary': solve_data.curr_int_sol = get_integer_solution( solve_data.working_model) solve_data.integer_list.append(solve_data.curr_int_sol) if config.strategy != 'ECP': fixed_nlp, fixed_nlp_result = solve_subproblem(solve_data, config) handle_nlp_subproblem_tc(fixed_nlp, fixed_nlp_result, solve_data, config) elif config.init_strategy == 'FP': init_rNLP(solve_data, config) fp_loop(solve_data, config)
def MindtPy_initialize_master(solve_data, config): """ Initializes the decomposition algorithm and creates the master MIP/MILP problem. This function initializes the decomposition problem, which includes generating the initial cuts required to build the master MIP/MILP Parameters ---------- solve_data: MindtPy Data Container data container that holds solve-instance data config: ConfigBlock contains the specific configurations for the algorithm """ # if single tree is activated, we need to add bounds for unbounded variables in nonlinear constraints to avoid unbounded master problem. if config.single_tree: var_bound_add(solve_data, config) m = solve_data.mip = solve_data.working_model.clone() MindtPy = m.MindtPy_utils if config.use_dual: m.dual.deactivate() if config.strategy == 'OA': calc_jacobians(solve_data, config) # preload jacobians MindtPy.MindtPy_linear_cuts.oa_cuts = ConstraintList( doc='Outer approximation cuts') elif config.strategy == 'ECP': calc_jacobians(solve_data, config) # preload jacobians MindtPy.MindtPy_linear_cuts.ecp_cuts = ConstraintList( doc='Extended Cutting Planes') # elif config.strategy == 'PSC': # detect_nonlinear_vars(solve_data, config) # MindtPy.MindtPy_linear_cuts.psc_cuts = ConstraintList( # doc='Partial surrogate cuts') # elif config.strategy == 'GBD': # MindtPy.MindtPy_linear_cuts.gbd_cuts = ConstraintList( # doc='Generalized Benders cuts') # Set default initialization_strategy if config.init_strategy is None: if config.strategy in {'OA', 'GOA'}: config.init_strategy = 'rNLP' else: config.init_strategy = 'max_binary' config.logger.info( '{} is the initial strategy being used.' '\n'.format( config.init_strategy)) # Do the initialization if config.init_strategy == 'rNLP': init_rNLP(solve_data, config) elif config.init_strategy == 'max_binary': init_max_binaries(solve_data, config) elif config.init_strategy == 'initial_binary': if config.strategy != 'ECP': fixed_nlp, fixed_nlp_result = solve_NLP_subproblem( solve_data, config) if fixed_nlp_result.solver.termination_condition in {tc.optimal, tc.locallyOptimal, tc.feasible}: handle_NLP_subproblem_optimal(fixed_nlp, solve_data, config) elif fixed_nlp_result.solver.termination_condition is tc.infeasible: handle_NLP_subproblem_infeasible(fixed_nlp, solve_data, config) else: handle_NLP_subproblem_other_termination(fixed_nlp, fixed_nlp_result.solver.termination_condition, solve_data, config)