From afbad8b5327af61fc606eae72d2b6a45d0819f70 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Wed, 7 Jul 2021 15:12:03 -0500 Subject: [PATCH] Clean up requirements Declarations that require a specific range of torso style now use one constraint to model that, rather than two. Inconsistent whitespace has been cleaned up. Skipping tails is only possible if there are tails to skip. --- Bone Market Solver.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Bone Market Solver.py b/Bone Market Solver.py index 15cdc24..4eb6b65 100644 --- a/Bone Market Solver.py +++ b/Bone Market Solver.py @@ -1556,16 +1556,14 @@ def Solve(shadowy_level, bone_market_fluctuations, zoological_mania, occasional_ model.Add(skulls == 1).OnlyEnforceIf(actions[Declaration.HUMANOID]) model.Add(legs == 2).OnlyEnforceIf(actions[Declaration.HUMANOID]) model.Add(arms == 2).OnlyEnforceIf(actions[Declaration.HUMANOID]) - model.Add(torso_style >= 10).OnlyEnforceIf(actions[Declaration.HUMANOID]) - model.Add(torso_style <= 20).OnlyEnforceIf(actions[Declaration.HUMANOID]) + model.AddLinearExpressionInDomain(torso_style, cp_model.Domain.FromFlatIntervals([10, 20])).OnlyEnforceIf(actions[Declaration.HUMANOID]) for prohibited_quality in [tails, fins, wings]: model.Add(prohibited_quality == 0).OnlyEnforceIf(actions[Declaration.HUMANOID]) # Ape requirements model.Add(skulls == 1).OnlyEnforceIf(actions[Declaration.APE]) model.Add(arms == 4).OnlyEnforceIf(actions[Declaration.APE]) - model.Add(torso_style >= 10).OnlyEnforceIf(actions[Declaration.APE]) - model.Add(torso_style <= 20).OnlyEnforceIf(actions[Declaration.APE]) + model.AddLinearExpressionInDomain(torso_style, cp_model.Domain.FromFlatIntervals([10, 20])).OnlyEnforceIf(actions[Declaration.APE]) for prohibited_quality in [legs, tails, fins, wings]: model.Add(prohibited_quality == 0).OnlyEnforceIf(actions[Declaration.APE]) @@ -1573,8 +1571,7 @@ def Solve(shadowy_level, bone_market_fluctuations, zoological_mania, occasional_ model.Add(skulls == 1).OnlyEnforceIf(actions[Declaration.MONKEY]) model.Add(arms == 4).OnlyEnforceIf(actions[Declaration.MONKEY]) model.Add(tails == 1).OnlyEnforceIf(actions[Declaration.MONKEY]) - model.Add(torso_style >= 10).OnlyEnforceIf(actions[Declaration.MONKEY]) - model.Add(torso_style <= 20).OnlyEnforceIf(actions[Declaration.MONKEY]) + model.AddLinearExpressionInDomain(torso_style, cp_model.Domain.FromFlatIntervals([10, 20])).OnlyEnforceIf(actions[Declaration.MONKEY]) for prohibited_quality in [legs, fins, wings]: model.Add(prohibited_quality == 0).OnlyEnforceIf(actions[Declaration.MONKEY]) @@ -1606,7 +1603,6 @@ def Solve(shadowy_level, bone_market_fluctuations, zoological_mania, occasional_ model.Add(torso_style >= 20).OnlyEnforceIf(actions[Declaration.AMPHIBIAN]) model.Add(legs == 4).OnlyEnforceIf(actions[Declaration.AMPHIBIAN]) model.Add(skulls == 1).OnlyEnforceIf(actions[Declaration.AMPHIBIAN]) - for prohibited_quality in [tails, fins, wings, arms]: model.Add(prohibited_quality == 0).OnlyEnforceIf(actions[Declaration.AMPHIBIAN]) @@ -1641,7 +1637,7 @@ def Solve(shadowy_level, bone_market_fluctuations, zoological_mania, occasional_ # Skeleton must have no unfilled tails, unless they were skipped model.Add(cp_model.LinearExpr.ScalProd(actions.values(), [action.value.tails_needed for action in actions.keys()]) == 0).OnlyEnforceIf(actions[Appendage.SKIP_TAILS].Not()) - model.Add(cp_model.LinearExpr.ScalProd(actions.values(), [action.value.tails_needed for action in actions.keys()]) >= 0).OnlyEnforceIf(actions[Appendage.SKIP_TAILS]) + model.Add(cp_model.LinearExpr.ScalProd(actions.values(), [action.value.tails_needed for action in actions.keys()]) > 0).OnlyEnforceIf(actions[Appendage.SKIP_TAILS]) # A Palaeontologist with Hoarding Propensities