# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2025
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
"""Transformation to convert explicit bounds to variable bounds."""
from math import fabs
import math
from pyomo.core.base.transformation import TransformationFactory
from pyomo.common.config import (
ConfigBlock,
ConfigValue,
NonNegativeFloat,
document_kwargs_from_configdict,
)
from pyomo.core.base.constraint import Constraint
from pyomo.core.expr.numvalue import value
from pyomo.core.plugins.transform.hierarchy import IsomorphicTransformation
from pyomo.repn import generate_standard_repn
def _adjust_var_value_if_not_feasible(var):
# Sometimes deactivating the constraint will remove a
# variable from all active constraints, so that it won't be
# updated during the optimization. Therefore, we need to
# shift the value of var as necessary in order to keep it
# within its implied bounds, as the constraint we are
# deactivating is not an invalid constraint, but rather we
# are moving its implied bound directly onto the variable.
var_value = var.value
if var.has_lb():
var_value = max(var_value, var.lb)
if var.has_ub():
var_value = min(var_value, var.ub)
if var.is_integer():
var.set_value(int(var_value))
else:
var.set_value(var_value)