From 74a3ab754bbe8d69faed936c0afd12a52cb01de9 Mon Sep 17 00:00:00 2001 From: vlkong Date: Tue, 10 Apr 2018 14:32:18 +0200 Subject: [PATCH] 2.6.93 --- examples/mp/modeling/diet.py | 12 ++++++++---- examples/mp/modeling/nurses.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/mp/modeling/diet.py b/examples/mp/modeling/diet.py index 2042c34..651562c 100644 --- a/examples/mp/modeling/diet.py +++ b/examples/mp/modeling/diet.py @@ -59,10 +59,11 @@ # ---------------------------------------------------------------------------- # Build the model # ---------------------------------------------------------------------------- + def build_diet_model(**kwargs): # Create tuples with named fields for foods and nutrients - food = [Food(*f) for f in FOODS] + foods = [Food(*f) for f in FOODS] nutrients = [Nutrient(*row) for row in NUTRIENTS] food_nutrients = {(fn[0], nutrients[n].name): @@ -72,23 +73,26 @@ def build_diet_model(**kwargs): mdl = Model(name='diet', **kwargs) # Decision variables, limited to be >= Food.qmin and <= Food.qmax - qty = {f: mdl.continuous_var(lb=f.qmin, ub=f.qmax, name=f.name) for f in food} + qty = mdl.continuous_var_dict(foods, lb=lambda f: f.qmin, ub=lambda f: f.qmax, name=lambda f: "q_%s" % f.name) # Limit range of nutrients, and mark them as KPIs for n in nutrients: - amount = mdl.sum(qty[f] * food_nutrients[f.name, n.name] for f in food) + amount = mdl.sum(qty[f] * food_nutrients[f.name, n.name] for f in foods) mdl.add_range(n.qmin, amount, n.qmax) mdl.add_kpi(amount, publish_name="Total %s" % n.name) # Minimize cost - mdl.minimize(mdl.sum(qty[f] * f.unit_cost for f in food)) + mdl.minimize(mdl.sum(qty[f] * f.unit_cost for f in foods)) mdl.print_information() + mdl.export_as_lp() return mdl # ---------------------------------------------------------------------------- # Solve the model and display the result # ---------------------------------------------------------------------------- + + if __name__ == '__main__': """DOcplexcloud credentials can be specified with url and api_key in the code block below. diff --git a/examples/mp/modeling/nurses.py b/examples/mp/modeling/nurses.py index 4f0603d..2157629 100644 --- a/examples/mp/modeling/nurses.py +++ b/examples/mp/modeling/nurses.py @@ -408,7 +408,7 @@ def setup_constraints(model): "high_required_{0!s}_{1!s}_{2!s}_{3!s}".format(dept, skill, required, dsh)) # nurse-nurse associations - # for each pair of associted nurses, their assignement variables are equal + # for each pair of associated nurses, their assignment variables are equal # over all shifts. c = 0 for (nurse_id1, nurse_id2) in model.nurse_associations: