当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.index方法代码示例

本文整理汇总了Python中odict.OrderedDict.index方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.index方法的具体用法?Python OrderedDict.index怎么用?Python OrderedDict.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Model

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import index [as 别名]
class Model(object):

    def __init__(self):
        self.Identifiers = OrderedDict()
        self.Parameters = OrderedDict()
        self.Variables = OrderedDict()
        self.Equations = OrderedDict()
        self.DifferentialEquations = OrderedDict()
        self.Functions = OrderedDict()
        self.InitialValues = OrderedDict()
        self.Bounds = {}

        #---------Some builtin functions-------
        self.Functions['exp'] = [('math.exp')]
        self.Functions['log'] = [('math.log')]
        self.Functions['log10'] = [('math.log10')]
        self.Functions['pow'] = [('math.pow')]
        self.Functions['sqrt'] = [('math.sqrt')]


        self.Functions['sin'] = [('math.sin')]
        self.Functions['cos'] = [('math.cos')]
        self.Functions['tan'] = [('math.tan')]
        self.Functions['hypot'] = [('math.hypot')]

        self.Functions['asin'] = [('math.asin')]
        self.Functions['acos'] = [('math.acos')]
        self.Functions['atan'] = [('math.atan')]


        self.Functions['radians'] = [('math.radians')]
        self.Functions['degrees'] = [('math.degrees')]


    def addInitialValue(self, name, value):
        self.InitialValues[name] = value

    def addIdentifier(self, name):
        if name not in self.Identifiers.keys():
            self.Identifiers[name] = 'id_' + str(len(self.Identifiers)).zfill(3)

        return self.Identifiers[name]

    def addVariable(self, id):
        attrs_present, parts = has_attributes(id)
        if attrs_present:
            raise EquationSenseError, 'Cannot use attributes in equation'

        if not self.Variables.has_key(id):
            self.Variables[id] = 0.0

        return 'x[' + str(self.Variables.index(id)) + ']'

    def addEquation(self, LHS, RHS, eqn_id = None):
        if eqn_id is None:
            eqn_id = '#' + str(len(self.Equations) + 1)

        self.Equations[eqn_id] = (LHS, RHS)

    def addVariableBound(self, id, lower_bound, upper_bound):
        existing = self.Bounds.get(id, None)

        if existing:
            if lower_bound is not None:
                existing = (float(lower_bound), existing[1])
            if upper_bound is not None:
                existing = (existing[0], float(upper_bound))

            self.Bounds[id] = existing
        else:
            if lower_bound is not None:
                lower_bound = float(lower_bound)
            if upper_bound is not None:
                upper_bound = float(upper_bound)

            self.Bounds[id] = (lower_bound, upper_bound)


    def addParameter(self, id, value):

        attrs_present, parts = has_attributes(id)
        if attrs_present:
            actual_id = id.split('.')[0]
            parts = [p.lower() for p in parts]

            if len(parts) == 1 and 'guess' in parts:
                self.addInitialValue(actual_id, value)
            elif len(parts) == 1 and 'min' in parts:
                self.addVariableBound(actual_id, value, None)
            elif len(parts) == 1 and 'max' in parts:
                self.addVariableBound(actual_id, None, value)
            else:
                raise EquationSenseError, 'Only supports guess, min and max attributes'

        else:
            #Check if the id is in the variable map, if it is delete it
            #and place it in the parameters map

            #This happens when a parameters is defined after its use
            #in an equation
#.........这里部分代码省略.........
开发者ID:AndreLester,项目名称:xyzsolve,代码行数:103,代码来源:Model.py


注:本文中的odict.OrderedDict.index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。