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


Python Options.type方法代码示例

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


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

示例1: Constraint

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import type [as 别名]
        return expr >= 1
    model.cover = Constraint(model.I, rule=cover_rule)

    #
    print_model_stats(model_options, model)
    return model

def test_model(options=None):
    model = pyomo_create_model(model_options=options)
    #print_model_stats(options, model)

if __name__ == '__main__':
    test_model()
    #
    options = Options()
    options.type = 'fixed_set_size'
    options.m = 11
    options.n = 21
    options.rho = 0.3
    test_model(options)
    #
    options = Options()
    options.type = 'fixed_element_coverage'
    test_model(options)
    #
    options = Options()
    options.m = 100
    options.n = 200
    options.type = 'fixed_probability'
    test_model(options)
    #
开发者ID:Pyomo,项目名称:pyomo,代码行数:33,代码来源:sc.py

示例2: pyomo_create_model

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import type [as 别名]
def pyomo_create_model(options=None, model_options=None):
    if model_options is None:
        model_options = Options()
    if model_options.type is None:
        model_options.type = 'fixed_set_size'
    #
    # m - number of elements
    #
    m = 100 if model_options.m is None else model_options.m
    #
    # n - number of sets
    #
    n = 200 if model_options.n is None else model_options.n
    seed = 9090 if model_options.seed is None else model_options.seed
    random.seed(9090)
    #
    if model_options.type == 'fixed_set_size':
        #
        # p   - fixed number elements per set
        # rho - fixed fraction of elements per set
        #
        p = model_options.p
        if p is None:
            if model_options.rho is None:
                p = int(math.ceil(m * 0.7))
            else:
                p = int(math.ceil(m * model_options.rho))
        #
        def S_rule(model):
            ans = set()
            for j in xrange(1,n+1):
                tmp = list(range(1,m+1))
                random.shuffle( tmp )
                for i in range(0,p):
                    ans.add( (tmp[i], j) )
            return ans
    elif model_options.type == 'fixed_element_coverage':
        #
        # p   - fixed number of sets that cover each element
        # rho - fixed fraction of sets that cover each element
        #
        p = model_options.p
        if p is None:
            if model_options.rho is None:
                p = int(math.ceil(n * 0.4))
            else:
                p = int(math.ceil(n * model_options.rho))
        #
        def S_rule(model):
            ans = set()
            for i in xrange(1,m+1):
                tmp = list(range(1,n+1))
                random.shuffle( tmp )
                for j in range(0,p):
                    ans.add( (i, tmp[j]) )
            return ans
    elif model_options.type == 'fixed_probability':
        #
        # rho - probability of selecting element for a set
        #
        rho = 0.3 if model_options.rho is None else model_options.rho
        #
        def S_rule(model):
            ans = set()
            for j in xrange(1,n+1):
                for i in xrange(1,m+1):
                    if random.uniform(0,1) < rho:
                        ans.add( (i, j) )
            return ans
    elif model_options.type == 'fixed_fill':
        #
        # rho - |S|/(I*J)
        #
        rho = 0.3 if model_options.rho is None else model_options.rho
        #
        def S_rule(model):
            ans = set()
            for j in xrange(1,n+1):
                for i in xrange(1,m+1):
                    if random.uniform(0,1) < rho:
                        ans.add( (i, j) )
            return ans
    #
    # CREATE MODEL
    #
    model = ConcreteModel()
    #
    # (i,j) in S if element i in set j
    #
    model.S = Set(dimen=2, initialize=S_rule)
    #
    # Dynamically create the I and J index sets, since
    # some rows or columns of S may not be populated.
    #
    def I_rule(model):
        return set((i for (i,j) in model.S))
    model.I = Set(initialize=I_rule)
    def J_rule(model):
        return set((j for (i,j) in model.S))
    model.J = Set(initialize=J_rule)
#.........这里部分代码省略.........
开发者ID:Pyomo,项目名称:pyomo,代码行数:103,代码来源:sc.py

示例3: print_model_stats

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import type [as 别名]
    #
    print_model_stats(model_options, model)
    return model


def test_model(options=None):
    model = pyomo_create_model(model_options=options)
    # print_model_stats(options, model)


if __name__ == "__main__":
    test_model()
    #
    options = Options()
    options.type = "fixed_set_size"
    options.m = 11
    options.n = 21
    options.rho = 0.3
    test_model(options)
    #
    options = Options()
    options.type = "fixed_element_coverage"
    test_model(options)
    #
    options = Options()
    options.m = 100
    options.n = 200
    options.type = "fixed_probability"
    test_model(options)
    #
开发者ID:qtothec,项目名称:pyomo,代码行数:32,代码来源:sc.py


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