From dabf0ff4d726bc7d6d835fff50dcb3e1220e8b8f Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Fri, 13 Aug 2021 08:39:04 -0500 Subject: [PATCH] Add blacklist parameter to solver Enum members in this dictionary are disallowed by the solver. The types that can be blacklisted have been added to __all__ in solve.py. --- bonemarketsolver/solve.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bonemarketsolver/solve.py b/bonemarketsolver/solve.py index 2db1650..0aae1f5 100644 --- a/bonemarketsolver/solve.py +++ b/bonemarketsolver/solve.py @@ -1,6 +1,6 @@ """Use constraint programming to devise the optimal skeleton at the Bone Market in Fallen London.""" -__all__ = ['Buyer', 'Declaration', 'DiplomatFascination', 'Fluctuation', 'OccasionalBuyer', 'Solve'] +__all__ = ['Adjustment', 'Appendage', 'Buyer', 'Declaration', 'DiplomatFascination', 'Embellishment', 'Fluctuation', 'OccasionalBuyer', 'Skull', 'Solve', 'Torso'] __author__ = "Jeremy Saklad" from functools import reduce @@ -73,7 +73,7 @@ cp_model.CpModel.AddGeneralMultiplicationEquality = AddGeneralMultiplicationEqua del AddGeneralMultiplicationEquality -def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = None, occasional_buyer = None, diplomat_fascination = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), workers = cpu_count(), stdscr = None): +def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = None, occasional_buyer = None, diplomat_fascination = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), workers = cpu_count(), blacklist = [], stdscr = None): model = cp_model.CpModel() actions = {} @@ -129,6 +129,9 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non if desired_buyers: model.Add(cp_model.LinearExpr.Sum([actions[desired_buyer] for desired_buyer in desired_buyers]) == 1) + # Blacklist + model.Add(cp_model.LinearExpr.Sum([actions[forbidden] for forbidden in blacklist]) == 0) + # One torso model.Add(cp_model.LinearExpr.Sum([value for (key, value) in actions.items() if isinstance(key, Torso)]) == 1)