From 56a80fb43573ae7a612925303d927b5f16cb954a Mon Sep 17 00:00:00 2001 From: Michael Bynum Date: Fri, 23 Apr 2021 12:28:24 -0600 Subject: [PATCH] robust use of find_component and better handling of bounds for quadratics --- galini/branch_and_cut/node_storage.py | 16 ++++++++++++---- galini/relaxations/relax.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/galini/branch_and_cut/node_storage.py b/galini/branch_and_cut/node_storage.py index 5e45014..b581025 100644 --- a/galini/branch_and_cut/node_storage.py +++ b/galini/branch_and_cut/node_storage.py @@ -96,11 +96,19 @@ def recompute_model_relaxation_bounds(self): if isinstance(relaxation, PWXSquaredRelaxationData): # w >= x^2: add an oa point in the midpoint relaxation.clean_oa_points() - var_values = pe.ComponentMap() x_var = relaxation.get_rhs_vars()[0] - midpoint = x_var.lb + 0.5*(x_var.ub - x_var.lb) - var_values[x_var] = midpoint - relaxation.add_oa_point(var_values) + if x_var.has_lb() and x_var.has_ub(): + midpoint = x_var.lb + 0.5*(x_var.ub - x_var.lb) + relaxation.add_oa_point(pe.ComponentMap([(x_var, midpoint)])) + elif x_var.has_lb(): + if x_var.lb <= 0: + relaxation.add_oa_point(pe.ComponentMap([(x_var, 1)])) + elif x_var.has_ub(): + if x_var.ub >= 0: + relaxation.add_oa_point(pe.ComponentMap([(x_var, -1)])) + else: + relaxation.add_oa_point(pe.ComponentMap([(x_var, -1)])) + relaxation.add_oa_point(pe.ComponentMap([(x_var, 1)])) relaxation.rebuild() diff --git a/galini/relaxations/relax.py b/galini/relaxations/relax.py index 876e80d..39bbc79 100644 --- a/galini/relaxations/relax.py +++ b/galini/relaxations/relax.py @@ -148,7 +148,7 @@ def relax(model, data, use_linear_relaxation=True): for var in model.component_data_objects(pe.Var, active=True, descend_into=True): - new_var = new_model.find_component(var.getname(fully_qualified=True)) + new_var = new_model.find_component(var) data.original_to_new_var_map[var] = new_var model = new_model