本文整理汇总了Python中pyomo.environ.ConcreteModel.z方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.z方法的具体用法?Python ConcreteModel.z怎么用?Python ConcreteModel.z使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.z方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_induced_linearity_case2
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_induced_linearity_case2(self):
m = ConcreteModel()
m.x = Var([0], bounds=(-3, 8))
m.y = Var(RangeSet(4), domain=Binary)
m.z = Var(domain=Integers, bounds=(-1, 2))
m.constr = Constraint(
expr=m.x[0] == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
m.logical = ConstraintList()
m.logical.add(expr=m.y[1] + m.y[2] == 1)
m.logical.add(expr=m.y[3] + m.y[4] == 1)
m.logical.add(expr=m.y[2] + m.y[4] <= 1)
m.b = Var(bounds=(-2, 7))
m.c = Var()
m.bilinear = Constraint(
expr=(m.x[0] - 3) * (m.b + 2) - (m.c + 4) * m.b +
exp(m.b ** 2) * m.x[0] <= m.c)
TransformationFactory('contrib.induced_linearity').apply_to(m)
xfrmed_blk = m._induced_linearity_info.x0_b_bilinear
self.assertSetEqual(
set(xfrmed_blk.valid_values), set([1, 2, 3, 4, 5]))
select_one_repn = generate_standard_repn(
xfrmed_blk.select_one_value.body)
self.assertEqual(
ComponentSet(select_one_repn.linear_vars),
ComponentSet(xfrmed_blk.x_active[i] for i in xfrmed_blk.valid_values))
示例2: test_bilinear_in_disjuncts
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_bilinear_in_disjuncts(self):
m = ConcreteModel()
m.x = Var([0], bounds=(-3, 8))
m.y = Var(RangeSet(4), domain=Binary)
m.z = Var(domain=Integers, bounds=(-1, 2))
m.constr = Constraint(
expr=m.x[0] == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
m.logical = ConstraintList()
m.logical.add(expr=m.y[1] + m.y[2] == 1)
m.logical.add(expr=m.y[3] + m.y[4] == 1)
m.logical.add(expr=m.y[2] + m.y[4] <= 1)
m.v = Var([1, 2])
m.v[1].setlb(-2)
m.v[1].setub(7)
m.v[2].setlb(-4)
m.v[2].setub(5)
m.bilinear = Constraint(
expr=(m.x[0] - 3) * (m.v[1] + 2) - (m.v[2] + 4) * m.v[1] +
exp(m.v[1] ** 2) * m.x[0] <= m.v[2])
m.disjctn = Disjunction(expr=[
[m.x[0] * m.v[1] <= 4],
[m.x[0] * m.v[2] >= 6]
])
TransformationFactory('contrib.induced_linearity').apply_to(m)
self.assertEqual(
m.disjctn.disjuncts[0].constraint[1].body.polynomial_degree(), 1)
self.assertEqual(
m.disjctn.disjuncts[1].constraint[1].body.polynomial_degree(), 1)
示例3: test_binary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_binary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.c = Constraint(expr=0 <= m.x + m.y - m.z * m.y / m.x + 7)
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m))
示例4: test_tuple_constraint_create
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_tuple_constraint_create(self):
def rule1(model):
return (0.0,model.x)
model = ConcreteModel()
model.x = Var()
model.y = Var()
model.z = Var()
model.o = Constraint(rule=rule1)
#
def rule1(model):
return (model.y,model.x,model.z)
model = AbstractModel()
model.x = Var()
model.y = Var()
model.z = Var()
model.o = Constraint(rule=rule1)
self.assertRaises(ValueError, model.create_instance)
示例5: test_skip_trivial_constraints
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_skip_trivial_constraints(self):
"""Tests handling of zero coefficients."""
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.c = Constraint(expr=m.x * m.y == m.z)
m.z.fix(0)
m.y.fix(0)
TransformationFactory('contrib.constraints_to_var_bounds').apply_to(m)
self.assertEqual(m.c.body.polynomial_degree(), 1)
self.assertTrue(m.c.active)
self.assertFalse(m.x.has_lb())
self.assertFalse(m.x.has_ub())
示例6: test_solve_linear_GDP_unbounded
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_solve_linear_GDP_unbounded(self):
m = ConcreteModel()
m.GDPopt_utils = Block()
m.x = Var(bounds=(-1, 10))
m.y = Var(bounds=(2, 3))
m.z = Var()
m.d = Disjunction(expr=[
[m.x + m.y >= 5], [m.x - m.y <= 3]
])
m.o = Objective(expr=m.z)
m.GDPopt_utils.variable_list = [m.x, m.y, m.z]
m.GDPopt_utils.disjunct_list = [m.d._autodisjuncts[0], m.d._autodisjuncts[1]]
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.gdpopt', logging.WARNING):
solve_linear_GDP(m, GDPoptSolveData(), GDPoptSolver.CONFIG(dict(mip_solver=mip_solver)))
self.assertIn("Linear GDP was unbounded. Resolving with arbitrary bound values",
output.getvalue().strip())
示例7: test_determine_valid_values
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_determine_valid_values(self):
m = ConcreteModel()
m.x = Var()
m.y = Var(RangeSet(4), domain=Binary)
m.z = Var(domain=Integers, bounds=(-1, 2))
m.constr = Constraint(
expr=m.x == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
m.logical = ConstraintList()
m.logical.add(expr=m.y[1] + m.y[2] == 1)
m.logical.add(expr=m.y[3] + m.y[4] == 1)
m.logical.add(expr=m.y[2] + m.y[4] <= 1)
var_to_values_map = determine_valid_values(
m, detect_effectively_discrete_vars(m, 1E-6), Bunch(
equality_tolerance=1E-6,
pruning_solver='glpk'))
valid_values = set([1, 2, 3, 4, 5])
self.assertEqual(set(var_to_values_map[m.x]), valid_values)
示例8: test_negative_float_double_operator
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_negative_float_double_operator(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var(bounds=(0, 6))
m.c = Constraint(expr=(m.x * m.y * -2) == 0)
m.c2 = Constraint(expr=m.z ** -1.5 == 0)
m.o = Objective(expr=m.z)
m.y.fix(-7)
m.x.fix(4)
lbl = NumericLabeler('x')
smap = SymbolMap(lbl)
tc = StorageTreeChecker(m)
self.assertEqual(expression_to_string(
m.c.body, tc, smap=smap), "4*(-7)*(-2)")
self.assertEqual(expression_to_string(
m.c2.body, tc, smap=smap), "x1 ** (-1.5)")
示例9: test_unary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_unary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.a = Var()
m.b = Var()
m.c = Var()
m.d = Var()
m.c1 = Constraint(expr=0 <= sin(m.x))
m.c2 = Constraint(expr=0 <= cos(m.y))
m.c3 = Constraint(expr=0 <= tan(m.z))
m.c4 = Constraint(expr=0 <= asin(m.a))
m.c5 = Constraint(expr=0 <= acos(m.b))
m.c6 = Constraint(expr=0 <= atan(m.c))
m.c7 = Constraint(expr=0 <= sqrt(m.d))
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m) is not False)
示例10: test_detect_effectively_discrete_vars
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_detect_effectively_discrete_vars(self):
m = ConcreteModel()
m.x = Var()
m.y = Var(domain=Binary)
m.z = Var(domain=Integers)
m.constr = Constraint(expr=m.x == m.y + m.z)
m.ignore_inequality = Constraint(expr=m.x <= m.y + m.z)
m.ignore_nonlinear = Constraint(expr=m.x ** 2 == m.y + m.z)
m.a = Var()
m.b = Var(domain=Binary)
m.c = Var(domain=Integers)
m.disj = Disjunct()
m.disj.constr = Constraint(expr=m.a == m.b + m.c)
effectively_discrete = detect_effectively_discrete_vars(m, 1E-6)
self.assertEqual(len(effectively_discrete), 1)
self.assertEqual(effectively_discrete[m.x], [m.constr])
effectively_discrete = detect_effectively_discrete_vars(m.disj, 1E-6)
self.assertEqual(len(effectively_discrete), 1)
self.assertEqual(effectively_discrete[m.a], [m.disj.constr])
示例11: test_detect_bilinear_vars
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_detect_bilinear_vars(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.c = Constraint(
expr=(m.x - 3) * (m.y + 2) - (m.z + 4) * m.y + (m.x + 2) ** 2
+ exp(m.y ** 2) * m.x <= m.z)
m.c2 = Constraint(expr=m.x * m.y == 3)
bilinear_map = _bilinear_expressions(m)
self.assertEqual(len(bilinear_map), 3)
self.assertEqual(len(bilinear_map[m.x]), 2)
self.assertEqual(len(bilinear_map[m.y]), 2)
self.assertEqual(len(bilinear_map[m.z]), 1)
self.assertEqual(bilinear_map[m.x][m.x], ComponentSet([m.c]))
self.assertEqual(bilinear_map[m.x][m.y], ComponentSet([m.c, m.c2]))
self.assertEqual(bilinear_map[m.y][m.x], ComponentSet([m.c, m.c2]))
self.assertEqual(bilinear_map[m.y][m.z], ComponentSet([m.c]))
self.assertEqual(bilinear_map[m.z][m.y], ComponentSet([m.c]))
示例12: test_fixed_var_to_string
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_fixed_var_to_string(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.z.fix(-3)
lbl = NumericLabeler('x')
smap = SymbolMap(lbl)
tc = StorageTreeChecker(m)
self.assertEqual(expression_to_string(
m.x + m.y - m.z, tc, lbl, smap=smap), "x1 + x2 - (-3)")
m.z.fix(-400)
self.assertEqual(expression_to_string(
m.z + m.y - m.z, tc, smap=smap), "(-400) + x2 - (-400)")
m.z.fix(8.8)
self.assertEqual(expression_to_string(
m.x + m.z - m.y, tc, smap=smap), "x1 + 8.8 - x2")
m.z.fix(-8.8)
self.assertEqual(expression_to_string(
m.x * m.z - m.y, tc, smap=smap), "x1*(-8.8) - x2")
示例13: test_compute_time_stage
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_compute_time_stage(self):
model = ConcreteModel()
model.x = Var()
model.y = Var([0,1])
model.z = Var()
model.p = Param(mutable=True)
model.cost = Expression([0,1])
model.cost[0] = model.x + model.y[0]
model.cost[1] = model.p + model.y[1] + model.y[0]*model.p
model.o = Objective(expr=model.cost[0] + model.cost[1])
model.c = ConstraintList()
model.c.add(model.x >= 1) # 1
model.c.add(model.y[0] >= 1) # 2
model.c.add(model.p * model.y[0] >= 1) # 3
model.c.add(model.y[0] >= model.p) # 4
model.c.add(model.p <= model.y[1]) # 5
model.c.add(model.y[1] <= 1) # 6
model.c.add(model.x >= model.p) # 7
model.c.add(model.z == 1) # 8
model.varstage = VariableStageAnnotation()
model.varstage.declare(model.x, 1)
model.varstage.declare(model.y[0], 1, derived=True)
model.varstage.declare(model.y[1], 2)
model.varstage.declare(model.z, 2, derived=True)
model.stagecost = StageCostAnnotation()
model.stagecost.declare(model.cost[0], 1)
model.stagecost.declare(model.cost[1], 2)
model.stochdata = StochasticDataAnnotation()
model.stochdata.declare(model.p,
distribution=UniformDistribution(0, 1))
sp = EmbeddedSP(model)
#
# check variables
#
self.assertEqual(sp.compute_time_stage(model.x),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.x,
derived_last_stage=True),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.y[0]),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.y[0],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.y[1]),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.y[1],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.z),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.z,
derived_last_stage=True),
max(sp.time_stages))
#
# check constraints
#
self.assertEqual(sp.compute_time_stage(model.c[1]),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[1],
derived_last_stage=True),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[2]),
min(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[2],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[3]),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[3],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[4]),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[4],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[5]),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[5],
derived_last_stage=True),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[6]),
max(sp.time_stages))
self.assertEqual(sp.compute_time_stage(model.c[6],
derived_last_stage=True),
max(sp.time_stages))
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def __init__(self, results, threshold=None, k=10, solver="glpk", verbosity=0):
"""
:param result: Epitope prediction result object from which the epitope selection should be performed
:type result: :class:`~Fred2.Core.Result.EpitopePredictionResult`
:param dict(str,float) threshold: A dictionary scoring the binding thresholds for each HLA
:class:`~Fred2.Core.Allele.Allele` key = allele name; value = the threshold
:param int k: The number of epitopes to select
:param str solver: The solver to be used (default glpk)
:param int verbosity: Integer defining whether additional debugg prints are made >0 => debug mode
"""
#check input data
if not isinstance(results, EpitopePredictionResult):
raise ValueError("first input parameter is not of type EpitopePredictionResult")
_alleles = copy.deepcopy(results.columns.values.tolist())
#test if allele prob is set, if not set allele prob uniform
#if only partly set infer missing values (assuming uniformity of missing value)
prob = []
no_prob = []
for a in _alleles:
if a.prob is None:
no_prob.append(a)
else:
prob.append(a)
if len(no_prob) > 0:
#group by locus
no_prob_grouped = {}
prob_grouped = {}
for a in no_prob:
no_prob_grouped.setdefault(a.locus, []).append(a)
for a in prob:
prob_grouped.setdefault(a.locus, []).append(a)
for g, v in no_prob_grouped.iteritems():
total_loc_a = len(v)
if g in prob_grouped:
remaining_mass = 1.0 - sum(a.prob for a in prob_grouped[g])
for a in v:
a.prob = remaining_mass/total_loc_a
else:
for a in v:
a.prob = 1.0/total_loc_a
probs = {a.name:a.prob for a in _alleles}
if verbosity:
for a in _alleles:
print a.name, a.prob
#start constructing model
self.__solver = SolverFactory(solver)
self.__verbosity = verbosity
self.__changed = True
self.__alleleProb = _alleles
self.__k = k
self.__result = None
self.__thresh = {} if threshold is None else threshold
# Variable, Set and Parameter preparation
alleles_I = {}
variations = []
epi_var = {}
imm = {}
peps = {}
cons = {}
#unstack multiindex df to get normal df based on first prediction method
#and filter for binding epitopes
method = results.index.values[0][1]
res_df = results.xs(results.index.values[0][1], level="Method")
res_df = res_df[res_df.apply(lambda x: any(x[a] > self.__thresh.get(a.name, -float("inf"))
for a in res_df.columns), axis=1)]
for tup in res_df.itertuples():
p = tup[0]
seq = str(p)
peps[seq] = p
for a, s in itr.izip(res_df.columns, tup[1:]):
if method in ["smm", "smmpmbec", "arb", "comblibsidney"]:
try:
thr = min(1., max(0.0, 1.0 - math.log(self.__thresh.get(a.name),
50000))) if a.name in self.__thresh else -float("inf")
except:
thr = 0
if s >= thr:
alleles_I.setdefault(a.name, set()).add(seq)
imm[seq, a.name] = min(1., max(0.0, 1.0 - math.log(s, 50000)))
else:
if s > self.__thresh.get(a.name, -float("inf")):
alleles_I.setdefault(a.name, set()).add(seq)
imm[seq, a.name] = s
prots = set(pr for pr in p.get_all_proteins())
cons[seq] = len(prots)
for prot in prots:
variations.append(prot.gene_id)
epi_var.setdefault(prot.gene_id, set()).add(seq)
self.__peptideSet = peps
#.........这里部分代码省略.........
示例15: test_get_check_units_on_all_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z [as 别名]
def test_get_check_units_on_all_expressions(self):
# this method is going to test all the expression types that should work
# to be defensive, we will also test that we actually have the expected expression type
# therefore, if the expression system changes and we get a different expression type,
# we will know we need to change these tests
uc = units
kg = uc.kg
m = uc.m
model = ConcreteModel()
model.x = Var()
model.y = Var()
model.z = Var()
model.p = Param(initialize=42.0, mutable=True)
# test equality
self._get_check_units_ok(3.0*kg == 1.0*kg, uc, 'kg', expr.EqualityExpression)
self._get_check_units_fail(3.0*kg == 2.0*m, uc, expr.EqualityExpression)
# test inequality
self._get_check_units_ok(3.0*kg <= 1.0*kg, uc, 'kg', expr.InequalityExpression)
self._get_check_units_fail(3.0*kg <= 2.0*m, uc, expr.InequalityExpression)
self._get_check_units_ok(3.0*kg >= 1.0*kg, uc, 'kg', expr.InequalityExpression)
self._get_check_units_fail(3.0*kg >= 2.0*m, uc, expr.InequalityExpression)
# test RangedExpression
self._get_check_units_ok(inequality(3.0*kg, 4.0*kg, 5.0*kg), uc, 'kg', expr.RangedExpression)
self._get_check_units_fail(inequality(3.0*m, 4.0*kg, 5.0*kg), uc, expr.RangedExpression)
self._get_check_units_fail(inequality(3.0*kg, 4.0*m, 5.0*kg), uc, expr.RangedExpression)
self._get_check_units_fail(inequality(3.0*kg, 4.0*kg, 5.0*m), uc, expr.RangedExpression)
# test SumExpression, NPV_SumExpression
self._get_check_units_ok(3.0*model.x*kg + 1.0*model.y*kg + 3.65*model.z*kg, uc, 'kg', expr.SumExpression)
self._get_check_units_fail(3.0*model.x*kg + 1.0*model.y*m + 3.65*model.z*kg, uc, expr.SumExpression)
self._get_check_units_ok(3.0*kg + 1.0*kg + 2.0*kg, uc, 'kg', expr.NPV_SumExpression)
self._get_check_units_fail(3.0*kg + 1.0*kg + 2.0*m, uc, expr.NPV_SumExpression)
# test ProductExpression, NPV_ProductExpression
self._get_check_units_ok(model.x*kg * model.y*m, uc, 'kg * m', expr.ProductExpression)
self._get_check_units_ok(3.0*kg * 1.0*m, uc, 'kg * m', expr.NPV_ProductExpression)
self._get_check_units_ok(3.0*kg*m, uc, 'kg * m', expr.NPV_ProductExpression)
# I don't think that there are combinations that can "fail" for products
# test MonomialTermExpression
self._get_check_units_ok(model.x*kg, uc, 'kg', expr.MonomialTermExpression)
# test ReciprocalExpression, NPV_ReciprocalExpression
self._get_check_units_ok(1.0/(model.x*kg), uc, '1 / kg', expr.ReciprocalExpression)
self._get_check_units_ok(1.0/kg, uc, '1 / kg', expr.NPV_ReciprocalExpression)
# I don't think that there are combinations that can "fail" for products
# test PowExpression, NPV_PowExpression
# ToDo: fix the str representation to combine the powers or the expression system
self._get_check_units_ok((model.x*kg**2)**3, uc, 'kg ** 6', expr.PowExpression) # would want this to be kg**6
self._get_check_units_fail(kg**model.x, uc, expr.PowExpression, UnitsError)
self._get_check_units_fail(model.x**kg, uc, expr.PowExpression, UnitsError)
self._get_check_units_ok(kg**2, uc, 'kg ** 2', expr.NPV_PowExpression)
self._get_check_units_fail(3.0**kg, uc, expr.NPV_PowExpression, UnitsError)
# test NegationExpression, NPV_NegationExpression
self._get_check_units_ok(-(kg*model.x*model.y), uc, 'kg', expr.NegationExpression)
self._get_check_units_ok(-kg, uc, 'kg', expr.NPV_NegationExpression)
# don't think there are combinations that fan "fail" for negation
# test AbsExpression, NPV_AbsExpression
self._get_check_units_ok(abs(kg*model.x), uc, 'kg', expr.AbsExpression)
self._get_check_units_ok(abs(kg), uc, 'kg', expr.NPV_AbsExpression)
# don't think there are combinations that fan "fail" for abs
# test the different UnaryFunctionExpression / NPV_UnaryFunctionExpression types
# log
self._get_check_units_ok(log(3.0*model.x), uc, None, expr.UnaryFunctionExpression)
self._get_check_units_fail(log(3.0*kg*model.x), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_ok(log(3.0*model.p), uc, None, expr.NPV_UnaryFunctionExpression)
self._get_check_units_fail(log(3.0*kg), uc, expr.NPV_UnaryFunctionExpression, UnitsError)
# log10
self._get_check_units_ok(log10(3.0*model.x), uc, None, expr.UnaryFunctionExpression)
self._get_check_units_fail(log10(3.0*kg*model.x), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_ok(log10(3.0*model.p), uc, None, expr.NPV_UnaryFunctionExpression)
self._get_check_units_fail(log10(3.0*kg), uc, expr.NPV_UnaryFunctionExpression, UnitsError)
# sin
self._get_check_units_ok(sin(3.0*model.x*uc.radians), uc, None, expr.UnaryFunctionExpression)
self._get_check_units_fail(sin(3.0*kg*model.x), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_fail(sin(3.0*kg*model.x*uc.kg), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_ok(sin(3.0*model.p*uc.radians), uc, None, expr.NPV_UnaryFunctionExpression)
self._get_check_units_fail(sin(3.0*kg), uc, expr.NPV_UnaryFunctionExpression, UnitsError)
# cos
self._get_check_units_ok(cos(3.0*model.x*uc.radians), uc, None, expr.UnaryFunctionExpression)
self._get_check_units_fail(cos(3.0*kg*model.x), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_fail(cos(3.0*kg*model.x*uc.kg), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_ok(cos(3.0*model.p*uc.radians), uc, None, expr.NPV_UnaryFunctionExpression)
self._get_check_units_fail(cos(3.0*kg), uc, expr.NPV_UnaryFunctionExpression, UnitsError)
# tan
self._get_check_units_ok(tan(3.0*model.x*uc.radians), uc, None, expr.UnaryFunctionExpression)
self._get_check_units_fail(tan(3.0*kg*model.x), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_fail(tan(3.0*kg*model.x*uc.kg), uc, expr.UnaryFunctionExpression, UnitsError)
self._get_check_units_ok(tan(3.0*model.p*uc.radians), uc, None, expr.NPV_UnaryFunctionExpression)
self._get_check_units_fail(tan(3.0*kg), uc, expr.NPV_UnaryFunctionExpression, UnitsError)
#.........这里部分代码省略.........