# ____________________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2026 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.
# ____________________________________________________________________________________
#
# NOTE: deprecated code
#
# This code is here for historical purposes, and
# because we may support an explicit matrix representation for models.
#
from pyomo.common.deprecation import deprecated
from pyomo.core.base import Objective, Constraint
import array
def _process_canonical_repn(self, expr):
"""
Returns a dictionary of {var_name_or_None: coef} values
"""
terms = {}
# Get the variables from the canonical representation
vars = expr.pop(-1, {})
# Find the linear terms
linear = expr.pop(1, {})
for k in linear:
# FrozeDicts don't support (k, v)-style iteration
v = linear[k]
# There's exactly 1 variable in each term
terms[vars[k.keys()[0]].label] = v
# Get the constant term, if present
const = expr.pop(0, {})
if None in const:
terms[None] = const[None]
if len(expr) != 0:
raise TypeError("Nonlinear terms in expression")
return terms