Skip to content

Commit

Permalink
feat: branch and perform obbt only on quadratic vars
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Dec 10, 2020
1 parent 39575cb commit 8c194c9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
16 changes: 10 additions & 6 deletions galini/branch_and_cut/bound_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import pyomo.environ as pe
from coramin.relaxations.iterators import relaxation_data_objects
from galini.branch_and_cut.branching import BILINEAR_RELAXATIONS_TYPES
from galini.math import is_close
from galini.pyomo import safe_set_bounds
from galini.pyomo.util import update_solver_options
Expand Down Expand Up @@ -72,13 +73,14 @@ def perform_obbt_on_model(solver, model, linear_model, upper_bound, timelimit, r
# collect variables in nonlinear constraints
nonlinear_variables = ComponentSet()
for relaxation in relaxation_data_objects(linear_model, active=True, descend_into=True):
for var in relaxation.get_rhs_vars():
# Coramin will complain about variables that are fixed
if not var.has_lb() or not var.has_ub():
nonlinear_variables.add(var)
else:
if not np.abs(var.ub - var.lb) < mc.epsilon:
if not isinstance(relaxation, BILINEAR_RELAXATIONS_TYPES):
for var in relaxation.get_rhs_vars():
# Coramin will complain about variables that are fixed
if not var.has_lb() or not var.has_ub():
nonlinear_variables.add(var)
else:
if not np.abs(var.ub - var.lb) < mc.epsilon:
nonlinear_variables.add(var)

time_left = timelimit - seconds_elapsed_since(obbt_start_time)
nonlinear_variables = list(nonlinear_variables)
Expand Down Expand Up @@ -140,6 +142,8 @@ def perform_obbt_on_model(solver, model, linear_model, upper_bound, timelimit, r

for var, new_lb, new_ub in zip(nonlinear_variables, *result):
original_var = model.find_component(var.getname(fully_qualified=True))
if original_var is None:
continue
new_lb = best_lower_bound(var, new_lb, var.lb, eps)
new_ub = best_upper_bound(var, new_ub, var.ub, eps)
if np.abs(new_ub - new_lb) < eps:
Expand Down
6 changes: 6 additions & 0 deletions galini/branch_and_cut/branching.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np
import pyomo.environ as pe
from coramin.relaxations.mccormick import PWMcCormickRelaxation

from galini.branch_and_bound.branching import BranchingPoint
from galini.branch_and_bound.strategy import BranchingStrategy
Expand All @@ -24,6 +25,9 @@
from galini.math import is_close, is_inf


BILINEAR_RELAXATIONS_TYPES = (PWMcCormickRelaxation,)


class BranchAndCutBranchingStrategy(BranchingStrategy):
def __init__(self, algorithm):
pass
Expand Down Expand Up @@ -162,6 +166,8 @@ def compute_nonlinear_infeasiblity_components(linear_problem, mip_solution):
}

for relaxation in linear_problem.galini_nonlinear_relaxations:
if not isinstance(relaxation, BILINEAR_RELAXATIONS_TYPES):
continue
rhs_vars = relaxation.get_rhs_vars()

if len(rhs_vars) > 2:
Expand Down
2 changes: 1 addition & 1 deletion galini/branch_and_cut/node_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from pyomo.contrib.fbbt.fbbt import compute_bounds_on_expr

from galini.branch_and_bound.branching import branch_at_point
from galini.relaxations.relax import RelaxationData
from galini.cuts.pool import CutNodeStorage, CutPool
from galini.pyomo import safe_setlb, safe_setub
from galini.relaxations.relax import RelaxationData


class BranchingDecision:
Expand Down
11 changes: 4 additions & 7 deletions galini/relaxations/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
"""Functions to relax nonlinear pyomo expresions."""

import networkx as nx

from suspect.pyomo.quadratic import QuadraticExpression
import pyomo.environ as pe
from suspect.convexity.rules.quadratic import QuadraticRule
from pyomo.contrib.fbbt.fbbt import compute_bounds_on_expr
from coramin.utils.coramin_enums import RelaxationSide, FunctionShape
from coramin.utils.coramin_enums import RelaxationSide
from galini.relaxations.multivariate import FactorableConvexExpressionRelaxation
from coramin.relaxations.auto_relax import replace_sub_expression_with_aux_var
from pyomo.contrib.fbbt.fbbt import compute_bounds_on_expr
from suspect.convexity.rules.quadratic import QuadraticRule
from suspect.pyomo.quadratic import QuadraticExpression

_convexity_rule = QuadraticRule()

Expand Down
8 changes: 4 additions & 4 deletions galini/relaxations/multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

"""Relaxation that replaces a convex function with an auxiliary variable."""

from coramin.utils.coramin_enums import RelaxationSide, FunctionShape
import math

import pyomo.environ as pe
from coramin.relaxations.custom_block import declare_custom_block
from coramin.relaxations.relaxations_base import BaseRelaxationData, ComponentWeakRef
from coramin.utils.coramin_enums import RelaxationSide
from pyomo.core.expr.visitor import identify_variables
import math
import pyomo.environ as pe
from coramin.relaxations._utils import _get_bnds_list


@declare_custom_block(name='FactorableConvexExpressionRelaxation')
Expand Down
3 changes: 2 additions & 1 deletion galini/relaxations/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
_relax_root_to_leaf_SumExpression,
_relax_expr,
)
from coramin.relaxations import PWXSquaredRelaxation, PWUnivariateRelaxation
from coramin.utils.coramin_enums import RelaxationSide
from pyomo.core.expr.numvalue import polynomial_degree
from suspect.pyomo.quadratic import QuadraticExpression
Expand Down Expand Up @@ -164,7 +165,7 @@ def relax(model, data, use_linear_relaxation=True):

assert obj.is_minimizing()

relaxation_side = RelaxationSide.UNDER
# relaxation_side = RelaxationSide.UNDER
relaxation_side = RelaxationSide.BOTH

new_body = relax_expression(model, obj.expr, relaxation_side, data)
Expand Down

0 comments on commit 8c194c9

Please sign in to comment.