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.
This commit is contained in:
Jeremy Saklad 2021-08-13 08:39:04 -05:00
parent cacb985be6
commit dabf0ff4d7
Signed by: Jeremy Saklad
GPG Key ID: 9CA2149583EDBF84
1 changed files with 5 additions and 2 deletions

View File

@ -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)