def _prop_bnds_root_to_leaf_PowExpression(node, bnds_dict): """ Parameters ---------- node: pyomo.core.expr.expr_pyomo5.ProductExpression bnds_dict: ComponentMap """ assert len(node.args) == 2 arg1, arg2 = node.args lb0, ub0 = bnds_dict[node] lb1, ub1 = bnds_dict[arg1] lb2, ub2 = bnds_dict[arg2] _lb1a, _ub1a = interval.log(lb0, ub0) _lb1a, _ub1a = interval.div(_lb1a, _ub1a, lb2, ub2) _lb1a, _ub1a = interval.exp(_lb1a, _ub1a) _lb1b, _ub1b = interval.sub(0, 0, _lb1a, _ub1a) _lb1 = min(_lb1a, _lb1b) _ub1 = max(_ub1a, _ub1b) _lb2a, _ub2a = interval.log(lb0, ub0) _lb2b, _ub2b = interval.log(lb1, ub1) _lb2, _ub2 = interval.div(_lb2a, _ub2a, _lb2b, _ub2b) if _lb1 > lb1: lb1 = _lb1 if _ub1 < ub1: ub1 = _ub1 if _lb2 > lb2: lb2 = _lb2 if _ub2 < ub2: ub2 = _ub2 bnds_dict[arg1] = (lb1, ub1) bnds_dict[arg2] = (lb2, ub2)
def _prop_bnds_root_to_leaf_ProductExpression(node, bnds_dict): """ Parameters ---------- node: pyomo.core.expr.expr_pyomo5.ProductExpression bnds_dict: ComponentMap """ assert len(node.args) == 2 arg1, arg2 = node.args lb0, ub0 = bnds_dict[node] lb1, ub1 = bnds_dict[arg1] lb2, ub2 = bnds_dict[arg2] _lb1, _ub1 = interval.div(lb0, ub0, lb2, ub2) _lb2, _ub2 = interval.div(lb0, ub0, lb1, ub1) if _lb1 > lb1: lb1 = _lb1 if _ub1 < ub1: ub1 = _ub1 if _lb2 > lb2: lb2 = _lb2 if _ub2 < ub2: ub2 = _ub2 bnds_dict[arg1] = (lb1, ub1) bnds_dict[arg2] = (lb2, ub2)
def _prop_bnds_root_to_leaf_ProductExpression(node, bnds_dict): """ Parameters ---------- node: pyomo.core.expr.numeric_expr.ProductExpression bnds_dict: ComponentMap """ assert len(node.args) == 2 arg1, arg2 = node.args lb0, ub0 = bnds_dict[node] lb1, ub1 = bnds_dict[arg1] lb2, ub2 = bnds_dict[arg2] _lb1, _ub1 = interval.div(lb0, ub0, lb2, ub2) _lb2, _ub2 = interval.div(lb0, ub0, lb1, ub1) if _lb1 > lb1: lb1 = _lb1 if _ub1 < ub1: ub1 = _ub1 if _lb2 > lb2: lb2 = _lb2 if _ub2 < ub2: ub2 = _ub2 bnds_dict[arg1] = (lb1, ub1) bnds_dict[arg2] = (lb2, ub2)
def test_div_edge_cases(self): lb, ub = interval.div(0, -1e-16, 0, 0, 1e-8) self.assertEqual(lb, -interval.inf) self.assertEqual(ub, interval.inf) lb, ub = interval.div(0, 1e-16, 0, 0, 1e-8) self.assertEqual(lb, -interval.inf) self.assertEqual(ub, interval.inf) lb, ub = interval.div(-1e-16, 0, 0, 0, 1e-8) self.assertEqual(lb, -interval.inf) self.assertEqual(ub, interval.inf) lb, ub = interval.div(1e-16, 0, 0, 0, 1e-8) self.assertEqual(lb, -interval.inf) self.assertEqual(ub, interval.inf)
def test_div(self): x_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5))] y_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)), (0, np.random.uniform(2, 5)), (np.random.uniform(0, 2), np.random.uniform(2, 5)), (np.random.uniform(-5, -2), 0), (np.random.uniform(-5, -2), np.random.uniform(-2, 0))] for xl, xu in x_bounds: for yl, yu in y_bounds: zl, zu = interval.div(xl, xu, yl, yu, feasibility_tol=1e-8) x = np.linspace(xl, xu, 100) y = np.linspace(yl, yu, 100) for _x in x: _z = _x / y self.assertTrue(np.all(zl <= _z)) self.assertTrue(np.all(zu >= _z))
def test_div(self): x_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5))] y_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)), (0, np.random.uniform(2, 5)), (np.random.uniform(0, 2), np.random.uniform(2, 5)), (np.random.uniform(-5, -2), 0), (np.random.uniform(-5, -2), np.random.uniform(-2, 0))] for xl, xu in x_bounds: for yl, yu in y_bounds: zl, zu = interval.div(xl, xu, yl, yu) x = np.linspace(xl, xu, 100) y = np.linspace(yl, yu, 100) for _x in x: _z = _x / y self.assertTrue(np.all(zl <= _z)) self.assertTrue(np.all(zu >= _z))