From 3d90d61debffc5948d324d4a4b20228b1d450fc0 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Wed, 22 Sep 2021 17:06:44 -0500 Subject: [PATCH] Replace helper functions with subclass The new subclass, BoneMarketModel, overrides CpModel's methods with improvements such as default parameters and support for enforcement literals. This should allow substantial improvements to the readability of the solver in the future. In addition, various lists have been replaced with tuples where appropriate. --- bonemarketsolver/objects/bone_market_model.py | 62 +++ bonemarketsolver/solve.py | 463 ++++++++---------- 2 files changed, 272 insertions(+), 253 deletions(-) create mode 100644 bonemarketsolver/objects/bone_market_model.py diff --git a/bonemarketsolver/objects/bone_market_model.py b/bonemarketsolver/objects/bone_market_model.py new file mode 100644 index 0000000..9a76161 --- /dev/null +++ b/bonemarketsolver/objects/bone_market_model.py @@ -0,0 +1,62 @@ +__author__ = "Jeremy Saklad" + +from functools import reduce + +from ortools.sat.python import cp_model + +class BoneMarketModel(cp_model.CpModel): + """A CpModel with additional functions for common constraints and enhanced enforcement literal support.""" + + __slots__ = () + + def AddAllowedAssignments(self, variables, tuples_list): + intermediate_variables, constraints = zip(*(self.NewIntermediateIntVar(variable, f'{repr((variables, tuples_list))}: {variable}') for variable in variables)) + super().AddAllowedAssignments(intermediate_variables, tuples_list) + return constraints + + def AddApproximateExponentiationEquality(self, target, var, exp, upto): + """Add an approximate exponentiation equality using a lookup table. + +Set `upto` to a value that is unlikely to come into play. + +Each parameter is interpreted as a BoundedLinearExpression, and a layer of indirection is applied such that each Constraint in the returned tuple can accept an enforcement literal.""" + return self.AddAllowedAssignments((target, var), ((int(base**exp), base) for base in range(upto + 1))) + + def AddMultiplicationEquality(self, target, variables): + """Adds `target == variables[0] * .. * variables[n]`. + +Each parameter is interpreted as a BoundedLinearExpression, and a layer of indirection is applied such that each Constraint in the returned tuple can accept an enforcement literal.""" + + superclass = super() + + def Multiply(end, stack): + intermediate_variable, variable_constraint = self.NewIntermediateIntVar(stack.pop(), f'{repr(end)} == {"*".join((repr(variable) for variable in stack))}: last variable') + + partial_target = self.NewIntVar(f'{repr(end)} == {"*".join((repr(variable) for variable in stack))}: partial target') + recursive_constraints = self.AddMultiplicationEquality(partial_target, stack) if len(stack) > 1 else (self.Add(partial_target == stack.pop()),) + + intermediate_target, target_constraint = self.NewIntermediateIntVar(end, f'{repr(end)} == {"*".join((repr(variable) for variable in stack))}: target') + + superclass.AddMultiplicationEquality(intermediate_target, (partial_target, intermediate_variable)) + + return (variable_constraint, *recursive_constraints, target_constraint) + + # Avoid mutating parameter directly + return Multiply(target, variables.copy() if isinstance(variables, list) else list(variables)) + + def NewIntermediateBoolVar(self, name, linear_exp, domain): + """Add a fully-reified implication using an intermediate Boolean variable.""" + + intermediate = self.NewBoolVar(name) + self.AddLinearExpressionInDomain(linear_exp, domain).OnlyEnforceIf(intermediate) + self.AddLinearExpressionInDomain(linear_exp, domain.Complement()).OnlyEnforceIf(intermediate.Not()) + return intermediate + + def NewIntermediateIntVar(self, linear_exp, name, *, lb = cp_model.INT_MIN//8, ub = cp_model.INT_MAX//8): + """Creates an integer variable equivalent to the given expression and returns a tuple consisting of the variable and constraint for use with enforcement literals.""" + + intermediate = super().NewIntVar(lb, ub, name) + return (intermediate, self.Add(intermediate == linear_exp)) + + def NewIntVar(self, name, *, lb = cp_model.INT32_MIN, ub = cp_model.INT32_MAX): + return super().NewIntVar(lb, ub, name) diff --git a/bonemarketsolver/solve.py b/bonemarketsolver/solve.py index b0c288c..c603298 100644 --- a/bonemarketsolver/solve.py +++ b/bonemarketsolver/solve.py @@ -3,7 +3,6 @@ __all__ = ['Adjustment', 'Appendage', 'Buyer', 'Declaration', 'DiplomatFascination', 'Embellishment', 'Fluctuation', 'OccasionalBuyer', 'Skull', 'Solve', 'Torso'] __author__ = "Jeremy Saklad" -from functools import reduce from os import cpu_count from ortools.sat.python import cp_model @@ -19,6 +18,7 @@ from .data.fluctuations import Fluctuation from .data.occasional_buyers import OccasionalBuyer from .data.skulls import Skull from .data.torsos import Torso +from .objects.bone_market_model import BoneMarketModel # This multiplier is applied to the profit margin to avoid losing precision due to rounding. PROFIT_MARGIN_MULTIPLIER = 10000000 @@ -30,51 +30,8 @@ MAXIMUM_ATTRIBUTE = 100 DIFFICULTY_SCALER = 0.6 -def NewIntermediateBoolVar(self, name, expression, domain): - """Add a fully-reified implication using an intermediate Boolean variable.""" - - intermediate = self.NewBoolVar(name) - self.AddLinearExpressionInDomain(expression, domain).OnlyEnforceIf(intermediate) - self.AddLinearExpressionInDomain(expression, domain.Complement()).OnlyEnforceIf(intermediate.Not()) - return intermediate - -cp_model.CpModel.NewIntermediateBoolVar = NewIntermediateBoolVar -del NewIntermediateBoolVar - - -def AddApproximateExponentiationEquality(self, target, var, exp, upto): - """Add an approximate exponentiation equality using a lookup table. - - Set `upto` to a value that is unlikely to come into play. - """ - return self.AddAllowedAssignments([target, var], [(int(base**exp), base) for base in range(upto + 1)]) - -cp_model.CpModel.AddApproximateExponentiationEquality = AddApproximateExponentiationEquality -del AddApproximateExponentiationEquality - - -def AddGeneralMultiplicationEquality(self, target, *variables): - """Add a multiplication equality for any number of terms using intermediate variables.""" - - # This is used for producing unique names for intermediate variables. - term_index = 1 - - def function(a, b): - nonlocal term_index - intermediate = self.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{target.Name()} term {term_index}') - term_index += 1 - self.AddMultiplicationEquality(intermediate, [a, b]) - return intermediate - - product = reduce(function, variables) - return self.Add(target == product) - -cp_model.CpModel.AddGeneralMultiplicationEquality = AddGeneralMultiplicationEquality -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(), blacklist = [], stdscr = None): - model = cp_model.CpModel() + model = BoneMarketModel() actions = {} @@ -84,20 +41,20 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Skull for skull in Skull: - actions[skull] = model.NewIntVar(0, cp_model.INT32_MAX, skull.value.name) + actions[skull] = model.NewIntVar(skull.value.name, lb = 0) # Appendage for appendage in Appendage: if appendage == Appendage.SKIP_TAILS: actions[appendage] = model.NewBoolVar(appendage.value.name) else: - actions[appendage] = model.NewIntVar(0, cp_model.INT32_MAX, appendage.value.name) + actions[appendage] = model.NewIntVar(appendage.value.name, lb = 0) # Avoid adding joints at first model.AddHint(actions[Appendage.ADD_JOINTS], 0) # Adjustment for adjustment in Adjustment: - actions[adjustment] = model.NewIntVar(0, cp_model.INT32_MAX, adjustment.value.name) + actions[adjustment] = model.NewIntVar(adjustment.value.name, lb = 0) # Declaration for declaration in Declaration: @@ -107,7 +64,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Embellishment for embellishment in Embellishment: - actions[embellishment] = model.NewIntVar(0, cp_model.INT32_MAX, embellishment.value.name) + actions[embellishment] = model.NewIntVar(embellishment.value.name, lb = 0) # Buyer @@ -144,19 +101,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Value calculation - value = model.NewIntVar(0, cp_model.INT32_MAX, 'value') + value = model.NewIntVar('value', lb = 0) - base_value = model.NewIntVar(0, cp_model.INT32_MAX, 'base value') + base_value = model.NewIntVar('base value', lb = 0) model.Add(base_value == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.value for action in actions.keys()])) # Calculate value from Vake skulls # This is a partial sum formula. - vake_skull_value = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'vake skull value') + vake_skull_value = model.NewIntVar('vake skull value') vake_skulls = actions[Skull.VAKE_SKULL] - vake_skulls_squared = model.NewIntVar(0, cp_model.INT32_MAX, 'vake skulls squared') - model.AddMultiplicationEquality(vake_skulls_squared, [vake_skulls, vake_skulls]) + vake_skulls_squared = model.NewIntVar('vake skulls squared', lb = 0) + model.AddMultiplicationEquality(vake_skulls_squared, (vake_skulls, vake_skulls)) model.Add(vake_skull_value == -250 * vake_skulls_squared + 6750 * vake_skulls) @@ -167,12 +124,12 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non del base_value, vake_skull_value # Zoological Mania - zoological_mania_bonus = model.NewIntVar(0, cp_model.INT32_MAX, 'zoological mania bonus') + zoological_mania_bonus = model.NewIntVar('zoological mania bonus', lb = 0) if zoological_mania: multiplier = 15 if zoological_mania in [Declaration.FISH, Declaration.INSECT, Declaration.SPIDER] else 10 - potential_zoological_mania_bonus = model.NewIntVar(0, cp_model.INT32_MAX, 'potential zoological mania bonus') - multiplied_value = model.NewIntVar(0, cp_model.INT32_MAX, 'multiplied value') + potential_zoological_mania_bonus = model.NewIntVar('potential zoological mania bonus', lb = 0) + multiplied_value = model.NewIntVar('multiplied value', lb = 0) model.Add(multiplied_value == multiplier*value) model.AddDivisionEquality(potential_zoological_mania_bonus, multiplied_value, 100) model.Add(zoological_mania_bonus == potential_zoological_mania_bonus).OnlyEnforceIf(actions[zoological_mania]) @@ -189,52 +146,52 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(torso_style == torso.value.torso_style).OnlyEnforceIf(torso_variable) # Skulls calculation - skulls = model.NewIntVar(0, cp_model.INT32_MAX, 'skulls') + skulls = model.NewIntVar('skulls', lb = 0) model.Add(skulls == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.skulls for action in actions.keys()])) # Arms calculation - arms = model.NewIntVar(0, cp_model.INT32_MAX, 'arms') + arms = model.NewIntVar('arms', lb = 0) model.Add(arms == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.arms for action in actions.keys()])) # Legs calculation - legs = model.NewIntVar(0, cp_model.INT32_MAX, 'legs') + legs = model.NewIntVar('legs', lb = 0) model.Add(legs == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.legs for action in actions.keys()])) # Tails calculation - tails = model.NewIntVar(0, cp_model.INT32_MAX, 'tails') + tails = model.NewIntVar('tails', lb = 0) model.Add(tails == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.tails for action in actions.keys()])) # Wings calculation - wings = model.NewIntVar(0, cp_model.INT32_MAX, 'wings') + wings = model.NewIntVar('wings', lb = 0) model.Add(wings == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.wings for action in actions.keys()])) # Fins calculation - fins = model.NewIntVar(0, cp_model.INT32_MAX, 'fins') + fins = model.NewIntVar('fins', lb = 0) model.Add(fins == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.fins for action in actions.keys()])) # Tentacles calculation - tentacles = model.NewIntVar(0, cp_model.INT32_MAX, 'tentacles') + tentacles = model.NewIntVar('tentacles', lb = 0) model.Add(tentacles == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.tentacles for action in actions.keys()])) # Amalgamy calculation - amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'amalgamy') + amalgamy = model.NewIntVar('amalgamy') model.Add(amalgamy == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.amalgamy for action in actions.keys()])) # Antiquity calculation - antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'antiquity') + antiquity = model.NewIntVar('antiquity') model.Add(antiquity == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.antiquity for action in actions.keys()])) # Menace calculation - menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'menace') + menace = model.NewIntVar('menace') - constant_base_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'constant base menace') + constant_base_menace = model.NewIntVar('constant base menace') model.Add(constant_base_menace == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.menace for action in actions.keys()])) # Calculate menace from Vake skulls vake_skull_bonus_menace = model.NewIntVarFromDomain(cp_model.Domain.FromValues([0, 2, 3]), 'vake skull bonus menace') - vake_skulls_times_two = model.NewIntVar(0, cp_model.INT32_MAX, 'vake skulls times two') - model.AddMultiplicationEquality(vake_skulls_times_two, [2, actions[Skull.VAKE_SKULL]]) + vake_skulls_times_two = model.NewIntVar('vake skulls times two', lb = 0) + model.AddMultiplicationEquality(vake_skulls_times_two, (2, actions[Skull.VAKE_SKULL])) model.AddMinEquality(vake_skull_bonus_menace, [vake_skulls_times_two, 3]) del vake_skulls_times_two @@ -244,23 +201,23 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Implausibility calculation - implausibility = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'implausibility') + implausibility = model.NewIntVar('implausibility') - constant_base_implausibility = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'implausibility') + constant_base_implausibility = model.NewIntVar('implausibility') model.Add(constant_base_implausibility == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.implausibility for action in actions.keys()])) # Calculate implausibility from Vake skulls # This is a partial sum formula. - vake_skull_implausibility = model.NewIntVar(0, cp_model.INT32_MAX, 'vake skull implausibility') + vake_skull_implausibility = model.NewIntVar('vake skull implausibility', lb = 0) - vake_skull_implausibility_numerator = model.NewIntVar(0, cp_model.INT32_MAX, 'vake skull implausibility numerator') + vake_skull_implausibility_numerator = model.NewIntVar('vake skull implausibility numerator', lb = 0) vake_skulls = actions[Skull.VAKE_SKULL] - vake_skull_implausibility_numerator_second_term = model.NewIntVar(0, cp_model.INT32_MAX, 'vake skull implausibility numerator second term') - model.AddMultiplicationEquality(vake_skull_implausibility_numerator_second_term, [vake_skulls, vake_skulls]) + vake_skull_implausibility_numerator_second_term = model.NewIntVar('vake skull implausibility numerator second term', lb = 0) + model.AddMultiplicationEquality(vake_skull_implausibility_numerator_second_term, (vake_skulls, vake_skulls)) - vake_skull_implausibility_numerator_third_term = model.NewIntVar(0, 1, 'vake skull implausibility numerator third term') + vake_skull_implausibility_numerator_third_term = model.NewIntVar('vake skull implausibility numerator third term', lb = 0, ub = 1) model.AddModuloEquality(vake_skull_implausibility_numerator_third_term, vake_skulls, 2) model.Add(vake_skull_implausibility_numerator == -2 * vake_skulls + vake_skull_implausibility_numerator_second_term + vake_skull_implausibility_numerator_third_term) @@ -279,44 +236,44 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Counter-church calculation # Calculate amount of Counter-church from Holy Relics of the Thigh of Saint Fiacre holy_relic = actions[Appendage.FIACRE_THIGH] - torso_style_divided_by_ten = model.NewIntVar(0, cp_model.INT32_MAX, 'torso style divided by ten') + torso_style_divided_by_ten = model.NewIntVar('torso style divided by ten', lb = 0) model.AddDivisionEquality(torso_style_divided_by_ten, torso_style, 10) - holy_relic_counter_church = model.NewIntVar(0, cp_model.INT32_MAX, 'holy relic counter-church') - model.AddMultiplicationEquality(holy_relic_counter_church, [holy_relic, torso_style_divided_by_ten]) + holy_relic_counter_church = model.NewIntVar('holy relic counter-church', lb = 0) + model.AddMultiplicationEquality(holy_relic_counter_church, (holy_relic, torso_style_divided_by_ten)) - counter_church = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'counter-church') + counter_church = model.NewIntVar('counter-church') model.Add(counter_church == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.counter_church for action in actions.keys()]) + holy_relic_counter_church) del holy_relic, torso_style_divided_by_ten, holy_relic_counter_church # Exhaustion calculation - exhaustion = model.NewIntVar(0, maximum_exhaustion, 'exhaustion') + exhaustion = model.NewIntVar('exhaustion', lb = 0, ub = maximum_exhaustion) # Exhaustion added by certain buyers - added_exhaustion = model.NewIntVar(0, maximum_exhaustion, 'added exhaustion') + added_exhaustion = model.NewIntVar('added exhaustion', lb = 0, ub = maximum_exhaustion) model.Add(exhaustion == cp_model.LinearExpr.ScalProd(actions.values(), [action.value.exhaustion for action in actions.keys()]) + added_exhaustion) # Profit intermediate variables - primary_revenue = model.NewIntVar(0, cp_model.INT32_MAX, 'primary revenue') - secondary_revenue = model.NewIntVar(0, cp_model.INT32_MAX, 'secondary revenue') - total_revenue = model.NewIntVar(0, cp_model.INT32_MAX*2, 'total revenue') + primary_revenue = model.NewIntVar('primary revenue', lb = 0) + secondary_revenue = model.NewIntVar('secondary revenue', lb = 0) + total_revenue = model.NewIntVar('total revenue', lb = 0) model.Add(total_revenue == cp_model.LinearExpr.Sum([primary_revenue, secondary_revenue])) # Cost # Calculate value of actions needed to sell the skeleton. - difficulty_level = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'difficulty level') + difficulty_level = model.NewIntVar('difficulty level') - non_zero_difficulty_level = model.NewIntVar(1, cp_model.INT32_MAX, 'non-zero difficulty level') + non_zero_difficulty_level = model.NewIntVar('non-zero difficulty level', lb = 1) model.AddMaxEquality(non_zero_difficulty_level, [difficulty_level, 1]) - sale_actions_times_action_value = model.NewIntVar(0, cp_model.INT32_MAX, 'sale actions times action value') + sale_actions_times_action_value = model.NewIntVar('sale actions times action value', lb = 0) model.AddDivisionEquality(sale_actions_times_action_value, model.NewConstant(round(DIFFICULTY_SCALER*shadowy_level*Cost.ACTION.value)), non_zero_difficulty_level) - abstract_sale_cost = model.NewIntVar(0, cp_model.INT32_MAX, 'abstract sale cost') + abstract_sale_cost = model.NewIntVar('abstract sale cost', lb = 0) model.AddDivisionEquality(abstract_sale_cost, Cost.ACTION.value**2, sale_actions_times_action_value) - sale_cost = model.NewIntVar(0, cp_model.INT32_MAX, 'sale cost') + sale_cost = model.NewIntVar('sale cost', lb = 0) model.AddMaxEquality(sale_cost, [abstract_sale_cost, Cost.ACTION.value]) del non_zero_difficulty_level, sale_actions_times_action_value, abstract_sale_cost @@ -324,52 +281,52 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Calculate cost of adding joints # This is a partial sum formula. - add_joints_amber_cost = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost') + add_joints_amber_cost = model.NewIntVar('add joints amber cost', lb = 0) add_joints = actions[Appendage.ADD_JOINTS] - base_joints = model.NewIntVar(0, cp_model.INT32_MAX, 'base joints') + base_joints = model.NewIntVar('base joints', lb = 0) model.Add(base_joints == cp_model.LinearExpr.ScalProd([value for (key, value) in actions.items() if isinstance(key, Torso)], [torso.value.limbs_needed + torso.value.arms + torso.value.legs + torso.value.wings + torso.value.fins + torso.value.tentacles for torso in Torso])) - add_joints_amber_cost_multiple = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple') + add_joints_amber_cost_multiple = model.NewIntVar('add joints amber cost multiple', lb = 0) - add_joints_amber_cost_multiple_first_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple first term') - model.AddGeneralMultiplicationEquality(add_joints_amber_cost_multiple_first_term, 25, base_joints, base_joints, add_joints) + add_joints_amber_cost_multiple_first_term = model.NewIntVar('add joints amber cost multiple first term', lb = 0) + model.AddMultiplicationEquality(add_joints_amber_cost_multiple_first_term, (25, base_joints, base_joints, add_joints)) - add_joints_amber_cost_multiple_second_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple second term') - model.AddGeneralMultiplicationEquality(add_joints_amber_cost_multiple_second_term, 100, base_joints, add_joints, add_joints) + add_joints_amber_cost_multiple_second_term = model.NewIntVar('add joints amber cost multiple second term', lb = 0) + model.AddMultiplicationEquality(add_joints_amber_cost_multiple_second_term, (100, base_joints, add_joints, add_joints)) - add_joints_amber_cost_multiple_third_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple third term') - model.AddGeneralMultiplicationEquality(add_joints_amber_cost_multiple_third_term, 100, base_joints, add_joints) + add_joints_amber_cost_multiple_third_term = model.NewIntVar('add joints amber cost multiple third term', lb = 0) + model.AddMultiplicationEquality(add_joints_amber_cost_multiple_third_term, (100, base_joints, add_joints)) - add_joints_amber_cost_multiple_fourth_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple fourth term') - add_joints_amber_cost_multiple_fourth_term_numerator = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple fourth term numerator') - add_joints_amber_cost_multiple_fourth_term_numerator_first_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple fourth term numerator first term') - model.AddGeneralMultiplicationEquality(add_joints_amber_cost_multiple_fourth_term_numerator_first_term, 400, add_joints, add_joints, add_joints) + add_joints_amber_cost_multiple_fourth_term = model.NewIntVar('add joints amber cost multiple fourth term', lb = 0) + add_joints_amber_cost_multiple_fourth_term_numerator = model.NewIntVar('add joints amber cost multiple fourth term numerator', lb = 0) + add_joints_amber_cost_multiple_fourth_term_numerator_first_term = model.NewIntVar('add joints amber cost multiple fourth term numerator first term', lb = 0) + model.AddMultiplicationEquality(add_joints_amber_cost_multiple_fourth_term_numerator_first_term, (400, add_joints, add_joints, add_joints)) model.Add(add_joints_amber_cost_multiple_fourth_term_numerator == add_joints_amber_cost_multiple_fourth_term_numerator_first_term + 200*add_joints) model.AddDivisionEquality(add_joints_amber_cost_multiple_fourth_term, add_joints_amber_cost_multiple_fourth_term_numerator, 3) del add_joints_amber_cost_multiple_fourth_term_numerator, add_joints_amber_cost_multiple_fourth_term_numerator_first_term - add_joints_amber_cost_multiple_fifth_term = model.NewIntVar(0, cp_model.INT32_MAX, 'add joints amber cost multiple fifth term') - model.AddGeneralMultiplicationEquality(add_joints_amber_cost_multiple_fifth_term, 200, add_joints, add_joints) + add_joints_amber_cost_multiple_fifth_term = model.NewIntVar('add joints amber cost multiple fifth term', lb = 0) + model.AddMultiplicationEquality(add_joints_amber_cost_multiple_fifth_term, (200, add_joints, add_joints)) model.Add(add_joints_amber_cost_multiple == add_joints_amber_cost_multiple_first_term + add_joints_amber_cost_multiple_second_term - add_joints_amber_cost_multiple_third_term + add_joints_amber_cost_multiple_fourth_term - add_joints_amber_cost_multiple_fifth_term) del add_joints_amber_cost_multiple_first_term, add_joints_amber_cost_multiple_second_term, add_joints_amber_cost_multiple_third_term, add_joints_amber_cost_multiple_fourth_term, add_joints_amber_cost_multiple_fifth_term - model.AddGeneralMultiplicationEquality(add_joints_amber_cost, add_joints_amber_cost_multiple, Cost.WARM_AMBER.value) + model.AddMultiplicationEquality(add_joints_amber_cost, (add_joints_amber_cost_multiple, Cost.WARM_AMBER.value)) del add_joints, add_joints_amber_cost_multiple - cost = model.NewIntVar(0, maximum_cost, 'cost') + cost = model.NewIntVar('cost', lb = 0, ub = maximum_cost) model.Add(cost == cp_model.LinearExpr.ScalProd(actions.values(), [int(action.value.cost) for action in actions.keys()]) + add_joints_amber_cost + sale_cost) del sale_cost, add_joints_amber_cost # Type of skeleton - skeleton_in_progress = model.NewIntVar(0, cp_model.INT32_MAX, 'skeleton in progress') + skeleton_in_progress = model.NewIntVar('skeleton in progress', lb = 0) # Chimera model.Add(skeleton_in_progress == 100) \ @@ -581,10 +538,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # A Naive Collector model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_NAIVE_COLLECTOR]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_NAIVE_COLLECTOR.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_NAIVE_COLLECTOR.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 249, f'{Buyer.A_NAIVE_COLLECTOR.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_NAIVE_COLLECTOR.name}: total value remainder', lb = 0, ub = 249) model.AddModuloEquality(total_value_remainder, total_value, 250) model.Add(primary_revenue == total_value - total_value_remainder).OnlyEnforceIf(actions[Buyer.A_NAIVE_COLLECTOR]) @@ -601,10 +558,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS]) model.Add(antiquity <= 0).OnlyEnforceIf(actions[Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 249, f'{Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS.name}: total value remainder', lb = 0, ub = 249) model.AddModuloEquality(total_value_remainder, total_value, 250) model.Add(primary_revenue == total_value - total_value_remainder + 1000).OnlyEnforceIf(actions[Buyer.A_FAMILIAR_BOHEMIAN_SCULPTRESS]) @@ -621,10 +578,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER]) model.Add(menace <= 0).OnlyEnforceIf(actions[Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 1000).OnlyEnforceIf(actions[Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER]) @@ -641,10 +598,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL]) model.Add(amalgamy <= 0).OnlyEnforceIf(actions[Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 249, f'{Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL.name}: total value remainder', lb = 0, ub = 249) model.AddModuloEquality(total_value_remainder, total_value, 250) model.Add(primary_revenue == total_value - total_value_remainder + 1000).OnlyEnforceIf(actions[Buyer.A_THEOLOGIAN_OF_THE_OLD_SCHOOL]) @@ -661,10 +618,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_OF_THE_ANCIENT_WORLD]) model.Add(antiquity > 0).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_OF_THE_ANCIENT_WORLD]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_PEDAGOGICALLY_INCLINED_GRANDMOTHER.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.AN_ENTHUSIAST_OF_THE_ANCIENT_WORLD.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.AN_ENTHUSIAST_OF_THE_ANCIENT_WORLD.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_OF_THE_ANCIENT_WORLD]) @@ -681,10 +638,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.MRS_PLENTY]) model.Add(menace > 0).OnlyEnforceIf(actions[Buyer.MRS_PLENTY]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.MRS_PLENTY.name}: total value') + total_value = model.NewIntVar(f'{Buyer.MRS_PLENTY.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.MRS_PLENTY.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.MRS_PLENTY.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder).OnlyEnforceIf(actions[Buyer.MRS_PLENTY]) @@ -701,10 +658,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_TENTACLED_SERVANT]) model.Add(amalgamy > 0).OnlyEnforceIf(actions[Buyer.A_TENTACLED_SERVANT]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_SERVANT.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_TENTACLED_SERVANT.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_TENTACLED_SERVANT.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_TENTACLED_SERVANT.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 250).OnlyEnforceIf(actions[Buyer.A_TENTACLED_SERVANT]) @@ -721,31 +678,31 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) model.Add(antiquity > 0).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) - antiquity_squared_times_four_fifths = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: antiquity squared times four-fifths') - antiquity_squared_times_four = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: antiquity squared times four') - model.AddGeneralMultiplicationEquality(antiquity_squared_times_four, antiquity, antiquity, 4) + antiquity_squared_times_four_fifths = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: antiquity squared times four-fifths', lb = 0) + antiquity_squared_times_four = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: antiquity squared times four', lb = 0) + model.AddMultiplicationEquality(antiquity_squared_times_four, (antiquity, antiquity, 4)) model.AddDivisionEquality(antiquity_squared_times_four_fifths, antiquity_squared_times_four, 5) del antiquity_squared_times_four - tailfeathers = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: tailfeathers') + tailfeathers = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: tailfeathers') if bone_market_fluctuations == Fluctuation.ANTIQUITY: - boosted_antiquity = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity') + boosted_antiquity = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity', lb = 0) model.AddApproximateExponentiationEquality(boosted_antiquity, antiquity, 2.1, MAXIMUM_ATTRIBUTE) - boosted_antiquity_times_four = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity times four') - model.AddMultiplicationEquality(boosted_antiquity_times_four, [boosted_antiquity, 4]) - boosted_antiquity_times_four_fifths = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity times four-fifths') + boosted_antiquity_times_four = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity times four', lb = 0) + model.AddMultiplicationEquality(boosted_antiquity_times_four, (boosted_antiquity, 4)) + boosted_antiquity_times_four_fifths = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: boosted antiquity times four-fifths', lb = 0) model.AddDivisionEquality(boosted_antiquity_times_four_fifths, boosted_antiquity_times_four, 5) model.Add(tailfeathers == boosted_antiquity_times_four_fifths).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) del boosted_antiquity, boosted_antiquity_times_four, boosted_antiquity_times_four_fifths else: model.Add(tailfeathers == antiquity_squared_times_four_fifths).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: total value') + total_value = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) - extra_value = model.NewIntermediateBoolVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: extra value', total_value_remainder, cp_model.Domain.FromFlatIntervals([0, cp_model.INT_MAX])) + extra_value = model.NewIntermediateBoolVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: extra value', total_value_remainder, cp_model.Domain.FromFlatIntervals([0, cp_model.INT32_MAX])) model.Add(primary_revenue == total_value + 50*extra_value + 250).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) model.Add(secondary_revenue == 250*tailfeathers).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) @@ -753,7 +710,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.AN_INVESTMENT_MINDED_AMBASSADOR.name}: derived exhaustion', lb = 0) model.AddDivisionEquality(derived_exhaustion, antiquity_squared_times_four_fifths, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.AN_INVESTMENT_MINDED_AMBASSADOR]) @@ -764,22 +721,22 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) model.Add(menace > 0).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) - menace_squared = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TELLER_OF_TERRORS.name}: menace squared') - model.AddMultiplicationEquality(menace_squared, [menace, menace]) + menace_squared = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: menace squared', lb = 0) + model.AddMultiplicationEquality(menace_squared, (menace, menace)) - feathers = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_TELLER_OF_TERRORS.name}: feathers') + feathers = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: feathers') if bone_market_fluctuations == Fluctuation.MENACE: - boosted_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_TELLER_OF_TERRORS.name}: boosted menace') + boosted_menace = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: boosted menace') model.AddApproximateExponentiationEquality(boosted_menace, menace, 2.1, MAXIMUM_ATTRIBUTE) model.Add(feathers == 4*boosted_menace).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) del boosted_menace else: model.Add(feathers == 4*menace_squared).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TELLER_OF_TERRORS.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 9, f'{Buyer.A_TELLER_OF_TERRORS.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: total value remainder', lb = 0, ub = 9) model.AddModuloEquality(total_value_remainder, total_value, 10) model.Add(primary_revenue == total_value - total_value_remainder + 50).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) @@ -788,7 +745,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TELLER_OF_TERRORS.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_TELLER_OF_TERRORS.name}: derived exhaustion', lb = 0) model.AddDivisionEquality(derived_exhaustion, menace_squared, 25) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_TELLER_OF_TERRORS]) @@ -799,22 +756,22 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) model.Add(amalgamy > 0).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) - amalgamy_squared = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: amalgamy squared') - model.AddMultiplicationEquality(amalgamy_squared, [amalgamy, amalgamy]) + amalgamy_squared = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: amalgamy squared', lb = 0) + model.AddMultiplicationEquality(amalgamy_squared, (amalgamy, amalgamy)) - final_breaths = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: final breaths') + final_breaths = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: final breaths') if bone_market_fluctuations == Fluctuation.AMALGAMY: - boosted_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: boosted amalgamy') + boosted_amalgamy = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: boosted amalgamy') model.AddApproximateExponentiationEquality(boosted_amalgamy, amalgamy, 2.1, MAXIMUM_ATTRIBUTE) model.Add(final_breaths == 4*boosted_amalgamy).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) del boosted_amalgamy else: model.Add(final_breaths == 4*amalgamy_squared).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 250).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) @@ -823,7 +780,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_TENTACLED_ENTREPRENEUR.name}: derived exhaustion', lb = 0) model.AddDivisionEquality(derived_exhaustion, amalgamy_squared, 25) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_TENTACLED_ENTREPRENEUR]) @@ -835,19 +792,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(antiquity > 0).OnlyEnforceIf(actions[Buyer.AN_AUTHOR_OF_GOTHIC_TALES]) model.Add(menace > 0).OnlyEnforceIf(actions[Buyer.AN_AUTHOR_OF_GOTHIC_TALES]) - antiquity_times_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: antiquity times menace') - model.AddMultiplicationEquality(antiquity_times_menace, [antiquity, menace]) + antiquity_times_menace = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: antiquity times menace') + model.AddMultiplicationEquality(antiquity_times_menace, (antiquity, menace)) - antiquity_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: antiquity fluctuation bonus') + antiquity_fluctuation_bonus = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: antiquity fluctuation bonus') model.AddDivisionEquality(antiquity_fluctuation_bonus, antiquity, 2) - menace_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: menace fluctuation bonus') + menace_fluctuation_bonus = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: menace fluctuation bonus') model.AddDivisionEquality(menace_fluctuation_bonus, menace, 2) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: total value') + total_value = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 250).OnlyEnforceIf(actions[Buyer.AN_AUTHOR_OF_GOTHIC_TALES]) @@ -856,7 +813,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.AN_AUTHOR_OF_GOTHIC_TALES]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.AN_AUTHOR_OF_GOTHIC_TALES.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, antiquity_times_menace, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.AN_AUTHOR_OF_GOTHIC_TALES]) @@ -868,19 +825,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(antiquity > 0).OnlyEnforceIf(actions[Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS]) model.Add(amalgamy > 0).OnlyEnforceIf(actions[Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS]) - amalgamy_times_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: amalgamy times antiquity') - model.AddMultiplicationEquality(amalgamy_times_antiquity, [amalgamy, antiquity]) + amalgamy_times_antiquity = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: amalgamy times antiquity') + model.AddMultiplicationEquality(amalgamy_times_antiquity, (amalgamy, antiquity)) - amalgamy_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: amalgamy fluctuation bonus') + amalgamy_fluctuation_bonus = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: amalgamy fluctuation bonus') model.AddDivisionEquality(amalgamy_fluctuation_bonus, amalgamy, 2) - antiquity_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: antiquity fluctuation bonus') + antiquity_fluctuation_bonus = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: antiquity fluctuation bonus') model.AddDivisionEquality(antiquity_fluctuation_bonus, antiquity, 2) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 9, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: total value remainder', lb = 0, ub = 9) model.AddModuloEquality(total_value_remainder, total_value, 10) model.Add(primary_revenue == total_value - total_value_remainder + 250).OnlyEnforceIf(actions[Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS]) @@ -889,7 +846,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, amalgamy_times_antiquity, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_ZAILOR_WITH_PARTICULAR_INTERESTS]) @@ -901,19 +858,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(amalgamy > 0).OnlyEnforceIf(actions[Buyer.A_RUBBERY_COLLECTOR]) model.Add(menace > 0).OnlyEnforceIf(actions[Buyer.A_RUBBERY_COLLECTOR]) - amalgamy_times_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_RUBBERY_COLLECTOR.name}: amalgamy times menace') - model.AddMultiplicationEquality(amalgamy_times_menace, [amalgamy, menace]) + amalgamy_times_menace = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: amalgamy times menace') + model.AddMultiplicationEquality(amalgamy_times_menace, (amalgamy, menace)) - amalgamy_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_RUBBERY_COLLECTOR.name}: amalgamy fluctuation bonus') + amalgamy_fluctuation_bonus = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: amalgamy fluctuation bonus') model.AddDivisionEquality(amalgamy_fluctuation_bonus, amalgamy, 2) - menace_fluctuation_bonus = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_RUBBERY_COLLECTOR.name}: menace fluctuation bonus') + menace_fluctuation_bonus = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: menace fluctuation bonus') model.AddDivisionEquality(menace_fluctuation_bonus, menace, 2) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_RUBBERY_COLLECTOR.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_RUBBERY_COLLECTOR.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 250).OnlyEnforceIf(actions[Buyer.A_RUBBERY_COLLECTOR]) @@ -922,7 +879,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 75*implausibility).OnlyEnforceIf(actions[Buyer.A_RUBBERY_COLLECTOR]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_RUBBERY_COLLECTOR.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_RUBBERY_COLLECTOR.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, amalgamy_times_menace, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_RUBBERY_COLLECTOR]) @@ -932,7 +889,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # A Constable model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([110, 119])).OnlyEnforceIf(actions[Buyer.A_CONSTABLE]) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_CONSTABLE.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.A_CONSTABLE.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 1000).OnlyEnforceIf(actions[Buyer.A_CONSTABLE]) @@ -949,9 +906,9 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) model.Add(skulls >= 2).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) - extra_skulls = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: extra skulls') + extra_skulls = model.NewIntVar(f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: extra skulls', lb = 0) model.Add(extra_skulls == skulls - 1).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) - vital_intelligence = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: vital intelligence') + vital_intelligence = model.NewIntVar(f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: vital intelligence') model.AddApproximateExponentiationEquality(vital_intelligence, extra_skulls, 1.8, MAXIMUM_ATTRIBUTE) model.Add(primary_revenue == value + zoological_mania_bonus).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) @@ -960,7 +917,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 60*implausibility).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.AN_ENTHUSIAST_IN_SKULLS.name}: derived exhaustion', lb = 0) model.AddDivisionEquality(derived_exhaustion, vital_intelligence, 4) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.AN_ENTHUSIAST_IN_SKULLS]) @@ -972,10 +929,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(amalgamy <= 0).OnlyEnforceIf(actions[Buyer.A_DREARY_MIDNIGHTER]) model.Add(counter_church <= 0).OnlyEnforceIf(actions[Buyer.A_DREARY_MIDNIGHTER]) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_DREARY_MIDNIGHTER.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_DREARY_MIDNIGHTER.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 2, f'{Buyer.A_DREARY_MIDNIGHTER.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_DREARY_MIDNIGHTER.name}: total value remainder', lb = 0, ub = 2) model.AddModuloEquality(total_value_remainder, total_value, 3) model.Add(primary_revenue == total_value - total_value_remainder + 300).OnlyEnforceIf(actions[Buyer.A_DREARY_MIDNIGHTER]) @@ -993,16 +950,16 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(implausibility >= 2).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE]) model.Add(amalgamy >= 4).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE]) - amalgamy_times_implausibility = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: amalgamy times implausibility') - model.AddMultiplicationEquality(amalgamy_times_implausibility, [amalgamy, implausibility]) + amalgamy_times_implausibility = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: amalgamy times implausibility') + model.AddMultiplicationEquality(amalgamy_times_implausibility, (amalgamy, implausibility)) - bazaarine_poetry = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: bazaarine poetry') + bazaarine_poetry = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: bazaarine poetry') model.Add(bazaarine_poetry == amalgamy_times_implausibility + 1) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 100).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE]) @@ -1011,7 +968,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, bazaarine_poetry, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_BAZAARINE]) @@ -1023,16 +980,16 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(implausibility >= 2).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL]) model.Add(menace >= 4).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL]) - menace_times_implausibility = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: menace times implausibility') - model.AddMultiplicationEquality(menace_times_implausibility, [menace, implausibility]) + menace_times_implausibility = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: menace times implausibility') + model.AddMultiplicationEquality(menace_times_implausibility, (menace, implausibility)) - stygian_ivory = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: stygian ivory') + stygian_ivory = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: stygian ivory') model.Add(stygian_ivory == menace_times_implausibility + 1) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 100).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL]) @@ -1041,7 +998,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, stygian_ivory, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_NOCTURNAL]) @@ -1053,16 +1010,16 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(implausibility >= 2).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL]) model.Add(antiquity >= 4).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL]) - antiquity_times_implausibility = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: antiquity times implausibility') - model.AddMultiplicationEquality(antiquity_times_implausibility, [antiquity, implausibility]) + antiquity_times_implausibility = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: antiquity times implausibility') + model.AddMultiplicationEquality(antiquity_times_implausibility, (antiquity, implausibility)) - knob_of_scintillack = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: knob of scintillack') + knob_of_scintillack = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: knob of scintillack') model.Add(knob_of_scintillack == antiquity_times_implausibility + 1) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: total value') + total_value = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder + 100).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL]) @@ -1071,7 +1028,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, knob_of_scintillack, 20) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.A_COLOURFUL_PHANTASIST_CELESTIAL]) @@ -1082,13 +1039,13 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(tentacles >= 4).OnlyEnforceIf(actions[Buyer.AN_INGENUOUS_MALACOLOGIST]) model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.AN_INGENUOUS_MALACOLOGIST]) - exponentiated_tentacles = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: exponentiated tentacles') + exponentiated_tentacles = model.NewIntVar(f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: exponentiated tentacles', lb = 0) model.AddApproximateExponentiationEquality(exponentiated_tentacles, tentacles, 2.2, MAXIMUM_ATTRIBUTE) - collated_research = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: collated research') + collated_research = model.NewIntVar(f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: collated research') model.AddDivisionEquality(collated_research, exponentiated_tentacles, 5) - value_remainder = model.NewIntVar(0, 249, f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: value remainder', lb = 0, ub = 249) model.AddModuloEquality(value_remainder, value, 250) model.Add(primary_revenue == value - value_remainder + 250).OnlyEnforceIf(actions[Buyer.AN_INGENUOUS_MALACOLOGIST]) @@ -1097,7 +1054,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 60*implausibility).OnlyEnforceIf(actions[Buyer.AN_INGENUOUS_MALACOLOGIST]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.AN_INGENUOUS_MALACOLOGIST.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, exponentiated_tentacles, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.AN_INGENUOUS_MALACOLOGIST]) @@ -1110,13 +1067,13 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.AN_ENTERPRISING_BOOT_SALESMAN]) model.Add(legs >= 4).OnlyEnforceIf(actions[Buyer.AN_ENTERPRISING_BOOT_SALESMAN]) - diamonds = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: diamonds') + diamonds = model.NewIntVar(f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: diamonds', lb = 0) model.AddApproximateExponentiationEquality(diamonds, legs, 2.2, MAXIMUM_ATTRIBUTE) - total_value = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: total value') + total_value = model.NewIntVar(f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: total value', lb = 0) model.Add(total_value == value + zoological_mania_bonus) - total_value_remainder = model.NewIntVar(0, 49, f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: total value remainder') + total_value_remainder = model.NewIntVar(f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: total value remainder', lb = 0, ub = 49) model.AddModuloEquality(total_value_remainder, total_value, 50) model.Add(primary_revenue == total_value - total_value_remainder).OnlyEnforceIf(actions[Buyer.AN_ENTERPRISING_BOOT_SALESMAN]) @@ -1125,7 +1082,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.AN_ENTERPRISING_BOOT_SALESMAN]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.AN_ENTERPRISING_BOOT_SALESMAN.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, diamonds, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.AN_ENTERPRISING_BOOT_SALESMAN]) @@ -1136,7 +1093,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([180, 189])).OnlyEnforceIf(actions[Buyer.THE_DUMBWAITER_OF_BALMORAL]) model.Add(value >= 250).OnlyEnforceIf(actions[Buyer.THE_DUMBWAITER_OF_BALMORAL]) - value_remainder = model.NewIntVar(0, 249, f'{Buyer.THE_DUMBWAITER_OF_BALMORAL.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_DUMBWAITER_OF_BALMORAL.name}: value remainder', lb = 0, ub = 249) model.AddModuloEquality(value_remainder, value, 250) model.Add(primary_revenue == value - value_remainder).OnlyEnforceIf(actions[Buyer.THE_DUMBWAITER_OF_BALMORAL]) @@ -1165,10 +1122,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY]) model.Add(amalgamy >= 5).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY]) - amalgamy_squared = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: amalgamy squared') - model.AddMultiplicationEquality(amalgamy_squared, [amalgamy, amalgamy]) + amalgamy_squared = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: amalgamy squared', lb = 0) + model.AddMultiplicationEquality(amalgamy_squared, (amalgamy, amalgamy)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY]) @@ -1177,7 +1134,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, amalgamy_squared, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_AMALGAMY]) @@ -1188,10 +1145,10 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY]) model.Add(antiquity >= 5).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY]) - antiquity_squared = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: antiquity squared') - model.AddMultiplicationEquality(antiquity_squared, [antiquity, antiquity]) + antiquity_squared = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: antiquity squared', lb = 0) + model.AddMultiplicationEquality(antiquity_squared, (antiquity, antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY]) @@ -1200,7 +1157,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, antiquity_squared, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_ANTIQUITY]) @@ -1210,19 +1167,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # The Trifling Diplomat - Bird model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([180, 189])).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_BIRD]) - non_negative_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative amalgamy') + non_negative_amalgamy = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative amalgamy') model.AddMaxEquality(non_negative_amalgamy, [amalgamy, 0]) - non_negative_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative menace') + non_negative_menace = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative menace') model.AddMaxEquality(non_negative_menace, [menace, 0]) - non_negative_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative antiquity') + non_negative_antiquity = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: non-negative antiquity') model.AddMaxEquality(non_negative_antiquity, [antiquity, 0]) - compromising_documents = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: compromising documents') - model.AddGeneralMultiplicationEquality(compromising_documents, non_negative_amalgamy, non_negative_menace, non_negative_antiquity) + compromising_documents = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: compromising documents', lb = 0) + model.AddMultiplicationEquality(compromising_documents, (non_negative_amalgamy, non_negative_menace, non_negative_antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_BIRD]) @@ -1231,7 +1188,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_BIRD]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_BIRD.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, compromising_documents, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_BIRD]) @@ -1241,19 +1198,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # The Trifling Diplomat - Fish model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([190, 199])).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_FISH]) - non_negative_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative amalgamy') + non_negative_amalgamy = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative amalgamy') model.AddMaxEquality(non_negative_amalgamy, [amalgamy, 0]) - non_negative_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative menace') + non_negative_menace = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative menace') model.AddMaxEquality(non_negative_menace, [menace, 0]) - non_negative_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative antiquity') + non_negative_antiquity = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: non-negative antiquity') model.AddMaxEquality(non_negative_antiquity, [antiquity, 0]) - compromising_documents = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: compromising documents') - model.AddGeneralMultiplicationEquality(compromising_documents, non_negative_amalgamy, non_negative_menace, non_negative_antiquity) + compromising_documents = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: compromising documents', lb = 0) + model.AddMultiplicationEquality(compromising_documents, (non_negative_amalgamy, non_negative_menace, non_negative_antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_FISH]) @@ -1262,7 +1219,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_FISH]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_FISH.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, compromising_documents, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_FISH]) @@ -1272,19 +1229,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # The Trifling Diplomat - Insect model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([210, 219])).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_INSECT]) - non_negative_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative amalgamy') + non_negative_amalgamy = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative amalgamy') model.AddMaxEquality(non_negative_amalgamy, [amalgamy, 0]) - non_negative_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative menace') + non_negative_menace = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative menace') model.AddMaxEquality(non_negative_menace, [menace, 0]) - non_negative_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative antiquity') + non_negative_antiquity = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: non-negative antiquity') model.AddMaxEquality(non_negative_antiquity, [antiquity, 0]) - compromising_documents = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: compromising documents') - model.AddGeneralMultiplicationEquality(compromising_documents, non_negative_amalgamy, non_negative_menace, non_negative_antiquity) + compromising_documents = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: compromising documents', lb = 0) + model.AddMultiplicationEquality(compromising_documents, (non_negative_amalgamy, non_negative_menace, non_negative_antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_INSECT]) @@ -1293,7 +1250,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_INSECT]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_INSECT.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, compromising_documents, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_INSECT]) @@ -1303,19 +1260,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # The Trifling Diplomat - Reptile model.AddLinearExpressionInDomain(skeleton_in_progress, cp_model.Domain.FromFlatIntervals([160, 169])).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_REPTILE]) - non_negative_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative amalgamy') + non_negative_amalgamy = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative amalgamy') model.AddMaxEquality(non_negative_amalgamy, [amalgamy, 0]) - non_negative_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative menace') + non_negative_menace = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative menace') model.AddMaxEquality(non_negative_menace, [menace, 0]) - non_negative_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative antiquity') + non_negative_antiquity = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: non-negative antiquity') model.AddMaxEquality(non_negative_antiquity, [antiquity, 0]) - compromising_documents = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: compromising documents') - model.AddGeneralMultiplicationEquality(compromising_documents, non_negative_amalgamy, non_negative_menace, non_negative_antiquity) + compromising_documents = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: compromising documents', lb = 0) + model.AddMultiplicationEquality(compromising_documents, (non_negative_amalgamy, non_negative_menace, non_negative_antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_REPTILE]) @@ -1324,7 +1281,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_REPTILE]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_REPTILE.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, compromising_documents, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_REPTILE]) @@ -1335,19 +1292,19 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(skeleton_in_progress >= 100).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_SKULLS]) model.Add(skulls >= 5).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_SKULLS]) - non_negative_amalgamy = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative amalgamy') + non_negative_amalgamy = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative amalgamy') model.AddMaxEquality(non_negative_amalgamy, [amalgamy, 0]) - non_negative_menace = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative menace') + non_negative_menace = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative menace') model.AddMaxEquality(non_negative_menace, [menace, 0]) - non_negative_antiquity = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative antiquity') + non_negative_antiquity = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: non-negative antiquity') model.AddMaxEquality(non_negative_antiquity, [antiquity, 0]) - compromising_documents = model.NewIntVar(0, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: compromising documents') - model.AddGeneralMultiplicationEquality(compromising_documents, non_negative_amalgamy, non_negative_menace, non_negative_antiquity) + compromising_documents = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: compromising documents', lb = 0) + model.AddMultiplicationEquality(compromising_documents, (non_negative_amalgamy, non_negative_menace, non_negative_antiquity)) - value_remainder = model.NewIntVar(0, 49, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: value remainder') + value_remainder = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: value remainder', lb = 0, ub = 49) model.AddModuloEquality(value_remainder, value, 50) model.Add(primary_revenue == value - value_remainder + 50).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_SKULLS]) @@ -1356,7 +1313,7 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non model.Add(difficulty_level == 0).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_SKULLS]) # The indirection is necessary for applying an enforcement literal - derived_exhaustion = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: derived exhaustion') + derived_exhaustion = model.NewIntVar(f'{Buyer.THE_TRIFLING_DIPLOMAT_SKULLS.name}: derived exhaustion') model.AddDivisionEquality(derived_exhaustion, compromising_documents, 100) model.Add(added_exhaustion == derived_exhaustion).OnlyEnforceIf(actions[Buyer.THE_TRIFLING_DIPLOMAT_SKULLS]) @@ -1364,22 +1321,22 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non # Maximize profit margin - net_profit = model.NewIntVar(cp_model.INT32_MIN, cp_model.INT32_MAX, 'net profit') + net_profit = model.NewIntVar('net profit') model.Add(net_profit == total_revenue - cost) # This is necessary to preserve some degree of precision after dividing - multiplied_net_profit = model.NewIntVar(cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER, 'multiplied net profit') - model.AddMultiplicationEquality(multiplied_net_profit, [net_profit, PROFIT_MARGIN_MULTIPLIER]) + multiplied_net_profit = model.NewIntVar('multiplied net profit', lb = cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, ub = cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER) + model.AddMultiplicationEquality(multiplied_net_profit, (net_profit, PROFIT_MARGIN_MULTIPLIER)) - absolute_multiplied_net_profit = model.NewIntVar(0, cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER, 'absolute multiplied net profit') + absolute_multiplied_net_profit = model.NewIntVar('absolute multiplied net profit', lb = 0, ub = cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER) model.AddAbsEquality(absolute_multiplied_net_profit, multiplied_net_profit) - absolute_profit_margin = model.NewIntVar(cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER, 'absolute profit margin') + absolute_profit_margin = model.NewIntVar('absolute profit margin', lb = cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, ub = cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER) model.AddDivisionEquality(absolute_profit_margin, absolute_multiplied_net_profit, total_revenue) - profit_margin = model.NewIntVar(cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER, 'profit margin') + profit_margin = model.NewIntVar('profit margin', lb = cp_model.INT32_MIN*PROFIT_MARGIN_MULTIPLIER, ub = cp_model.INT32_MAX*PROFIT_MARGIN_MULTIPLIER) - positive_net_profit = model.NewIntermediateBoolVar('positive net profit', net_profit, cp_model.Domain.FromFlatIntervals([0, cp_model.INT_MAX])) + positive_net_profit = model.NewIntermediateBoolVar('positive net profit', net_profit, cp_model.Domain.FromFlatIntervals([0, cp_model.INT32_MAX])) model.Add(profit_margin == absolute_profit_margin).OnlyEnforceIf(positive_net_profit) model.Add(profit_margin == absolute_profit_margin*-1).OnlyEnforceIf(positive_net_profit.Not())