本文整理汇总了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)
#
示例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)
#.........这里部分代码省略.........
示例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)
#