Remove BoneMarketModel.AddDivisionApproximateExponentiationEquality
This function has been obsoleted by the ability to pass partial methods as parameters to helper functions. Use of this function has been replaced with partial methods accordingly. This has allowed some intermediate variables to be removed entirely, allowing for further simplification.
This commit is contained in:
parent
6b9643041a
commit
1175575c92
@ -22,22 +22,6 @@ 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 AddDivisionApproximateExponentiationEquality(self, target, num, denom, exp, upto):
|
||||
"""Adds `target == (num // denom)**exp` using a lookup table.
|
||||
|
||||
Set `upto` to a value that is unlikely to come into play.
|
||||
|
||||
`target`, `num`, and `denom` are interpreted as a BoundedLinearExpression, and a layer of indirection is applied such that each Constraint in the returned tuple can accept an enforcement literal."""
|
||||
quotient = self.NewIntVar(f'{repr(target)} == ({repr(num)} // {repr(denom)})**{repr(exp)}: quotient')
|
||||
intermediate_num, num_constraint = self.NewIntermediateIntVar(num, f'{repr(target)} == ({repr(num)} // {repr(denom)})**{repr(exp)}: num', lb = 0)
|
||||
intermediate_denom, denom_constraint = self.NewIntermediateIntVar(denom, f'{repr(target)} == ({repr(num)} // {repr(denom)})**{repr(exp)}: denom', lb = 1)
|
||||
intermediate_target, target_constraint = self.NewIntermediateIntVar(target, f'{repr(target)} == ({repr(num)} // {repr(denom)})**{repr(exp)}: target')
|
||||
|
||||
super().AddDivisionEquality(quotient, intermediate_num, intermediate_denom)
|
||||
super().AddAllowedAssignments((intermediate_target, quotient), ((int(base**exp), base) for base in range(upto + 1)))
|
||||
|
||||
return (num_constraint, denom_constraint, target_constraint)
|
||||
|
||||
def AddDivisionEquality(self, target, num, denom):
|
||||
"""Adds `target == num // denom` (integer division rounded towards 0).
|
||||
|
||||
|
@ -956,25 +956,33 @@ def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = Non
|
||||
menace,
|
||||
)
|
||||
}
|
||||
for fascination, criteria in (
|
||||
('BIRD', (cp_model.BoundedLinearExpression(skeleton_in_progress, (180, 189)),)),
|
||||
('FISH', (cp_model.BoundedLinearExpression(skeleton_in_progress, (190, 199)),)),
|
||||
('INSECT', (cp_model.BoundedLinearExpression(skeleton_in_progress, (210, 219)),)),
|
||||
('REPTILE', (cp_model.BoundedLinearExpression(skeleton_in_progress, (160, 169)),)),
|
||||
('SKULLS', (skeleton_in_progress >= 100, skulls >= 5)),
|
||||
):
|
||||
compromising_documents = model.NewIntVar(f'{getattr(DiplomatFascination, fascination).name}: compromising documents')
|
||||
compromising_documents_constraints = model.AddDivisionApproximateExponentiationEquality(compromising_documents, cp_model.LinearExpr.Sum((amalgamy, antiquity, menace)), 3, 2.2, MAXIMUM_ATTRIBUTE)
|
||||
{
|
||||
model.AddIf(actions[getattr(DiplomatFascination, fascination).value],
|
||||
*criteria,
|
||||
partialmethod(BoneMarketModel.AddDivisionMultiplicationEquality, primary_revenue - 50, value, 50),
|
||||
secondary_revenue == 50*compromising_documents,
|
||||
compromising_documents_constraints, # Applies enforcement literal to intermediate calculations
|
||||
partialmethod(BoneMarketModel.AddMultiplicationEquality,
|
||||
secondary_revenue,
|
||||
(50,
|
||||
partialmethod(BoneMarketModel.AddApproximateExponentiationEquality,
|
||||
var = partialmethod(BoneMarketModel.AddDivisionEquality,
|
||||
num = cp_model.LinearExpr.Sum((amalgamy, antiquity, menace)),
|
||||
denom = 3
|
||||
),
|
||||
exp = 2.2,
|
||||
upto = MAXIMUM_ATTRIBUTE
|
||||
)
|
||||
)
|
||||
),
|
||||
difficulty_level == 0,
|
||||
partialmethod(BoneMarketModel.AddDivisionEquality, added_exhaustion, secondary_revenue, 5000),
|
||||
)
|
||||
else:
|
||||
del fascination, criteria, compromising_documents, compromising_documents_constraints
|
||||
) for fascination, criteria in (
|
||||
('BIRD', (cp_model.BoundedLinearExpression(skeleton_in_progress, (180, 189)),)),
|
||||
('FISH', (cp_model.BoundedLinearExpression(skeleton_in_progress, (190, 199)),)),
|
||||
('INSECT', (cp_model.BoundedLinearExpression(skeleton_in_progress, (210, 219)),)),
|
||||
('REPTILE', (cp_model.BoundedLinearExpression(skeleton_in_progress, (160, 169)),)),
|
||||
('SKULLS', (skeleton_in_progress >= 100, skulls >= 5)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
# Maximize profit margin
|
||||
|
Loading…
Reference in New Issue
Block a user